Switch to skcms-based factories and getters in SkColorSpace
Test: Mechanical substitution, still builds.
Change-Id: I877e4edd61e81279830ffbbcfea18d721abf6943
diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp
index 8fa2980..3d74f8b 100644
--- a/cmds/screencap/screencap.cpp
+++ b/cmds/screencap/screencap.cpp
@@ -81,8 +81,7 @@
case ui::Dataspace::V0_SRGB:
return SkColorSpace::MakeSRGB();
case ui::Dataspace::DISPLAY_P3:
- return SkColorSpace::MakeRGB(
- SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kDCIP3_D65_Gamut);
+ return SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
default:
return nullptr;
}
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp
index eb7338a..c1e0047 100755
--- a/core/jni/android/graphics/Bitmap.cpp
+++ b/core/jni/android/graphics/Bitmap.cpp
@@ -8,7 +8,6 @@
#include "SkImageInfo.h"
#include "SkColor.h"
#include "SkColorSpace.h"
-#include "SkMatrix44.h"
#include "GraphicsJNI.h"
#include "SkStream.h"
@@ -356,8 +355,8 @@
if (xyzD50 == nullptr || transferParameters == nullptr) {
colorSpace = SkColorSpace::MakeSRGB();
} else {
- SkColorSpaceTransferFn p = GraphicsJNI::getNativeTransferParameters(env, transferParameters);
- SkMatrix44 xyzMatrix = GraphicsJNI::getNativeXYZMatrix(env, xyzD50);
+ skcms_TransferFunction p = GraphicsJNI::getNativeTransferParameters(env, transferParameters);
+ skcms_Matrix3x3 xyzMatrix = GraphicsJNI::getNativeXYZMatrix(env, xyzD50);
colorSpace = SkColorSpace::MakeRGB(p, xyzMatrix);
}
@@ -549,8 +548,7 @@
if (skbitmap.colorType() == kRGBA_F16_SkColorType) {
// Convert to P3 before encoding. This matches SkAndroidCodec::computeOutputColorSpace
// for wide gamuts.
- auto cs = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kDCIP3_D65_Gamut);
+ auto cs = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
auto info = skbitmap.info().makeColorType(kRGBA_8888_SkColorType)
.makeColorSpace(std::move(cs));
SkBitmap p3;
@@ -910,32 +908,32 @@
SkColorSpace* colorSpace = bitmapHolder->info().colorSpace();
if (colorSpace == nullptr) return JNI_FALSE;
- SkMatrix44 xyzMatrix(SkMatrix44::kUninitialized_Constructor);
+ skcms_Matrix3x3 xyzMatrix;
if (!colorSpace->toXYZD50(&xyzMatrix)) return JNI_FALSE;
jfloat* xyz = env->GetFloatArrayElements(xyzArray, NULL);
- xyz[0] = xyzMatrix.getFloat(0, 0);
- xyz[1] = xyzMatrix.getFloat(1, 0);
- xyz[2] = xyzMatrix.getFloat(2, 0);
- xyz[3] = xyzMatrix.getFloat(0, 1);
- xyz[4] = xyzMatrix.getFloat(1, 1);
- xyz[5] = xyzMatrix.getFloat(2, 1);
- xyz[6] = xyzMatrix.getFloat(0, 2);
- xyz[7] = xyzMatrix.getFloat(1, 2);
- xyz[8] = xyzMatrix.getFloat(2, 2);
+ xyz[0] = xyzMatrix.vals[0][0];
+ xyz[1] = xyzMatrix.vals[1][0];
+ xyz[2] = xyzMatrix.vals[2][0];
+ xyz[3] = xyzMatrix.vals[0][1];
+ xyz[4] = xyzMatrix.vals[1][1];
+ xyz[5] = xyzMatrix.vals[2][1];
+ xyz[6] = xyzMatrix.vals[0][2];
+ xyz[7] = xyzMatrix.vals[1][2];
+ xyz[8] = xyzMatrix.vals[2][2];
env->ReleaseFloatArrayElements(xyzArray, xyz, 0);
- SkColorSpaceTransferFn transferParams;
+ skcms_TransferFunction transferParams;
if (!colorSpace->isNumericalTransferFn(&transferParams)) return JNI_FALSE;
jfloat* params = env->GetFloatArrayElements(paramsArray, NULL);
- params[0] = transferParams.fA;
- params[1] = transferParams.fB;
- params[2] = transferParams.fC;
- params[3] = transferParams.fD;
- params[4] = transferParams.fE;
- params[5] = transferParams.fF;
- params[6] = transferParams.fG;
+ params[0] = transferParams.a;
+ params[1] = transferParams.b;
+ params[2] = transferParams.c;
+ params[3] = transferParams.d;
+ params[4] = transferParams.e;
+ params[5] = transferParams.f;
+ params[6] = transferParams.g;
env->ReleaseFloatArrayElements(paramsArray, params, 0);
return JNI_TRUE;
@@ -1121,8 +1119,8 @@
static jobject Bitmap_wrapHardwareBufferBitmap(JNIEnv* env, jobject, jobject hardwareBuffer,
jfloatArray xyzD50, jobject transferParameters) {
- SkColorSpaceTransferFn p = GraphicsJNI::getNativeTransferParameters(env, transferParameters);
- SkMatrix44 xyzMatrix = GraphicsJNI::getNativeXYZMatrix(env, xyzD50);
+ skcms_TransferFunction p = GraphicsJNI::getNativeTransferParameters(env, transferParameters);
+ skcms_Matrix3x3 xyzMatrix = GraphicsJNI::getNativeXYZMatrix(env, xyzD50);
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(p, xyzMatrix);
AHardwareBuffer* hwBuf = android_hardware_HardwareBuffer_getNativeHardwareBuffer(env,
hardwareBuffer);
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index 67d0c8a..ebeb5b2 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -424,30 +424,30 @@
///////////////////////////////////////////////////////////////////////////////
-SkColorSpaceTransferFn GraphicsJNI::getNativeTransferParameters(JNIEnv* env, jobject transferParams) {
- SkColorSpaceTransferFn p;
- p.fA = (float) env->GetDoubleField(transferParams, gTransferParams_aFieldID);
- p.fB = (float) env->GetDoubleField(transferParams, gTransferParams_bFieldID);
- p.fC = (float) env->GetDoubleField(transferParams, gTransferParams_cFieldID);
- p.fD = (float) env->GetDoubleField(transferParams, gTransferParams_dFieldID);
- p.fE = (float) env->GetDoubleField(transferParams, gTransferParams_eFieldID);
- p.fF = (float) env->GetDoubleField(transferParams, gTransferParams_fFieldID);
- p.fG = (float) env->GetDoubleField(transferParams, gTransferParams_gFieldID);
+skcms_TransferFunction GraphicsJNI::getNativeTransferParameters(JNIEnv* env, jobject transferParams) {
+ skcms_TransferFunction p;
+ p.a = (float) env->GetDoubleField(transferParams, gTransferParams_aFieldID);
+ p.b = (float) env->GetDoubleField(transferParams, gTransferParams_bFieldID);
+ p.c = (float) env->GetDoubleField(transferParams, gTransferParams_cFieldID);
+ p.d = (float) env->GetDoubleField(transferParams, gTransferParams_dFieldID);
+ p.e = (float) env->GetDoubleField(transferParams, gTransferParams_eFieldID);
+ p.f = (float) env->GetDoubleField(transferParams, gTransferParams_fFieldID);
+ p.g = (float) env->GetDoubleField(transferParams, gTransferParams_gFieldID);
return p;
}
-SkMatrix44 GraphicsJNI::getNativeXYZMatrix(JNIEnv* env, jfloatArray xyzD50) {
- SkMatrix44 xyzMatrix(SkMatrix44::kIdentity_Constructor);
+skcms_Matrix3x3 GraphicsJNI::getNativeXYZMatrix(JNIEnv* env, jfloatArray xyzD50) {
+ skcms_Matrix3x3 xyzMatrix;
jfloat* array = env->GetFloatArrayElements(xyzD50, NULL);
- xyzMatrix.setFloat(0, 0, array[0]);
- xyzMatrix.setFloat(1, 0, array[1]);
- xyzMatrix.setFloat(2, 0, array[2]);
- xyzMatrix.setFloat(0, 1, array[3]);
- xyzMatrix.setFloat(1, 1, array[4]);
- xyzMatrix.setFloat(2, 1, array[5]);
- xyzMatrix.setFloat(0, 2, array[6]);
- xyzMatrix.setFloat(1, 2, array[7]);
- xyzMatrix.setFloat(2, 2, array[8]);
+ xyzMatrix.vals[0][0] = array[0];
+ xyzMatrix.vals[1][0] = array[1];
+ xyzMatrix.vals[2][0] = array[2];
+ xyzMatrix.vals[0][1] = array[3];
+ xyzMatrix.vals[1][1] = array[4];
+ xyzMatrix.vals[2][1] = array[5];
+ xyzMatrix.vals[0][2] = array[6];
+ xyzMatrix.vals[1][2] = array[7];
+ xyzMatrix.vals[2][2] = array[8];
env->ReleaseFloatArrayElements(xyzD50, array, 0);
return xyzMatrix;
}
@@ -472,8 +472,8 @@
jfloatArray xyzD50 = (jfloatArray) env->CallObjectMethod(colorSpaceD50,
gColorSpaceRGB_getTransformMethodID);
- SkMatrix44 xyzMatrix = getNativeXYZMatrix(env, xyzD50);
- SkColorSpaceTransferFn transferFunction = getNativeTransferParameters(env, transferParams);
+ skcms_Matrix3x3 xyzMatrix = getNativeXYZMatrix(env, xyzD50);
+ skcms_TransferFunction transferFunction = getNativeTransferParameters(env, transferParams);
return SkColorSpace::MakeRGB(transferFunction, xyzMatrix);
}
@@ -499,30 +499,30 @@
} else if (decodeColorSpace.get() != nullptr) {
// Try to match against known RGB color spaces using the CIE XYZ D50
// conversion matrix and numerical transfer function parameters
- SkMatrix44 xyzMatrix(SkMatrix44::kUninitialized_Constructor);
+ skcms_Matrix3x3 xyzMatrix;
LOG_ALWAYS_FATAL_IF(!decodeColorSpace->toXYZD50(&xyzMatrix));
- SkColorSpaceTransferFn transferParams;
+ skcms_TransferFunction transferParams;
// We can only handle numerical transfer functions at the moment
LOG_ALWAYS_FATAL_IF(!decodeColorSpace->isNumericalTransferFn(&transferParams));
jobject params = env->NewObject(gTransferParameters_class,
gTransferParameters_constructorMethodID,
- transferParams.fA, transferParams.fB, transferParams.fC,
- transferParams.fD, transferParams.fE, transferParams.fF,
- transferParams.fG);
+ transferParams.a, transferParams.b, transferParams.c,
+ transferParams.d, transferParams.e, transferParams.f,
+ transferParams.g);
jfloatArray xyzArray = env->NewFloatArray(9);
jfloat xyz[9] = {
- xyzMatrix.getFloat(0, 0),
- xyzMatrix.getFloat(1, 0),
- xyzMatrix.getFloat(2, 0),
- xyzMatrix.getFloat(0, 1),
- xyzMatrix.getFloat(1, 1),
- xyzMatrix.getFloat(2, 1),
- xyzMatrix.getFloat(0, 2),
- xyzMatrix.getFloat(1, 2),
- xyzMatrix.getFloat(2, 2)
+ xyzMatrix.vals[0][0],
+ xyzMatrix.vals[1][0],
+ xyzMatrix.vals[2][0],
+ xyzMatrix.vals[0][1],
+ xyzMatrix.vals[1][1],
+ xyzMatrix.vals[2][1],
+ xyzMatrix.vals[0][2],
+ xyzMatrix.vals[1][2],
+ xyzMatrix.vals[2][2]
};
env->SetFloatArrayRegion(xyzArray, 0, 9, xyz);
diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h
index b0bd683..699d153 100644
--- a/core/jni/android/graphics/GraphicsJNI.h
+++ b/core/jni/android/graphics/GraphicsJNI.h
@@ -10,7 +10,6 @@
#include "SkPoint.h"
#include "SkRect.h"
#include "SkColorSpace.h"
-#include "SkMatrix44.h"
#include <jni.h>
#include <hwui/Canvas.h>
#include <hwui/Bitmap.h>
@@ -101,8 +100,8 @@
int srcStride, int x, int y, int width, int height,
SkBitmap* dstBitmap);
- static SkColorSpaceTransferFn getNativeTransferParameters(JNIEnv* env, jobject transferParams);
- static SkMatrix44 getNativeXYZMatrix(JNIEnv* env, jfloatArray xyzD50);
+ static skcms_TransferFunction getNativeTransferParameters(JNIEnv* env, jobject transferParams);
+ static skcms_Matrix3x3 getNativeXYZMatrix(JNIEnv* env, jfloatArray xyzD50);
static sk_sp<SkColorSpace> getNativeColorSpace(JNIEnv* env, jobject colorSpace);
static jobject getColorSpace(JNIEnv* env, sk_sp<SkColorSpace>& decodeColorSpace,
diff --git a/libs/hwui/DeviceInfo.cpp b/libs/hwui/DeviceInfo.cpp
index ed167e5..56b1885 100644
--- a/libs/hwui/DeviceInfo.cpp
+++ b/libs/hwui/DeviceInfo.cpp
@@ -79,8 +79,7 @@
switch (wcgDataspace) {
case ui::Dataspace::DISPLAY_P3:
*colorGamut = SkColorSpace::Gamut::kDCIP3_D65_Gamut;
- *colorSpace = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::Gamut::kDCIP3_D65_Gamut);
+ *colorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
break;
case ui::Dataspace::V0_SCRGB:
*colorGamut = SkColorSpace::Gamut::kSRGB_Gamut;
diff --git a/libs/hwui/tests/unit/SkiaCanvasTests.cpp b/libs/hwui/tests/unit/SkiaCanvasTests.cpp
index f3a7648..f6178af 100644
--- a/libs/hwui/tests/unit/SkiaCanvasTests.cpp
+++ b/libs/hwui/tests/unit/SkiaCanvasTests.cpp
@@ -44,8 +44,8 @@
}
TEST(SkiaCanvas, colorSpaceXform) {
- sk_sp<SkColorSpace> adobe = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kAdobeRGB_Gamut);
+ sk_sp<SkColorSpace> adobe = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
+ SkNamedGamut::kAdobeRGB);
SkImageInfo adobeInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kOpaque_SkAlphaType, adobe);
sk_sp<Bitmap> adobeBitmap = Bitmap::allocateHeapBitmap(adobeInfo);
diff --git a/libs/hwui/utils/Color.cpp b/libs/hwui/utils/Color.cpp
index dc347f6..4415a59 100644
--- a/libs/hwui/utils/Color.cpp
+++ b/libs/hwui/utils/Color.cpp
@@ -25,38 +25,6 @@
namespace android {
namespace uirenderer {
-static inline bool almostEqual(float a, float b) {
- return std::abs(a - b) < 1e-2f;
-}
-
-bool transferFunctionCloseToSRGB(const SkColorSpace* colorSpace) {
- if (colorSpace == nullptr) return true;
- if (colorSpace->isSRGB()) return true;
-
- SkColorSpaceTransferFn transferFunction;
- if (colorSpace->isNumericalTransferFn(&transferFunction)) {
- // sRGB transfer function params:
- const float sRGBParamA = 1 / 1.055f;
- const float sRGBParamB = 0.055f / 1.055f;
- const float sRGBParamC = 1 / 12.92f;
- const float sRGBParamD = 0.04045f;
- const float sRGBParamE = 0.0f;
- const float sRGBParamF = 0.0f;
- const float sRGBParamG = 2.4f;
-
- // This comparison will catch Display P3
- return almostEqual(sRGBParamA, transferFunction.fA) &&
- almostEqual(sRGBParamB, transferFunction.fB) &&
- almostEqual(sRGBParamC, transferFunction.fC) &&
- almostEqual(sRGBParamD, transferFunction.fD) &&
- almostEqual(sRGBParamE, transferFunction.fE) &&
- almostEqual(sRGBParamF, transferFunction.fF) &&
- almostEqual(sRGBParamG, transferFunction.fG);
- }
-
- return false;
-}
-
android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType) {
switch (colorType) {
case kRGBA_8888_SkColorType:
@@ -79,19 +47,19 @@
sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace) {
- SkColorSpace::Gamut gamut;
+ skcms_Matrix3x3 gamut;
switch (dataspace & HAL_DATASPACE_STANDARD_MASK) {
case HAL_DATASPACE_STANDARD_BT709:
- gamut = SkColorSpace::kSRGB_Gamut;
+ gamut = SkNamedGamut::kSRGB;
break;
case HAL_DATASPACE_STANDARD_BT2020:
- gamut = SkColorSpace::kRec2020_Gamut;
+ gamut = SkNamedGamut::kRec2020;
break;
case HAL_DATASPACE_STANDARD_DCI_P3:
- gamut = SkColorSpace::kDCIP3_D65_Gamut;
+ gamut = SkNamedGamut::kDCIP3;
break;
case HAL_DATASPACE_STANDARD_ADOBE_RGB:
- gamut = SkColorSpace::kAdobeRGB_Gamut;
+ gamut = SkNamedGamut::kAdobeRGB;
break;
case HAL_DATASPACE_STANDARD_UNSPECIFIED:
return nullptr;
@@ -109,9 +77,9 @@
switch (dataspace & HAL_DATASPACE_TRANSFER_MASK) {
case HAL_DATASPACE_TRANSFER_LINEAR:
- return SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, gamut);
+ return SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear, gamut);
case HAL_DATASPACE_TRANSFER_SRGB:
- return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, gamut);
+ return SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, gamut);
case HAL_DATASPACE_TRANSFER_GAMMA2_2:
return SkColorSpace::MakeRGB({2.2f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, gamut);
case HAL_DATASPACE_TRANSFER_GAMMA2_6:
diff --git a/libs/hwui/utils/Color.h b/libs/hwui/utils/Color.h
index 4473ce6..3880252 100644
--- a/libs/hwui/utils/Color.h
+++ b/libs/hwui/utils/Color.h
@@ -111,11 +111,6 @@
#endif
}
-// Returns whether the specified color space's transfer function can be
-// approximated with the native sRGB transfer function. This method
-// returns true for sRGB, gamma 2.2 and Display P3 for instance
-bool transferFunctionCloseToSRGB(const SkColorSpace* colorSpace);
-
android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType);
ANDROID_API sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace);