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

Side by Side Diff: gm/texdata.cpp

Issue 1225923010: Refugee from Dead Machine 4: MDB Monster Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Last update from dead machine Created 4 years, 7 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/imagefiltersscaled.cpp ('k') | gm/texturedomaineffect.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 /* 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 if (!ctx) {
26 skiagm::GM::DrawGpuOnlyMessage(canvas);
27 return;
28 }
25 SkAutoTUnref<GrDrawContext> drawContext(ctx ? ctx->drawContext(target) : nullptr); 29 SkAutoTUnref<GrDrawContext> drawContext(ctx ? ctx->drawContext(target) : nullptr);
26 if (drawContext && target) { 30 if (drawContext && target) {
27 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S)); 31 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S));
28 static const int stride = 2 * S; 32 static const int stride = 2 * S;
29 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40); 33 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
30 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff); 34 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
31 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00); 35 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
32 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80); 36 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
33 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00); 37 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
34 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00); 38 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 desc.fWidth = 2 * S; 74 desc.fWidth = 2 * S;
71 desc.fHeight = 2 * S; 75 desc.fHeight = 2 * S;
72 GrTexture* texture = ctx->textureProvider()->createTexture( 76 GrTexture* texture = ctx->textureProvider()->createTexture(
73 desc, false, gTextureData.get(), 0); 77 desc, false, gTextureData.get(), 0);
74 78
75 if (!texture) { 79 if (!texture) {
76 return; 80 return;
77 } 81 }
78 SkAutoTUnref<GrTexture> au(texture); 82 SkAutoTUnref<GrTexture> au(texture);
79 83
84 SkASSERT(texture->fromRawPixels2());
85
86 SkAutoTUnref<GrDrawContext> dc9;
87 if (i) {
88 texture->setFromRawPixels(false);
89 dc9.reset(ctx->drawContext(texture->asRenderTarget()));
90 if (!dc9) {
91 return;
92 }
93 } else {
94 texture->setException(true);
95 }
96
80 // setup new clip 97 // setup new clip
81 GrClip clip(SkRect::MakeWH(2*S, 2*S)); 98 GrClip clip(SkRect::MakeWH(2*S, 2*S));
82 99
83 GrPaint paint; 100 GrPaint paint;
84 paint.setPorterDuffXPFactory(SkXfermode::kSrcOver_Mode); 101 paint.setPorterDuffXPFactory(SkXfermode::kSrcOver_Mode);
85 102
86 SkMatrix vm; 103 SkMatrix vm;
87 if (i) { 104 if (i) {
88 vm.setRotate(90 * SK_Scalar1, 105 vm.setRotate(90 * SK_Scalar1,
89 S * SK_Scalar1, 106 S * SK_Scalar1,
90 S * SK_Scalar1); 107 S * SK_Scalar1);
91 } else { 108 } else {
92 vm.reset(); 109 vm.reset();
93 } 110 }
94 SkMatrix tm; 111 SkMatrix tm;
95 tm = vm; 112 tm = vm;
96 tm.postIDiv(2*S, 2*S); 113 tm.postIDiv(2*S, 2*S);
97 paint.addColorTextureProcessor(texture, tm); 114 paint.addColorTextureProcessor(texture, tm, target);
98 115
99 drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S)) ; 116 drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S)) ;
100 117
118 #if 0
119 // Here we've used dc9/texture as a src for a drawRect. This "cl osed"
120 // the DT. We need to reopen it here so we can use dc9/texture f or
121 // the writePixels
122 if (dc9) {
123 dc9 = ctx->drawContext(texture->asRenderTarget());
124 }
125 #endif
126
101 // now update the lower right of the texture in first pass 127 // now update the lower right of the texture in first pass
102 // or upper right in second pass 128 // or upper right in second pass
103 offset = 0; 129 offset = 0;
104 for (int y = 0; y < S; ++y) { 130 for (int y = 0; y < S; ++y) {
105 for (int x = 0; x < S; ++x) { 131 for (int x = 0; x < S; ++x) {
106 gTextureData[offset + y * stride + x] = 132 gTextureData[offset + y * stride + x] =
107 ((x + y) % 2) ? (i ? green : red) : blue; 133 ((x + y) % 2) ? (i ? green : red) : blue;
108 } 134 }
109 } 135 }
110 texture->writePixels(S, (i ? 0 : S), S, S, 136 texture->writePixels(dc9, S, (i ? 0 : S), S, S,
111 texture->config(), gTextureData.get(), 137 texture->config(), gTextureData.get(),
112 4 * stride); 138 4 * stride);
113 drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S)) ; 139 drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S)) ;
114 } 140 }
115 } else {
116 skiagm::GM::DrawGpuOnlyMessage(canvas);
117 } 141 }
118 } 142 }
119 #endif 143 #endif
OLDNEW
« no previous file with comments | « gm/imagefiltersscaled.cpp ('k') | gm/texturedomaineffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698