OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GFX_ICC_PROFILE_H_ | 5 #ifndef UI_GFX_ICC_PROFILE_H_ |
6 #define UI_GFX_ICC_PROFILE_H_ | 6 #define UI_GFX_ICC_PROFILE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "ui/gfx/color_space.h" | 12 #include "ui/gfx/color_space.h" |
13 | 13 |
14 #if defined(OS_MACOSX) | 14 #if defined(OS_MACOSX) |
15 #include <CoreGraphics/CGColorSpace.h> | 15 #include <CoreGraphics/CGColorSpace.h> |
16 #endif | 16 #endif |
17 | 17 |
18 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); | 18 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); |
19 | 19 |
20 namespace mojo { | 20 namespace mojo { |
21 template <typename, typename> struct StructTraits; | 21 template <typename, typename> struct StructTraits; |
22 } | 22 } |
23 | 23 |
24 namespace gfx { | 24 namespace gfx { |
25 | 25 |
| 26 namespace mojom { |
| 27 class ICCProfileDataView; |
| 28 } |
| 29 |
26 // Used to represent a full ICC profile, usually retrieved from a monitor. It | 30 // Used to represent a full ICC profile, usually retrieved from a monitor. It |
27 // can be lossily compressed into a ColorSpace object. This structure should | 31 // can be lossily compressed into a ColorSpace object. This structure should |
28 // only be sent from higher-privilege processes to lower-privilege processes, | 32 // only be sent from higher-privilege processes to lower-privilege processes, |
29 // as parsing this structure is not secure. | 33 // as parsing this structure is not secure. |
30 class GFX_EXPORT ICCProfile { | 34 class GFX_EXPORT ICCProfile { |
31 public: | 35 public: |
32 ICCProfile(); | 36 ICCProfile(); |
33 ICCProfile(ICCProfile&& other); | 37 ICCProfile(ICCProfile&& other); |
34 ICCProfile(const ICCProfile& other); | 38 ICCProfile(const ICCProfile& other); |
35 ICCProfile& operator=(ICCProfile&& other); | 39 ICCProfile& operator=(ICCProfile&& other); |
36 ICCProfile& operator=(const ICCProfile& other); | 40 ICCProfile& operator=(const ICCProfile& other); |
37 ~ICCProfile(); | 41 ~ICCProfile(); |
38 bool operator==(const ICCProfile& other) const; | 42 bool operator==(const ICCProfile& other) const; |
39 bool operator!=(const ICCProfile& other) const; | 43 bool operator!=(const ICCProfile& other) const; |
40 | 44 |
41 // Returns the color profile of the monitor that can best represent color. | 45 // Returns the color profile of the monitor that can best represent color. |
42 // This profile should be used for creating content that does not know on | 46 // This profile should be used for creating content that does not know on |
43 // which monitor it will be displayed. | 47 // which monitor it will be displayed. |
44 static ICCProfile FromBestMonitor(); | 48 static ICCProfile FromBestMonitor(); |
45 #if defined(OS_MACOSX) | 49 #if defined(OS_MACOSX) |
46 static ICCProfile FromCGColorSpace(CGColorSpaceRef cg_color_space); | 50 static ICCProfile FromCGColorSpace(CGColorSpaceRef cg_color_space); |
47 #endif | 51 #endif |
48 | 52 |
49 // This will recover a ICCProfile from a compact ColorSpace representation. | 53 // This will recover a ICCProfile from a compact ColorSpace representation. |
50 // Internally, this will make an effort to create an identical ICCProfile | 54 // Internally, this will make an effort to create an identical ICCProfile |
51 // to the one that created |color_space|, but this is not guaranteed. | 55 // to the one that created |color_space|, but this is not guaranteed. |
52 static ICCProfile FromColorSpace(const gfx::ColorSpace& color_space); | 56 static ICCProfile FromColorSpace(const gfx::ColorSpace& color_space); |
| 57 static ICCProfile FromSkColorSpace(sk_sp<SkColorSpace> color_space); |
53 | 58 |
54 // Create directly from profile data. | 59 // Create directly from profile data. |
55 static ICCProfile FromData(const void* icc_profile, size_t size); | 60 static ICCProfile FromData(const char* icc_profile, size_t size); |
56 | 61 |
57 // This will perform a potentially-lossy conversion to a more compact color | 62 // This will perform a potentially-lossy conversion to a more compact color |
58 // space representation. | 63 // space representation. |
59 const ColorSpace& GetColorSpace() const; | 64 ColorSpace GetColorSpace() const; |
60 | 65 |
61 const std::vector<char>& GetData() const; | 66 const std::vector<char>& GetData() const; |
62 | 67 |
63 #if defined(OS_WIN) | 68 #if defined(OS_WIN) |
64 // This will read monitor ICC profiles from disk and cache the results for the | 69 // This will read monitor ICC profiles from disk and cache the results for the |
65 // other functions to read. This should not be called on the UI or IO thread. | 70 // other functions to read. This should not be called on the UI or IO thread. |
66 static void UpdateCachedProfilesOnBackgroundThread(); | 71 static void UpdateCachedProfilesOnBackgroundThread(); |
67 static bool CachedProfilesNeedUpdate(); | 72 static bool CachedProfilesNeedUpdate(); |
68 #endif | 73 #endif |
69 | 74 |
| 75 enum class Type { |
| 76 // This is not a valid profile. |
| 77 INVALID, |
| 78 // This is from a gfx::ColorSpace. This ensures that GetColorSpace returns |
| 79 // the exact same object as was used to create this. |
| 80 FROM_COLOR_SPACE, |
| 81 // This was created from ICC profile data. |
| 82 FROM_DATA, |
| 83 LAST = FROM_DATA |
| 84 }; |
| 85 |
70 private: | 86 private: |
71 // TODO(ccameron): Remove this function once its callerrs are gone. | |
72 static ICCProfile FromSkColorSpace(sk_sp<SkColorSpace> color_space); | |
73 static bool IsValidProfileLength(size_t length); | 87 static bool IsValidProfileLength(size_t length); |
74 void ComputeColorSpaceAndCache(); | 88 |
| 89 Type type_ = Type::INVALID; |
| 90 gfx::ColorSpace color_space_; |
| 91 std::vector<char> data_; |
75 | 92 |
76 // This globally identifies this ICC profile. It is used to look up this ICC | 93 // This globally identifies this ICC profile. It is used to look up this ICC |
77 // profile from a ColorSpace object created from it. The object is invalid if | 94 // profile from a ColorSpace object created from it. |
78 // |id_| is zero. | |
79 uint64_t id_ = 0; | 95 uint64_t id_ = 0; |
80 std::vector<char> data_; | |
81 | |
82 gfx::ColorSpace color_space_; | |
83 | 96 |
84 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, BT709toSRGBICC); | 97 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, BT709toSRGBICC); |
85 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, GetColorSpace); | 98 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, GetColorSpace); |
86 friend int ::LLVMFuzzerTestOneInput(const uint8_t*, size_t); | 99 friend int ::LLVMFuzzerTestOneInput(const uint8_t*, size_t); |
87 friend class ColorSpace; | 100 friend class ColorSpace; |
88 friend struct IPC::ParamTraits<gfx::ICCProfile>; | 101 friend struct IPC::ParamTraits<gfx::ICCProfile>; |
| 102 friend struct IPC::ParamTraits<gfx::ICCProfile::Type>; |
| 103 friend struct mojo::StructTraits<gfx::mojom::ICCProfileDataView, |
| 104 gfx::ICCProfile>; |
89 }; | 105 }; |
90 | 106 |
91 } // namespace gfx | 107 } // namespace gfx |
92 | 108 |
93 #endif // UI_GFX_ICC_PROFILE_H_ | 109 #endif // UI_GFX_ICC_PROFILE_H_ |
OLD | NEW |