1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "third_party/blink/renderer/platform/graphics/canvas_color_params.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/blink/renderer/platform/graphics/color_correction_test_utils.h"
9 #include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
10 #include "ui/gfx/color_space.h"
11
12 namespace blink {
13
14 // When drawing a color managed canvas, the target SkColorSpace is obtained by
15 // calling CanvasColorParams::GetSkColorSpaceForSkSurfaces(). When drawing media
16 // to the canvas, the target gfx::ColorSpace is returned by CanvasColorParams::
17 // GetStorageGfxColorSpace(). This test verifies that the two different color
18 // spaces are approximately the same for different CanvasColorParam objects.
TEST(CanvasColorParamsTest,MatchSkColorSpaceWithGfxColorSpace)19 TEST(CanvasColorParamsTest, MatchSkColorSpaceWithGfxColorSpace) {
20 CanvasColorSpace canvas_color_spaces[] = {
21 CanvasColorSpace::kSRGB,
22 CanvasColorSpace::kLinearRGB,
23 CanvasColorSpace::kRec2020,
24 CanvasColorSpace::kP3,
25 };
26 for (int iter_color_space = 0; iter_color_space < 4; iter_color_space++) {
27 CanvasColorParams color_params(canvas_color_spaces[iter_color_space],
28 CanvasPixelFormat::kF16, kNonOpaque);
29 sk_sp<SkColorSpace> canvas_drawing_color_space =
30 color_params.GetSkColorSpace();
31 sk_sp<SkColorSpace> canvas_media_color_space =
32 color_params.GetStorageGfxColorSpace().ToSkColorSpace();
33 ASSERT_TRUE(ColorCorrectionTestUtils::MatchColorSpace(
34 canvas_drawing_color_space, canvas_media_color_space));
35 }
36 }
37
38 } // namespace blink
39