OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 // This test only works with the GPU backend. | 8 // This test only works with the GPU backend. |
9 | 9 |
10 #include "gm.h" | 10 #include "gm.h" |
11 | 11 |
12 #if SK_SUPPORT_GPU | 12 #if SK_SUPPORT_GPU |
13 #include "GrContext.h" | 13 #include "GrContext.h" |
14 #include "GrDrawContext.h" | 14 #include "GrDrawContext.h" |
15 #include "SkColorPriv.h" | 15 #include "SkColorPriv.h" |
16 #include "effects/GrPorterDuffXferProcessor.h" | 16 #include "effects/GrPorterDuffXferProcessor.h" |
17 #include "effects/GrSimpleTextureEffect.h" | 17 #include "effects/GrSimpleTextureEffect.h" |
18 | 18 |
19 static const int S = 200; | 19 static const int S = 200; |
20 | 20 |
21 DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) { | 21 DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) { |
22 GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTa
rget(); | 22 GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawCont
ext(); |
23 GrContext* ctx = canvas->getGrContext(); | 23 if (!drawContext) { |
24 sk_sp<GrDrawContext> drawContext(ctx ? ctx->drawContext(sk_ref_sp(target
)) : nullptr); | 24 skiagm::GM::DrawGpuOnlyMessage(canvas); |
25 if (drawContext && target) { | 25 return; |
26 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S)); | 26 } |
27 static const int stride = 2 * S; | |
28 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40); | |
29 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff); | |
30 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00); | |
31 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80); | |
32 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00); | |
33 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00); | |
34 for (int i = 0; i < 2; ++i) { | |
35 int offset = 0; | |
36 // fill upper-left | |
37 for (int y = 0; y < S; ++y) { | |
38 for (int x = 0; x < S; ++x) { | |
39 gTextureData[offset + y * stride + x] = gray; | |
40 } | |
41 } | |
42 // fill upper-right | |
43 offset = S; | |
44 for (int y = 0; y < S; ++y) { | |
45 for (int x = 0; x < S; ++x) { | |
46 gTextureData[offset + y * stride + x] = white; | |
47 } | |
48 } | |
49 // fill lower left | |
50 offset = S * stride; | |
51 for (int y = 0; y < S; ++y) { | |
52 for (int x = 0; x < S; ++x) { | |
53 gTextureData[offset + y * stride + x] = black; | |
54 } | |
55 } | |
56 // fill lower right | |
57 offset = S * stride + S; | |
58 for (int y = 0; y < S; ++y) { | |
59 for (int x = 0; x < S; ++x) { | |
60 gTextureData[offset + y * stride + x] = gray; | |
61 } | |
62 } | |
63 | 27 |
64 GrSurfaceDesc desc; | 28 GrContext* context = canvas->getGrContext(); |
65 // use RT flag bit because in GL it makes the texture be bottom-
up | 29 if (!context) { |
66 desc.fFlags = i ? kRenderTarget_GrSurfaceFlag : | 30 return; |
67 kNone_GrSurfaceFlags; | 31 } |
68 desc.fConfig = kSkia8888_GrPixelConfig; | |
69 desc.fWidth = 2 * S; | |
70 desc.fHeight = 2 * S; | |
71 GrTexture* texture = ctx->textureProvider()->createTexture( | |
72 desc, SkBudgeted::kNo, gTextureData.get(), 0); | |
73 | 32 |
74 if (!texture) { | 33 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S)); |
75 return; | 34 static const int stride = 2 * S; |
76 } | 35 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40); |
77 SkAutoTUnref<GrTexture> au(texture); | 36 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff); |
| 37 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00); |
| 38 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80); |
| 39 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00); |
| 40 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00); |
| 41 for (int i = 0; i < 2; ++i) { |
| 42 int offset = 0; |
| 43 // fill upper-left |
| 44 for (int y = 0; y < S; ++y) { |
| 45 for (int x = 0; x < S; ++x) { |
| 46 gTextureData[offset + y * stride + x] = gray; |
| 47 } |
| 48 } |
| 49 // fill upper-right |
| 50 offset = S; |
| 51 for (int y = 0; y < S; ++y) { |
| 52 for (int x = 0; x < S; ++x) { |
| 53 gTextureData[offset + y * stride + x] = white; |
| 54 } |
| 55 } |
| 56 // fill lower left |
| 57 offset = S * stride; |
| 58 for (int y = 0; y < S; ++y) { |
| 59 for (int x = 0; x < S; ++x) { |
| 60 gTextureData[offset + y * stride + x] = black; |
| 61 } |
| 62 } |
| 63 // fill lower right |
| 64 offset = S * stride + S; |
| 65 for (int y = 0; y < S; ++y) { |
| 66 for (int x = 0; x < S; ++x) { |
| 67 gTextureData[offset + y * stride + x] = gray; |
| 68 } |
| 69 } |
78 | 70 |
79 // setup new clip | 71 GrSurfaceDesc desc; |
80 GrClip clip(SkRect::MakeWH(2*S, 2*S)); | 72 // use RT flag bit because in GL it makes the texture be bottom-up |
| 73 desc.fFlags = i ? kRenderTarget_GrSurfaceFlag : |
| 74 kNone_GrSurfaceFlags; |
| 75 desc.fConfig = kSkia8888_GrPixelConfig; |
| 76 desc.fWidth = 2 * S; |
| 77 desc.fHeight = 2 * S; |
| 78 GrTexture* texture = context->textureProvider()->createTexture( |
| 79 desc, SkBudgeted::kNo, gTextureData.get(), 0); |
81 | 80 |
82 GrPaint paint; | 81 if (!texture) { |
83 paint.setPorterDuffXPFactory(SkXfermode::kSrcOver_Mode); | 82 return; |
| 83 } |
| 84 SkAutoTUnref<GrTexture> au(texture); |
84 | 85 |
85 SkMatrix vm; | 86 // setup new clip |
86 if (i) { | 87 GrClip clip(SkRect::MakeWH(2*S, 2*S)); |
87 vm.setRotate(90 * SK_Scalar1, | |
88 S * SK_Scalar1, | |
89 S * SK_Scalar1); | |
90 } else { | |
91 vm.reset(); | |
92 } | |
93 SkMatrix tm; | |
94 tm = vm; | |
95 tm.postIDiv(2*S, 2*S); | |
96 paint.addColorTextureProcessor(texture, tm); | |
97 | 88 |
98 drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S))
; | 89 GrPaint paint; |
| 90 paint.setPorterDuffXPFactory(SkXfermode::kSrcOver_Mode); |
99 | 91 |
100 // now update the lower right of the texture in first pass | 92 SkMatrix vm; |
101 // or upper right in second pass | 93 if (i) { |
102 offset = 0; | 94 vm.setRotate(90 * SK_Scalar1, |
103 for (int y = 0; y < S; ++y) { | 95 S * SK_Scalar1, |
104 for (int x = 0; x < S; ++x) { | 96 S * SK_Scalar1); |
105 gTextureData[offset + y * stride + x] = | 97 } else { |
106 ((x + y) % 2) ? (i ? green : red) : blue; | 98 vm.reset(); |
107 } | 99 } |
108 } | 100 SkMatrix tm; |
109 texture->writePixels(S, (i ? 0 : S), S, S, | 101 tm = vm; |
110 texture->config(), gTextureData.get(), | 102 tm.postIDiv(2*S, 2*S); |
111 4 * stride); | 103 paint.addColorTextureProcessor(texture, tm); |
112 drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S))
; | 104 |
| 105 drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S)); |
| 106 |
| 107 // now update the lower right of the texture in first pass |
| 108 // or upper right in second pass |
| 109 offset = 0; |
| 110 for (int y = 0; y < S; ++y) { |
| 111 for (int x = 0; x < S; ++x) { |
| 112 gTextureData[offset + y * stride + x] = |
| 113 ((x + y) % 2) ? (i ? green : red) : blue; |
113 } | 114 } |
114 } else { | |
115 skiagm::GM::DrawGpuOnlyMessage(canvas); | |
116 } | 115 } |
| 116 texture->writePixels(S, (i ? 0 : S), S, S, |
| 117 texture->config(), gTextureData.get(), |
| 118 4 * stride); |
| 119 drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S)); |
| 120 } |
117 } | 121 } |
118 #endif | 122 #endif |
| 123 |
OLD | NEW |