Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: src/core/SkColorSpace.cpp

Issue 1949313003: Reland of SkOncePtr -> SkOnce (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/private/SkOncePtr.h ('k') | src/core/SkData.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkAtomics.h" 8 #include "SkAtomics.h"
9 #include "SkColorSpace.h" 9 #include "SkColorSpace.h"
10 #include "SkOncePtr.h" 10 #include "SkOnce.h"
11 11
12 static bool color_space_almost_equal(float a, float b) { 12 static bool color_space_almost_equal(float a, float b) {
13 return SkTAbs(a - b) < 0.01f; 13 return SkTAbs(a - b) < 0.01f;
14 } 14 }
15 15
16 void SkFloat3::dump() const { 16 void SkFloat3::dump() const {
17 SkDebugf("[%7.4f %7.4f %7.4f]\n", fVec[0], fVec[1], fVec[2]); 17 SkDebugf("[%7.4f %7.4f %7.4f]\n", fVec[0], fVec[1], fVec[2]);
18 } 18 }
19 19
20 //////////////////////////////////////////////////////////////////////////////// ////////////////// 20 //////////////////////////////////////////////////////////////////////////////// //////////////////
(...skipping 15 matching lines...) Expand all
36 , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID)) 36 , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID))
37 , fNamed(kUnknown_Named) 37 , fNamed(kUnknown_Named)
38 {} 38 {}
39 39
40 const float gSRGB_toXYZD50[] { 40 const float gSRGB_toXYZD50[] {
41 0.4358f, 0.2224f, 0.0139f, // * R 41 0.4358f, 0.2224f, 0.0139f, // * R
42 0.3853f, 0.7170f, 0.0971f, // * G 42 0.3853f, 0.7170f, 0.0971f, // * G
43 0.1430f, 0.0606f, 0.7139f, // * B 43 0.1430f, 0.0606f, 0.7139f, // * B
44 }; 44 };
45 45
46 SK_DECLARE_STATIC_ONCE_PTR(SkColorSpace, sRGB);
47
48 sk_sp<SkColorSpace> SkColorSpace::NewRGB(SkGammas gammas, const SkMatrix44& toXY ZD50) { 46 sk_sp<SkColorSpace> SkColorSpace::NewRGB(SkGammas gammas, const SkMatrix44& toXY ZD50) {
49 // Check if we really have sRGB 47 // Check if we really have sRGB
50 if (color_space_almost_equal(2.2f, gammas.fRed.fValue) && 48 if (color_space_almost_equal(2.2f, gammas.fRed.fValue) &&
51 color_space_almost_equal(2.2f, gammas.fGreen.fValue) && 49 color_space_almost_equal(2.2f, gammas.fGreen.fValue) &&
52 color_space_almost_equal(2.2f, gammas.fBlue.fValue) && 50 color_space_almost_equal(2.2f, gammas.fBlue.fValue) &&
53 color_space_almost_equal(toXYZD50.getFloat(0, 0), gSRGB_toXYZD50[0]) && 51 color_space_almost_equal(toXYZD50.getFloat(0, 0), gSRGB_toXYZD50[0]) &&
54 color_space_almost_equal(toXYZD50.getFloat(0, 1), gSRGB_toXYZD50[1]) && 52 color_space_almost_equal(toXYZD50.getFloat(0, 1), gSRGB_toXYZD50[1]) &&
55 color_space_almost_equal(toXYZD50.getFloat(0, 2), gSRGB_toXYZD50[2]) && 53 color_space_almost_equal(toXYZD50.getFloat(0, 2), gSRGB_toXYZD50[2]) &&
56 color_space_almost_equal(toXYZD50.getFloat(1, 0), gSRGB_toXYZD50[3]) && 54 color_space_almost_equal(toXYZD50.getFloat(1, 0), gSRGB_toXYZD50[3]) &&
57 color_space_almost_equal(toXYZD50.getFloat(1, 1), gSRGB_toXYZD50[4]) && 55 color_space_almost_equal(toXYZD50.getFloat(1, 1), gSRGB_toXYZD50[4]) &&
58 color_space_almost_equal(toXYZD50.getFloat(1, 2), gSRGB_toXYZD50[5]) && 56 color_space_almost_equal(toXYZD50.getFloat(1, 2), gSRGB_toXYZD50[5]) &&
59 color_space_almost_equal(toXYZD50.getFloat(2, 0), gSRGB_toXYZD50[6]) && 57 color_space_almost_equal(toXYZD50.getFloat(2, 0), gSRGB_toXYZD50[6]) &&
60 color_space_almost_equal(toXYZD50.getFloat(2, 1), gSRGB_toXYZD50[7]) && 58 color_space_almost_equal(toXYZD50.getFloat(2, 1), gSRGB_toXYZD50[7]) &&
61 color_space_almost_equal(toXYZD50.getFloat(2, 2), gSRGB_toXYZD50[8]) && 59 color_space_almost_equal(toXYZD50.getFloat(2, 2), gSRGB_toXYZD50[8]) &&
62 color_space_almost_equal(toXYZD50.getFloat(0, 3), 0.0f) && 60 color_space_almost_equal(toXYZD50.getFloat(0, 3), 0.0f) &&
63 color_space_almost_equal(toXYZD50.getFloat(1, 3), 0.0f) && 61 color_space_almost_equal(toXYZD50.getFloat(1, 3), 0.0f) &&
64 color_space_almost_equal(toXYZD50.getFloat(2, 3), 0.0f) && 62 color_space_almost_equal(toXYZD50.getFloat(2, 3), 0.0f) &&
65 color_space_almost_equal(toXYZD50.getFloat(3, 0), 0.0f) && 63 color_space_almost_equal(toXYZD50.getFloat(3, 0), 0.0f) &&
66 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) && 64 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) &&
67 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) && 65 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) &&
68 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f)) 66 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f))
69 { 67 {
70 return SkColorSpace::NewNamed(kSRGB_Named); 68 return SkColorSpace::NewNamed(kSRGB_Named);
71 } 69 }
72 70
73 return sk_sp<SkColorSpace>(new SkColorSpace(std::move(gammas), toXYZD50, kUn known_Named)); 71 return sk_sp<SkColorSpace>(new SkColorSpace(std::move(gammas), toXYZD50, kUn known_Named));
74 } 72 }
75 73
76 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { 74 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) {
75 static SkOnce once;
76 static SkColorSpace* sRGB;
77
77 switch (named) { 78 switch (named) {
78 case kSRGB_Named: { 79 case kSRGB_Named: {
79 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); 80 once([] {
80 srgbToxyzD50.set3x3ColMajorf(gSRGB_toXYZD50); 81 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
81 return sk_ref_sp(sRGB.get([=]{ 82 srgbToxyzD50.set3x3ColMajorf(gSRGB_toXYZD50);
82 return new SkColorSpace(SkGammas(2.2f, 2.2f, 2.2f), srgbToxyzD50 , kSRGB_Named); 83 sRGB = new SkColorSpace(SkGammas(2.2f, 2.2f, 2.2f), srgbToxyzD50 , kSRGB_Named);
83 })); 84 });
85 return sk_ref_sp(sRGB);
84 } 86 }
85 default: 87 default:
86 break; 88 break;
87 } 89 }
88 return nullptr; 90 return nullptr;
89 } 91 }
90 92
91 //////////////////////////////////////////////////////////////////////////////// /////////////////// 93 //////////////////////////////////////////////////////////////////////////////// ///////////////////
92 94
93 #include "SkFixed.h" 95 #include "SkFixed.h"
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 toXYZ)); 634 toXYZ));
633 } 635 }
634 636
635 } 637 }
636 default: 638 default:
637 break; 639 break;
638 } 640 }
639 641
640 return_null("ICC profile contains unsupported colorspace"); 642 return_null("ICC profile contains unsupported colorspace");
641 } 643 }
OLDNEW
« no previous file with comments | « include/private/SkOncePtr.h ('k') | src/core/SkData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698