1818
1919#define ATRACE_TAG ATRACE_TAG_GRAPHICS
2020#define LOG_TAG " drmhwc"
21+ #include " DrmAtomicStateManager.h"
2122#include < drm/drm_fourcc.h>
2223#include < cmath>
23- #include " DrmAtomicStateManager.h"
2424
2525#include < drm/drm_mode.h>
2626#include < sync/sync.h>
2727#include < utils/Trace.h>
28- #include " utils/intel_blit.h"
2928#include < cassert>
29+ #include " utils/intel_blit.h"
3030
3131#include " drm/DrmCrtc.h"
3232#include " drm/DrmDevice.h"
@@ -132,20 +132,6 @@ auto DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) -> int {
132132 }
133133 }
134134
135- if (args.color_matrix && crtc->GetCtmProperty ()) {
136- auto blob = drm->RegisterUserPropertyBlob (args.color_matrix .get (),
137- sizeof (drm_color_ctm));
138- new_frame_state.ctm_blob = std::move (blob);
139-
140- if (!new_frame_state.ctm_blob ) {
141- ALOGE (" Failed to create CTM blob" );
142- return -EINVAL;
143- }
144-
145- if (!crtc->GetCtmProperty ().AtomicSet (*pset, *new_frame_state.ctm_blob ))
146- return -EINVAL;
147- }
148-
149135 if (args.colorspace && connector->GetColorspaceProperty ()) {
150136 if (!connector->GetColorspaceProperty ()
151137 .AtomicSet (*pset, connector->GetColorspacePropertyValue (
@@ -159,21 +145,89 @@ auto DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) -> int {
159145 return -EINVAL;
160146 }
161147
162- if (args.hdr_metadata && connector->GetHdrOutputMetadataProperty ()) {
163- auto blob = drm->RegisterUserPropertyBlob (args.hdr_metadata .get (),
164- sizeof (hdr_output_metadata));
165- new_frame_state.hdr_metadata_blob = std::move (blob);
166- if (!new_frame_state.hdr_metadata_blob ) {
167- ALOGE (" Failed to create %s blob" ,
168- connector->GetHdrOutputMetadataProperty ().GetName ().c_str ());
148+ if (connector->GetHdrOutputMetadataProperty ()) {
149+ if (args.hdr_metadata ) {
150+ auto blob = drm->RegisterUserPropertyBlob (args.hdr_metadata .get (),
151+ sizeof (hdr_output_metadata));
152+ new_frame_state.hdr_metadata_blob = std::move (blob);
153+ if (!new_frame_state.hdr_metadata_blob ) {
154+ ALOGE (" Failed to create %s blob" ,
155+ connector->GetHdrOutputMetadataProperty ().GetName ().c_str ());
156+ return -EINVAL;
157+ }
158+
159+ if (!connector->GetHdrOutputMetadataProperty ()
160+ .AtomicSet (*pset, *new_frame_state.hdr_metadata_blob ))
161+ return -EINVAL;
162+ } else {
163+ if (!connector->GetHdrOutputMetadataProperty ().AtomicSet (*pset, 0 ))
164+ return -EINVAL;
165+ }
166+ }
167+
168+ if (args.color_matrix && crtc->GetCtmProperty ()) {
169+ auto blob = drm->RegisterUserPropertyBlob (args.color_matrix .get (),
170+ sizeof (drm_color_ctm));
171+ new_frame_state.ctm_blob = std::move (blob);
172+
173+ if (!new_frame_state.ctm_blob ) {
174+ ALOGE (" Failed to create CTM blob" );
169175 return -EINVAL;
170176 }
171177
172- if (!connector->GetHdrOutputMetadataProperty ()
173- .AtomicSet (*pset, *new_frame_state.hdr_metadata_blob ))
178+ if (!crtc->GetCtmProperty ().AtomicSet (*pset, *new_frame_state.ctm_blob ))
174179 return -EINVAL;
175180 }
176181
182+ // HDR pipeline handling (degamma -> CTM -> gamma)
183+ // CTM matrix is set above
184+ {
185+ // Build blobs for degamma
186+ if (crtc->GetDeGammaLutProperty ()) {
187+ if (args.degamma_lut ) {
188+ auto blob = drm->RegisterUserPropertyBlob (args.degamma_lut ->data (),
189+ args.degamma_lut ->size () *
190+ sizeof (drm_color_lut));
191+ new_frame_state.degamma_blob = std::move (blob);
192+ if (!new_frame_state.degamma_blob ) {
193+ ALOGE (" Failed to create %s blob" ,
194+ crtc->GetDeGammaLutProperty ().GetName ().c_str ());
195+ return -EINVAL;
196+ }
197+
198+ if (!crtc->GetDeGammaLutProperty ()
199+ .AtomicSet (*pset, *new_frame_state.degamma_blob ))
200+ return -EINVAL;
201+ } else {
202+ if (crtc->GetDeGammaLutProperty () &&
203+ !crtc->GetDeGammaLutProperty ().AtomicSet (*pset, 0 ))
204+ return -EINVAL;
205+ }
206+ }
207+ // Output gamma PQ
208+ if (crtc->GetGammaLutProperty ()) {
209+ if (args.gamma_lut ) {
210+ auto blob = drm->RegisterUserPropertyBlob (args.gamma_lut ->data (),
211+ args.gamma_lut ->size () *
212+ sizeof (drm_color_lut));
213+ new_frame_state.gamma_blob = std::move (blob);
214+ if (!new_frame_state.gamma_blob ) {
215+ ALOGE (" Failed to create %s blob" ,
216+ crtc->GetGammaLutProperty ().GetName ().c_str ());
217+ return -EINVAL;
218+ }
219+
220+ if (!crtc->GetGammaLutProperty ().AtomicSet (*pset,
221+ *new_frame_state.gamma_blob ))
222+ return -EINVAL;
223+ } else {
224+ if (crtc->GetGammaLutProperty () &&
225+ !crtc->GetGammaLutProperty ().AtomicSet (*pset, 0 ))
226+ return -EINVAL;
227+ }
228+ }
229+ }
230+
177231 auto unused_planes = new_frame_state.used_planes ;
178232
179233 if (args.composition ) {
@@ -244,6 +298,10 @@ auto DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) -> int {
244298 flags |= DRM_MODE_ATOMIC_NONBLOCK;
245299 }
246300
301+ if (args.hdr_enabled ) {
302+ args.color_adjustment = false ;
303+ }
304+
247305 if (args.color_adjustment == true ) {
248306 SetColorSaturationHue ();
249307 SetColorBrightnessContrast ();
@@ -709,6 +767,26 @@ auto DrmAtomicStateManager::ApplyPendingLUT(struct drm_color_lut *lut, uint64_t
709767 return 0 ;
710768}
711769
770+ auto DrmAtomicStateManager::ApplyPendingDeLUT (struct drm_color_lut *lut, uint64_t lut_size) -> int {
771+ uint32_t lut_blob_id = 0 ;
772+ if (pipe_->crtc ->Get ()->GetDeGammaLutProperty ().id () == 0 ) {
773+ ALOGE (" GetDeGammaLutProperty().id() == 0" );
774+ return -EINVAL;
775+ }
776+
777+ drmModeCreatePropertyBlob (
778+ *(pipe_->device ->GetFd ()), lut, sizeof (struct drm_color_lut ) * lut_size, &lut_blob_id);
779+ if (lut_blob_id == 0 ) {
780+ ALOGE (" COLOR_ lut_blob_id == 0" );
781+ return -EINVAL;
782+ }
783+
784+ drmModeObjectSetProperty (*(pipe_->device ->GetFd ()), pipe_->crtc ->Get ()->GetId (), DRM_MODE_OBJECT_CRTC,
785+ pipe_->crtc ->Get ()->GetDeGammaLutProperty ().id (), lut_blob_id);
786+ drmModeDestroyPropertyBlob (*(pipe_->device ->GetFd ()), lut_blob_id);
787+ return 0 ;
788+ }
789+
712790auto DrmAtomicStateManager::SetColorSaturationHue (void ) ->int{
713791 double color_transform_matrix[16 ] = {1.0 , 0.0 , 0.0 , 0.0 ,
714792 0.0 , 1.0 , 0.0 , 0.0 ,
0 commit comments