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 "GrDrawContext.h" |
16 #include "SkColorPriv.h" | 16 #include "SkColorPriv.h" |
17 #include "effects/GrPorterDuffXferProcessor.h" | 17 #include "effects/GrPorterDuffXferProcessor.h" |
18 #include "effects/GrSimpleTextureEffect.h" | 18 #include "effects/GrSimpleTextureEffect.h" |
19 | 19 |
20 static const int S = 200; | 20 static const int S = 200; |
21 | 21 |
22 DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) { | 22 DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) { |
23 GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTa
rget(); | 23 GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTa
rget(); |
24 GrContext* ctx = canvas->getGrContext(); | 24 GrContext* ctx = canvas->getGrContext(); |
25 SkAutoTUnref<GrDrawContext> drawContext(ctx ? ctx->drawContext() : nullp
tr); | 25 SkAutoTUnref<GrDrawContext> drawContext(ctx ? ctx->drawContext(target) :
nullptr); |
26 if (drawContext && target) { | 26 if (drawContext && target) { |
27 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S)); | 27 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S)); |
28 static const int stride = 2 * S; | 28 static const int stride = 2 * S; |
29 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40); | 29 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40); |
30 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff); | 30 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff); |
31 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00); | 31 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00); |
32 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80); | 32 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80); |
33 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00); | 33 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00); |
34 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00); | 34 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00); |
35 for (int i = 0; i < 2; ++i) { | 35 for (int i = 0; i < 2; ++i) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 S * SK_Scalar1, | 89 S * SK_Scalar1, |
90 S * SK_Scalar1); | 90 S * SK_Scalar1); |
91 } else { | 91 } else { |
92 vm.reset(); | 92 vm.reset(); |
93 } | 93 } |
94 SkMatrix tm; | 94 SkMatrix tm; |
95 tm = vm; | 95 tm = vm; |
96 tm.postIDiv(2*S, 2*S); | 96 tm.postIDiv(2*S, 2*S); |
97 paint.addColorTextureProcessor(texture, tm); | 97 paint.addColorTextureProcessor(texture, tm); |
98 | 98 |
99 drawContext->drawRect(target, clip, paint, vm, SkRect::MakeWH(2*
S, 2*S)); | 99 drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S))
; |
100 | 100 |
101 // now update the lower right of the texture in first pass | 101 // now update the lower right of the texture in first pass |
102 // or upper right in second pass | 102 // or upper right in second pass |
103 offset = 0; | 103 offset = 0; |
104 for (int y = 0; y < S; ++y) { | 104 for (int y = 0; y < S; ++y) { |
105 for (int x = 0; x < S; ++x) { | 105 for (int x = 0; x < S; ++x) { |
106 gTextureData[offset + y * stride + x] = | 106 gTextureData[offset + y * stride + x] = |
107 ((x + y) % 2) ? (i ? green : red) : blue; | 107 ((x + y) % 2) ? (i ? green : red) : blue; |
108 } | 108 } |
109 } | 109 } |
110 texture->writePixels(S, (i ? 0 : S), S, S, | 110 texture->writePixels(S, (i ? 0 : S), S, S, |
111 texture->config(), gTextureData.get(), | 111 texture->config(), gTextureData.get(), |
112 4 * stride); | 112 4 * stride); |
113 drawContext->drawRect(target, clip, paint, vm, SkRect::MakeWH(2*
S, 2*S)); | 113 drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S))
; |
114 } | 114 } |
115 } else { | 115 } else { |
116 skiagm::GM::DrawGpuOnlyMessage(canvas); | 116 skiagm::GM::DrawGpuOnlyMessage(canvas); |
117 } | 117 } |
118 } | 118 } |
119 #endif | 119 #endif |
OLD | NEW |