OLD | NEW |
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 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::CreateLinear( | 22 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kRepe
at_TileMode, 0, |
23 pts, colors, nullptr, 2, SkShader::kRepeat_TileMode, 0, &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() | 28 ColorCubeGM() |
29 : fInitialized(false) | 29 : fInitialized(false) |
30 , f3DLut4(nullptr) | 30 , f3DLut4(nullptr) |
31 , f3DLut8(nullptr) | 31 , f3DLut8(nullptr) |
32 , f3DLut16(nullptr) | 32 , f3DLut16(nullptr) |
33 , f3DLut32(nullptr) | 33 , f3DLut32(nullptr) |
(...skipping 22 matching lines...) Expand all Loading... |
56 make_3Dlut(&f3DLut32, 32, true, true, false); | 56 make_3Dlut(&f3DLut32, 32, true, true, false); |
57 make_3Dlut(&f3DLut64, 64, true, false, true); | 57 make_3Dlut(&f3DLut64, 64, true, false, true); |
58 } | 58 } |
59 | 59 |
60 void make_bitmap() { | 60 void make_bitmap() { |
61 fBitmap.allocN32Pixels(80, 80); | 61 fBitmap.allocN32Pixels(80, 80); |
62 SkCanvas canvas(fBitmap); | 62 SkCanvas canvas(fBitmap); |
63 canvas.clear(0x00000000); | 63 canvas.clear(0x00000000); |
64 SkPaint paint; | 64 SkPaint paint; |
65 paint.setAntiAlias(true); | 65 paint.setAntiAlias(true); |
66 SkShader* shader = MakeLinear(); | 66 paint.setShader(MakeLinear()); |
67 paint.setShader(shader); | 67 canvas.drawRect(SkRect::MakeWH(80, 80), paint); |
68 SkRect r = { 0, 0, SkIntToScalar(80), SkIntToScalar(80) }; | |
69 canvas.drawRect(r, paint); | |
70 shader->unref(); | |
71 } | 68 } |
72 | 69 |
73 void make_3Dlut(SkData** data, int size, bool invR, bool invG, bool invB) { | 70 void make_3Dlut(SkData** data, int size, bool invR, bool invG, bool invB) { |
74 *data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size); | 71 *data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size); |
75 SkColor* pixels = (SkColor*)((*data)->writable_data()); | 72 SkColor* pixels = (SkColor*)((*data)->writable_data()); |
76 SkAutoTMalloc<uint8_t> lutMemory(size); | 73 SkAutoTMalloc<uint8_t> lutMemory(size); |
77 SkAutoTMalloc<uint8_t> invLutMemory(size); | 74 SkAutoTMalloc<uint8_t> invLutMemory(size); |
78 uint8_t* lut = lutMemory.get(); | 75 uint8_t* lut = lutMemory.get(); |
79 uint8_t* invLut = invLutMemory.get(); | 76 uint8_t* invLut = invLutMemory.get(); |
80 const int maxIndex = size - 1; | 77 const int maxIndex = size - 1; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 SkData* f3DLut32; | 130 SkData* f3DLut32; |
134 SkData* f3DLut64; | 131 SkData* f3DLut64; |
135 }; | 132 }; |
136 | 133 |
137 ////////////////////////////////////////////////////////////////////////////// | 134 ////////////////////////////////////////////////////////////////////////////// |
138 | 135 |
139 static GM* MyFactory(void*) { return new ColorCubeGM; } | 136 static GM* MyFactory(void*) { return new ColorCubeGM; } |
140 static GMRegistry reg(MyFactory); | 137 static GMRegistry reg(MyFactory); |
141 | 138 |
142 } | 139 } |
OLD | NEW |