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

Side by Side Diff: gm/texturedomaineffect.cpp

Issue 208313017: Add GM that tests GrTextureDomain and fix bug where kDecal_Mode gets incorrectly ignored. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Address comments and use gradients to init texture rather than noise. Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 // This test only works with the GPU backend.
10
11 #include "gm.h"
12
13 #if SK_SUPPORT_GPU
14
15 #include "GrContext.h"
16 #include "GrTest.h"
17 #include "effects/GrTextureDomain.h"
18 #include "SkBitmap.h"
19 #include "SkGr.h"
20 #include "SkGradientShader.h"
21
22 namespace skiagm {
23 /**
24 * This GM directly exercises GrTextureDomainEffect.
25 */
26 class TextureDomainEffect : public GM {
27 public:
28 TextureDomainEffect() {
29 this->setBGColor(0xFFFFFFFF);
30 }
31
32 protected:
33 virtual SkString onShortName() SK_OVERRIDE {
34 return SkString("texture_domain_effect");
35 }
36
37 virtual SkISize onISize() SK_OVERRIDE {
38 return make_isize(400, 800);
39 }
40
41 virtual uint32_t onGetFlags() const SK_OVERRIDE {
42 // This is a GPU-specific GM.
43 return kGPUOnly_Flag;
44 }
45
46 virtual void onOnceBeforeDraw() SK_OVERRIDE {
47 fBmp.allocN32Pixels(100, 100);
48 SkCanvas canvas(fBmp);
49 SkPaint paint;
50
51 SkColor colors1[] = { SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGRAY };
52 paint.setShader(SkGradientShader::CreateSweep(65.f, 75.f, colors1,
53 NULL, SK_ARRAY_COUNT(color s1)))->unref();
54 canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f,
55 fBmp.width() + 10.f, fBmp.height() + 10 .f), paint);
56
57 SkColor colors2[] = { SK_ColorMAGENTA, SK_ColorLTGRAY, SK_ColorYELLOW };
58 paint.setShader(SkGradientShader::CreateSweep(45.f, 55.f, colors2, NULL,
59 SK_ARRAY_COUNT(colors2)))- >unref();
60 paint.setXfermodeMode(SkXfermode::kDarken_Mode);
61 canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f,
62 fBmp.width() + 10.f, fBmp.height() + 10 .f), paint);
63
64 SkColor colors3[] = { SK_ColorBLUE, SK_ColorLTGRAY, SK_ColorGREEN };
65 paint.setShader(SkGradientShader::CreateSweep(25.f, 35.f, colors3, NULL,
66 SK_ARRAY_COUNT(colors3)))- >unref();
67 paint.setXfermodeMode(SkXfermode::kLighten_Mode);
68 canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f,
69 fBmp.width() + 10.f, fBmp.height() + 10 .f), paint);
70 }
71
72 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
73 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget ();
74 if (NULL == rt) {
75 return;
76 }
77 GrContext* context = rt->getContext();
78 if (NULL == context) {
79 return;
80 }
81
82 GrTestTarget tt;
83 context->getTestTarget(&tt);
84 if (NULL == tt.target()) {
85 SkDEBUGFAIL("Couldn't get Gr test target.");
86 return;
87 }
88
89 GrDrawState* drawState = tt.target()->drawState();
90
91 GrTexture* texture = GrLockAndRefCachedBitmapTexture(context, fBmp, NULL );
92 if (NULL == texture) {
93 return;
94 }
95
96 static const SkScalar kDrawPad = 10.f;
97 static const SkScalar kTestPad = 10.f;
98
99 SkTArray<SkMatrix> textureMatrices;
100 textureMatrices.push_back().setIDiv(texture->width(), texture->height()) ;
101 textureMatrices.push_back() = textureMatrices[0];
102 textureMatrices.back().postScale(1.5f, 0.85f);
103 textureMatrices.push_back() = textureMatrices[0];
104 textureMatrices.back().preRotate(45.f, texture->width() / 2.f, texture-> height() / 2.f);
105
106 const SkIRect texelDomains[] = {
107 SkIRect::MakeWH(fBmp.width(), fBmp.height()),
108 SkIRect::MakeXYWH(fBmp.width() / 4,
109 fBmp.height() / 4,
110 fBmp.width() / 2,
111 fBmp.height() / 2),
112 };
113
114 SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fBmp.width()),
115 SkIntToScalar(fBmp.height()));
116 renderRect.outset(kDrawPad, kDrawPad);
117
118 SkScalar y = kDrawPad + kTestPad;
119 for (int tm = 0; tm < textureMatrices.count(); ++tm) {
120 for (size_t d = 0; d < SK_ARRAY_COUNT(texelDomains); ++d) {
121 SkScalar x = kDrawPad + kTestPad;
122 for (int m = 0; m < GrTextureDomain::kModeCount; ++m) {
123 GrTextureDomain::Mode mode = (GrTextureDomain::Mode) m;
124 SkAutoTUnref<GrEffectRef> effect(
125 GrTextureDomainEffect::Create(texture, textureMatrices[t m],
126 GrTextureDomain::MakeTexelDomain (texture,
127 texelDomains[d]),
128 mode, GrTextureParams::kNone_Fil terMode));
129
130 if (!effect) {
131 continue;
132 }
133 SkMatrix viewMatrix;
134 viewMatrix.setTranslate(x, y);
135 drawState->reset(viewMatrix);
136 drawState->setRenderTarget(rt);
137 drawState->setColor(0xffffffff);
138 drawState->addColorEffect(effect, 1);
139
140 tt.target()->drawSimpleRect(renderRect);
141 x += renderRect.width() + kTestPad;
142 }
143 y += renderRect.height() + kTestPad;
144 }
145 }
146 GrUnlockAndUnrefCachedBitmapTexture(texture);
147 }
148
149 private:
150 SkBitmap fBmp;
151
152 typedef GM INHERITED;
153 };
154
155 DEF_GM( return SkNEW(TextureDomainEffect); )
156 }
157
158 #endif
OLDNEW
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698