diff options
Diffstat (limited to 'services/surfaceflinger/SurfaceFlinger.cpp')
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 53 | 
1 files changed, 31 insertions, 22 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 787bbd2fcc..cd51dd1d61 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -37,6 +37,7 @@  #include <dvr/vr_flinger.h> +#include <ui/ColorSpace.h>  #include <ui/DebugUtils.h>  #include <ui/DisplayInfo.h>  #include <ui/DisplayStatInfo.h> @@ -747,9 +748,24 @@ void SurfaceFlinger::init() {          ALOGE("Run StartPropertySetThread failed!");      } -    mLegacySrgbSaturationMatrix = getBE().mHwc->getDataspaceSaturationMatrix(HWC_DISPLAY_PRIMARY, +    // This is a hack. Per definition of getDataspaceSaturationMatrix, the returned matrix +    // is used to saturate legacy sRGB content. However, to make sure the same color under +    // Display P3 will be saturated to the same color, we intentionally break the API spec +    // and apply this saturation matrix on Display P3 content. Unless the risk of applying +    // such saturation matrix on Display P3 is understood fully, the API should always return +    // identify matrix. +    mEnhancedSaturationMatrix = getBE().mHwc->getDataspaceSaturationMatrix(HWC_DISPLAY_PRIMARY,              Dataspace::SRGB_LINEAR); +    // we will apply this on Display P3. +    if (mEnhancedSaturationMatrix != mat4()) { +        ColorSpace srgb(ColorSpace::sRGB()); +        ColorSpace displayP3(ColorSpace::DisplayP3()); +        mat4 srgbToP3 = mat4(ColorSpaceConnector(srgb, displayP3).getTransform()); +        mat4 p3ToSrgb = mat4(ColorSpaceConnector(displayP3, srgb).getTransform()); +        mEnhancedSaturationMatrix = srgbToP3 * mEnhancedSaturationMatrix * p3ToSrgb; +    } +      ALOGV("Done initializing");  } @@ -2912,8 +2928,7 @@ bool SurfaceFlinger::doComposeSurfaces(const sp<const DisplayDevice>& displayDev      ATRACE_INT("hasClientComposition", hasClientComposition);      bool applyColorMatrix = false; -    bool needsLegacyColorMatrix = false; -    bool legacyColorMatrixApplied = false; +    bool needsEnhancedColorMatrix = false;      if (hasClientComposition) {          ALOGV("hasClientComposition"); @@ -2930,15 +2945,23 @@ bool SurfaceFlinger::doComposeSurfaces(const sp<const DisplayDevice>& displayDev          const bool skipClientColorTransform = getBE().mHwc->hasCapability(              HWC2::Capability::SkipClientColorTransform); +        mat4 colorMatrix;          applyColorMatrix = !hasDeviceComposition && !skipClientColorTransform;          if (applyColorMatrix) { -            getRenderEngine().setupColorTransform(mDrawingState.colorMatrix); +            colorMatrix = mDrawingState.colorMatrix;          } -        needsLegacyColorMatrix = +        // The current enhanced saturation matrix is designed to enhance Display P3, +        // thus we only apply this matrix when the render intent is not colorimetric +        // and the output color space is Display P3. +        needsEnhancedColorMatrix =              (displayDevice->getActiveRenderIntent() >= RenderIntent::ENHANCE && -             outputDataspace != Dataspace::UNKNOWN && -             outputDataspace != Dataspace::SRGB); +             outputDataspace == Dataspace::DISPLAY_P3); +        if (needsEnhancedColorMatrix) { +            colorMatrix *= mEnhancedSaturationMatrix; +        } + +        getRenderEngine().setupColorTransform(colorMatrix);          if (!displayDevice->makeCurrent()) {              ALOGW("DisplayDevice::makeCurrent failed. Aborting surface composition for display %s", @@ -3025,17 +3048,6 @@ bool SurfaceFlinger::doComposeSurfaces(const sp<const DisplayDevice>& displayDev                      break;                  }                  case HWC2::Composition::Client: { -                    // switch color matrices lazily -                    if (layer->isLegacyDataSpace() && needsLegacyColorMatrix) { -                        if (!legacyColorMatrixApplied) { -                            getRenderEngine().setSaturationMatrix(mLegacySrgbSaturationMatrix); -                            legacyColorMatrixApplied = true; -                        } -                    } else if (legacyColorMatrixApplied) { -                        getRenderEngine().setSaturationMatrix(mat4()); -                        legacyColorMatrixApplied = false; -                    } -                      layer->draw(renderArea, clip);                      break;                  } @@ -3048,12 +3060,9 @@ bool SurfaceFlinger::doComposeSurfaces(const sp<const DisplayDevice>& displayDev          firstLayer = false;      } -    if (applyColorMatrix) { +    if (applyColorMatrix || needsEnhancedColorMatrix) {          getRenderEngine().setupColorTransform(mat4());      } -    if (needsLegacyColorMatrix && legacyColorMatrixApplied) { -        getRenderEngine().setSaturationMatrix(mat4()); -    }      // disable scissor at the end of the frame      getBE().mRenderEngine->disableScissor();  |