Index: ui/gfx/color_space.cc |
diff --git a/ui/gfx/color_space.cc b/ui/gfx/color_space.cc |
index 849d2201fc949e04b4fe87994917e245dc772725..507d285308db24f1b318ac60c07e025e07d77494 100644 |
--- a/ui/gfx/color_space.cc |
+++ b/ui/gfx/color_space.cc |
@@ -65,10 +65,25 @@ ColorSpace::ColorSpace(int primaries, int transfer, int matrix, RangeID range) |
// TODO: Set profile_id_ |
} |
+ColorSpace::ColorSpace(const ColorSpace& other) |
+ : primaries_(other.primaries_), |
+ transfer_(other.transfer_), |
+ matrix_(other.matrix_), |
+ range_(other.range_), |
+ icc_profile_id_(other.icc_profile_id_), |
+ sk_color_space_(other.sk_color_space_) { |
+ memcpy(custom_primary_matrix_, other.custom_primary_matrix_, |
+ sizeof(custom_primary_matrix_)); |
+} |
+ |
+ColorSpace::~ColorSpace() = default; |
+ |
// static |
ColorSpace ColorSpace::CreateSRGB() { |
- return ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, |
+ ColorSpace result(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, |
RangeID::FULL); |
+ result.sk_color_space_ = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
+ return result; |
} |
// Static |
@@ -140,20 +155,7 @@ bool ColorSpace::operator<(const ColorSpace& other) const { |
} |
sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const { |
- // Unspecified color spaces are represented as nullptr SkColorSpaces. |
- if (*this == gfx::ColorSpace()) |
- return nullptr; |
- if (*this == gfx::ColorSpace::CreateSRGB()) |
- return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
- |
- // TODO(crbug.com/634102): Support more than just ICC profile based color |
- // spaces. The DCHECK here is to ensure that callers that expect a valid |
- // result are notified of this incomplete functionality. |
- std::vector<char> icc_data = gfx::ICCProfile::FromColorSpace(*this).GetData(); |
- sk_sp<SkColorSpace> result = |
- SkColorSpace::MakeICC(icc_data.data(), icc_data.size()); |
- DCHECK(result); |
- return result; |
+ return sk_color_space_; |
} |
ColorSpace ColorSpace::FromSkColorSpace( |
@@ -165,8 +167,10 @@ ColorSpace ColorSpace::FromSkColorSpace( |
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get())) |
return gfx::ColorSpace::CreateSRGB(); |
- // TODO(crbug.com/634102): Add conversion to gfx::ColorSpace. |
- return gfx::ColorSpace(); |
+ // TODO(crbug.com/634102): Add conversion to gfx::ColorSpace for |
+ // non-ICC-profile based color spaces. |
+ ICCProfile icc_profile = ICCProfile::FromSkColorSpace(sk_color_space); |
+ return icc_profile.GetColorSpace(); |
} |
} // namespace gfx |