OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 // This test only works with the GPU backend. | 9 // This test only works with the GPU backend. |
10 | 10 |
11 #include "gm.h" | 11 #include "gm.h" |
12 | 12 |
13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
14 #include "GrContext.h" | 14 #include "GrContext.h" |
| 15 #include "GrDrawContext.h" |
15 #include "SkColorPriv.h" | 16 #include "SkColorPriv.h" |
16 #include "effects/GrPorterDuffXferProcessor.h" | 17 #include "effects/GrPorterDuffXferProcessor.h" |
17 #include "effects/GrSimpleTextureEffect.h" | 18 #include "effects/GrSimpleTextureEffect.h" |
18 | 19 |
19 namespace skiagm { | 20 namespace skiagm { |
20 | 21 |
21 static const int S = 200; | 22 static const int S = 200; |
22 | 23 |
23 class TexDataGM : public GM { | 24 class TexDataGM : public GM { |
24 public: | 25 public: |
25 TexDataGM() { | 26 TexDataGM() { |
26 this->setBGColor(0xff000000); | 27 this->setBGColor(0xff000000); |
27 } | 28 } |
28 | 29 |
29 protected: | 30 protected: |
30 SkString onShortName() override { | 31 SkString onShortName() override { |
31 return SkString("texdata"); | 32 return SkString("texdata"); |
32 } | 33 } |
33 | 34 |
34 SkISize onISize() override { | 35 SkISize onISize() override { |
35 return SkISize::Make(2*S, 2*S); | 36 return SkISize::Make(2*S, 2*S); |
36 } | 37 } |
37 | 38 |
38 void onDraw(SkCanvas* canvas) override { | 39 void onDraw(SkCanvas* canvas) override { |
39 GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTa
rget(); | 40 GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTa
rget(); |
40 GrContext* ctx = canvas->getGrContext(); | 41 GrContext* ctx = canvas->getGrContext(); |
41 if (ctx && target) { | 42 GrDrawContext* drawContext = ctx ? ctx->drawContext() : NULL; |
| 43 if (drawContext && target) { |
42 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S)); | 44 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S)); |
43 static const int stride = 2 * S; | 45 static const int stride = 2 * S; |
44 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40); | 46 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40); |
45 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff); | 47 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff); |
46 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00); | 48 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00); |
47 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80); | 49 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80); |
48 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00); | 50 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00); |
49 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00); | 51 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00); |
50 for (int i = 0; i < 2; ++i) { | 52 for (int i = 0; i < 2; ++i) { |
51 int offset = 0; | 53 int offset = 0; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 S * SK_Scalar1, | 106 S * SK_Scalar1, |
105 S * SK_Scalar1); | 107 S * SK_Scalar1); |
106 } else { | 108 } else { |
107 vm.reset(); | 109 vm.reset(); |
108 } | 110 } |
109 SkMatrix tm; | 111 SkMatrix tm; |
110 tm = vm; | 112 tm = vm; |
111 tm.postIDiv(2*S, 2*S); | 113 tm.postIDiv(2*S, 2*S); |
112 paint.addColorTextureProcessor(texture, tm); | 114 paint.addColorTextureProcessor(texture, tm); |
113 | 115 |
114 ctx->drawRect(target, clip, paint, vm, SkRect::MakeWH(2*S, 2*S))
; | 116 drawContext->drawRect(target, clip, paint, vm, SkRect::MakeWH(2*
S, 2*S)); |
115 | 117 |
116 // now update the lower right of the texture in first pass | 118 // now update the lower right of the texture in first pass |
117 // or upper right in second pass | 119 // or upper right in second pass |
118 offset = 0; | 120 offset = 0; |
119 for (int y = 0; y < S; ++y) { | 121 for (int y = 0; y < S; ++y) { |
120 for (int x = 0; x < S; ++x) { | 122 for (int x = 0; x < S; ++x) { |
121 gTextureData[offset + y * stride + x] = | 123 gTextureData[offset + y * stride + x] = |
122 ((x + y) % 2) ? (i ? green : red) : blue; | 124 ((x + y) % 2) ? (i ? green : red) : blue; |
123 } | 125 } |
124 } | 126 } |
125 texture->writePixels(S, (i ? 0 : S), S, S, | 127 texture->writePixels(S, (i ? 0 : S), S, S, |
126 texture->config(), gTextureData.get(), | 128 texture->config(), gTextureData.get(), |
127 4 * stride); | 129 4 * stride); |
128 ctx->drawRect(target, clip, paint, vm, SkRect::MakeWH(2*S, 2*S))
; | 130 drawContext->drawRect(target, clip, paint, vm, SkRect::MakeWH(2*
S, 2*S)); |
129 } | 131 } |
130 } else { | 132 } else { |
131 this->drawGpuOnlyMessage(canvas); | 133 this->drawGpuOnlyMessage(canvas); |
132 } | 134 } |
133 } | 135 } |
134 | 136 |
135 private: | 137 private: |
136 typedef GM INHERITED; | 138 typedef GM INHERITED; |
137 }; | 139 }; |
138 | 140 |
139 ////////////////////////////////////////////////////////////////////////////// | 141 ////////////////////////////////////////////////////////////////////////////// |
140 | 142 |
141 static GM* MyFactory(void*) { return new TexDataGM; } | 143 static GM* MyFactory(void*) { return new TexDataGM; } |
142 static GMRegistry reg(MyFactory); | 144 static GMRegistry reg(MyFactory); |
143 | 145 |
144 } | 146 } |
145 | 147 |
146 #endif | 148 #endif |
OLD | NEW |