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

Side by Side Diff: gm/colorcube.cpp

Issue 1821103004: Revert of Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.o… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 | « gm/color4f.cpp ('k') | gm/coloremoji.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 2014 Google Inc. 2 * Copyright 2014 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 "gm.h" 8 #include "gm.h"
9 #include "SkColorCubeFilter.h" 9 #include "SkColorCubeFilter.h"
10 #include "SkData.h" 10 #include "SkData.h"
11 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
12 #include "SkTemplates.h" 12 #include "SkTemplates.h"
13 13
14 namespace skiagm { 14 namespace skiagm {
15 15
16 static sk_sp<SkShader> MakeLinear() { 16 static sk_sp<SkShader> MakeLinear() {
17 static const SkPoint pts[2] = { 17 static const SkPoint pts[2] = {
18 { 0, 0 }, 18 { 0, 0 },
19 { SkIntToScalar(80), SkIntToScalar(80) } 19 { SkIntToScalar(80), SkIntToScalar(80) }
20 }; 20 };
21 static const SkColor colors[] = { SK_ColorYELLOW, SK_ColorBLUE }; 21 static const SkColor colors[] = { SK_ColorYELLOW, SK_ColorBLUE };
22 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kRepe at_TileMode, 0, 22 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kRepe at_TileMode, 0,
23 &SkMatrix::I()); 23 &SkMatrix::I());
24 } 24 }
25 25
26 class ColorCubeGM : public GM { 26 class ColorCubeGM : public GM {
27 public: 27 public:
28 ColorCubeGM() : fInitialized(false) { 28 ColorCubeGM()
29 : fInitialized(false)
30 , f3DLut4(nullptr)
31 , f3DLut8(nullptr)
32 , f3DLut16(nullptr)
33 , f3DLut32(nullptr)
34 , f3DLut64(nullptr)
35 {
29 this->setBGColor(0xFF000000); 36 this->setBGColor(0xFF000000);
30 } 37 }
31 38
39 ~ColorCubeGM() {
40 SkSafeUnref(f3DLut4);
41 SkSafeUnref(f3DLut8);
42 SkSafeUnref(f3DLut16);
43 SkSafeUnref(f3DLut32);
44 SkSafeUnref(f3DLut64);
45 }
46
32 protected: 47 protected:
33 SkString onShortName() override { 48 virtual SkString onShortName() {
34 return SkString("colorcube"); 49 return SkString("colorcube");
35 } 50 }
36 51
37 void make_3Dluts() { 52 void make_3Dluts() {
38 make_3Dlut(&f3DLut4, 4, true, false, false); 53 make_3Dlut(&f3DLut4, 4, true, false, false);
39 make_3Dlut(&f3DLut8, 8, false, true, false); 54 make_3Dlut(&f3DLut8, 8, false, true, false);
40 make_3Dlut(&f3DLut16, 16, false, true, true); 55 make_3Dlut(&f3DLut16, 16, false, true, true);
41 make_3Dlut(&f3DLut32, 32, true, true, false); 56 make_3Dlut(&f3DLut32, 32, true, true, false);
42 make_3Dlut(&f3DLut64, 64, true, false, true); 57 make_3Dlut(&f3DLut64, 64, true, false, true);
43 } 58 }
44 59
45 void make_bitmap() { 60 void make_bitmap() {
46 fBitmap.allocN32Pixels(80, 80); 61 fBitmap.allocN32Pixels(80, 80);
47 SkCanvas canvas(fBitmap); 62 SkCanvas canvas(fBitmap);
48 canvas.clear(0x00000000); 63 canvas.clear(0x00000000);
49 SkPaint paint; 64 SkPaint paint;
50 paint.setAntiAlias(true); 65 paint.setAntiAlias(true);
51 paint.setShader(MakeLinear()); 66 paint.setShader(MakeLinear());
52 canvas.drawRect(SkRect::MakeWH(80, 80), paint); 67 canvas.drawRect(SkRect::MakeWH(80, 80), paint);
53 } 68 }
54 69
55 void make_3Dlut(sk_sp<SkData>* data, int size, bool invR, bool invG, bool in vB) { 70 void make_3Dlut(SkData** data, int size, bool invR, bool invG, bool invB) {
56 *data = SkData::MakeUninitialized(sizeof(SkColor) * size * size * size); 71 *data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size);
57 SkColor* pixels = (SkColor*)((*data)->writable_data()); 72 SkColor* pixels = (SkColor*)((*data)->writable_data());
58 SkAutoTMalloc<uint8_t> lutMemory(size); 73 SkAutoTMalloc<uint8_t> lutMemory(size);
59 SkAutoTMalloc<uint8_t> invLutMemory(size); 74 SkAutoTMalloc<uint8_t> invLutMemory(size);
60 uint8_t* lut = lutMemory.get(); 75 uint8_t* lut = lutMemory.get();
61 uint8_t* invLut = invLutMemory.get(); 76 uint8_t* invLut = invLutMemory.get();
62 const int maxIndex = size - 1; 77 const int maxIndex = size - 1;
63 for (int i = 0; i < size; i++) { 78 for (int i = 0; i < size; i++) {
64 lut[i] = (i * 255) / maxIndex; 79 lut[i] = (i * 255) / maxIndex;
65 invLut[i] = ((maxIndex - i) * 255) / maxIndex; 80 invLut[i] = ((maxIndex - i) * 255) / maxIndex;
66 } 81 }
67 for (int r = 0; r < size; ++r) { 82 for (int r = 0; r < size; ++r) {
68 for (int g = 0; g < size; ++g) { 83 for (int g = 0; g < size; ++g) {
69 for (int b = 0; b < size; ++b) { 84 for (int b = 0; b < size; ++b) {
70 pixels[(size * ((size * b) + g)) + r] = sk_tool_utils::color _to_565( 85 pixels[(size * ((size * b) + g)) + r] = sk_tool_utils::color _to_565(
71 SkColorSetARGB(0xFF, 86 SkColorSetARGB(0xFF,
72 invR ? invLut[r] : lut[r], 87 invR ? invLut[r] : lut[r],
73 invG ? invLut[g] : lut[g], 88 invG ? invLut[g] : lut[g],
74 invB ? invLut[b] : lut[b])); 89 invB ? invLut[b] : lut[b]));
75 } 90 }
76 } 91 }
77 } 92 }
78 } 93 }
79 94
80 SkISize onISize() override { 95 virtual SkISize onISize() {
81 return SkISize::Make(500, 100); 96 return SkISize::Make(500, 100);
82 } 97 }
83 98
84 void onDraw(SkCanvas* canvas) override { 99 virtual void onDraw(SkCanvas* canvas) {
85 if (!fInitialized) { 100 if (!fInitialized) {
86 this->make_bitmap(); 101 this->make_bitmap();
87 this->make_3Dluts(); 102 this->make_3Dluts();
88 fInitialized = true; 103 fInitialized = true;
89 } 104 }
90 canvas->clear(0x00000000); 105 canvas->clear(0x00000000);
91 SkPaint paint; 106 SkPaint paint;
92 paint.setColorFilter(SkColorCubeFilter::Make(f3DLut4, 4)); 107 paint.setColorFilter(SkColorCubeFilter::Create(f3DLut4, 4))->unref();
93 canvas->drawBitmap(fBitmap, 10, 10, &paint); 108 canvas->drawBitmap(fBitmap, 10, 10, &paint);
94 109
95 paint.setColorFilter(SkColorCubeFilter::Make(f3DLut8, 8)); 110 paint.setColorFilter(SkColorCubeFilter::Create(f3DLut8, 8))->unref();
96 canvas->drawBitmap(fBitmap, 110, 10, &paint); 111 canvas->drawBitmap(fBitmap, 110, 10, &paint);
97 112
98 paint.setColorFilter(SkColorCubeFilter::Make(f3DLut16, 16)); 113 paint.setColorFilter(SkColorCubeFilter::Create(f3DLut16, 16))->unref();
99 canvas->drawBitmap(fBitmap, 210, 10, &paint); 114 canvas->drawBitmap(fBitmap, 210, 10, &paint);
100 115
101 paint.setColorFilter(SkColorCubeFilter::Make(f3DLut32, 32)); 116 paint.setColorFilter(SkColorCubeFilter::Create(f3DLut32, 32))->unref();
102 canvas->drawBitmap(fBitmap, 310, 10, &paint); 117 canvas->drawBitmap(fBitmap, 310, 10, &paint);
103 118
104 paint.setColorFilter(SkColorCubeFilter::Make(f3DLut64, 64)); 119 paint.setColorFilter(SkColorCubeFilter::Create(f3DLut64, 64))->unref();
105 canvas->drawBitmap(fBitmap, 410, 10, &paint); 120 canvas->drawBitmap(fBitmap, 410, 10, &paint);
106 } 121 }
107 122
108 private: 123 private:
109 typedef GM INHERITED; 124 typedef GM INHERITED;
110 bool fInitialized; 125 bool fInitialized;
111 SkBitmap fBitmap; 126 SkBitmap fBitmap;
112 sk_sp<SkData> f3DLut4; 127 SkData* f3DLut4;
113 sk_sp<SkData> f3DLut8; 128 SkData* f3DLut8;
114 sk_sp<SkData> f3DLut16; 129 SkData* f3DLut16;
115 sk_sp<SkData> f3DLut32; 130 SkData* f3DLut32;
116 sk_sp<SkData> f3DLut64; 131 SkData* f3DLut64;
117 }; 132 };
118 133
119 ////////////////////////////////////////////////////////////////////////////// 134 //////////////////////////////////////////////////////////////////////////////
120 135
121 static GM* MyFactory(void*) { return new ColorCubeGM; } 136 static GM* MyFactory(void*) { return new ColorCubeGM; }
122 static GMRegistry reg(MyFactory); 137 static GMRegistry reg(MyFactory);
123 138
124 } 139 }
OLDNEW
« no previous file with comments | « gm/color4f.cpp ('k') | gm/coloremoji.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698