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

Side by Side Diff: gm/bleed.cpp

Issue 23172013: Third (and hopefully final) change to support bleed flag in Ganesh (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fixed comment Created 7 years, 4 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 | src/gpu/SkGpuDevice.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 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 #include "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkBlurMaskFilter.h"
10 11
11 #if SK_SUPPORT_GPU 12 #if SK_SUPPORT_GPU
12 #include "GrContext.h" 13 #include "GrContext.h"
13 14
14 namespace skiagm { 15 namespace skiagm {
15 extern GrContext* GetGr(); 16 extern GrContext* GetGr();
16 }; 17 };
17 18
18 void GrContext::setMaxTextureSizeOverride(int maxTextureSizeOverride) { 19 void GrContext::setMaxTextureSizeOverride(int maxTextureSizeOverride) {
19 fMaxTextureSizeOverride = maxTextureSizeOverride; 20 fMaxTextureSizeOverride = maxTextureSizeOverride;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 133
133 SkPaint paint; 134 SkPaint paint;
134 paint.setFilterBitmap(filter); 135 paint.setFilterBitmap(filter);
135 136
136 canvas->save(); 137 canvas->save();
137 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); 138 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
138 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags); 139 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags);
139 canvas->restore(); 140 canvas->restore();
140 } 141 }
141 142
143 // Draw the center of the small bitmap with a mask filter
144 void drawCase4(SkCanvas* canvas, int transX, int transY,
145 SkCanvas::DrawBitmapRectFlags flags, bool filter) {
146 SkRect src = SkRect::MakeXYWH(1, 1,
147 kSmallTextureSize-2,
148 kSmallTextureSize-2);
149 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc alar(kBlockSize));
150
151 SkPaint paint;
152 paint.setFilterBitmap(filter);
153 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkIntToScalar(3),
154 SkBlurMaskFilter::kNormal_Bl urStyle);
155 paint.setMaskFilter(mf)->unref();
156
157 canvas->save();
158 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
159 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags);
160 canvas->restore();
161 }
162
142 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 163 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
143 164
144 canvas->clear(SK_ColorGRAY); 165 canvas->clear(SK_ColorGRAY);
145 166
146 // First draw a column with no bleeding, tiling, or filtering 167 // First draw a column with no bleeding, tiling, or filtering
147 this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFl ag, false); 168 this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFl ag, false);
148 this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFl ag, false); 169 this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFl ag, false);
149 this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFl ag, false); 170 this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFl ag, false);
171 this->drawCase4(canvas, kCol0X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFl ag, false);
150 172
151 // Then draw a column with no bleeding or tiling but with filtering 173 // Then draw a column with no bleeding or tiling but with filtering
152 this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFl ag, true); 174 this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFl ag, true);
153 this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFl ag, true); 175 this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFl ag, true);
154 this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFl ag, true); 176 this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFl ag, true);
177 this->drawCase4(canvas, kCol1X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFl ag, true);
155 178
156 179
157 #if SK_SUPPORT_GPU 180 #if SK_SUPPORT_GPU
158 GrContext* ctx = skiagm::GetGr(); 181 GrContext* ctx = skiagm::GetGr();
159 int oldMaxTextureSize = 0; 182 int oldMaxTextureSize = 0;
160 if (NULL != ctx) { 183 if (NULL != ctx) {
161 // shrink the max texture size so all our textures can be reasonably sized 184 // shrink the max texture size so all our textures can be reasonably sized
162 oldMaxTextureSize = ctx->getMaxTextureSize(); 185 oldMaxTextureSize = ctx->getMaxTextureSize();
163 ctx->setMaxTextureSizeOverride(kMaxTextureSize); 186 ctx->setMaxTextureSizeOverride(kMaxTextureSize);
164 } 187 }
165 #endif 188 #endif
166 189
167 // Then draw a column with no bleeding but with tiling and filtering 190 // Then draw a column with no bleeding but with tiling and filtering
168 this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFl ag, true); 191 this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFl ag, true);
169 this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFl ag, true); 192 this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFl ag, true);
170 this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFl ag, true); 193 this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFl ag, true);
194 this->drawCase4(canvas, kCol2X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFl ag, true);
171 195
172 // Finally draw a column with all three (bleeding, tiling, and filtering ) 196 // Finally draw a column with all three (bleeding, tiling, and filtering )
173 this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kBleed_DrawBitmapRectF lag, true); 197 this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kBleed_DrawBitmapRectF lag, true);
174 this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kBleed_DrawBitmapRectF lag, true); 198 this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kBleed_DrawBitmapRectF lag, true);
175 this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kBleed_DrawBitmapRectF lag, true); 199 this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kBleed_DrawBitmapRectF lag, true);
200 this->drawCase4(canvas, kCol3X, kRow3Y, SkCanvas::kBleed_DrawBitmapRectF lag, true);
176 201
177 #if SK_SUPPORT_GPU 202 #if SK_SUPPORT_GPU
178 if (NULL != ctx) { 203 if (NULL != ctx) {
179 ctx->setMaxTextureSizeOverride(oldMaxTextureSize); 204 ctx->setMaxTextureSizeOverride(oldMaxTextureSize);
180 } 205 }
181 #endif 206 #endif
182 } 207 }
183 208
184 private: 209 private:
185 static const int kBlockSize = 90; 210 static const int kBlockSize = 90;
186 static const int kBlockSpacing = 10; 211 static const int kBlockSpacing = 10;
187 212
188 static const int kCol0X = kBlockSpacing; 213 static const int kCol0X = kBlockSpacing;
189 static const int kCol1X = 2*kBlockSpacing + kBlockSize; 214 static const int kCol1X = 2*kBlockSpacing + kBlockSize;
190 static const int kCol2X = 3*kBlockSpacing + 2*kBlockSize; 215 static const int kCol2X = 3*kBlockSpacing + 2*kBlockSize;
191 static const int kCol3X = 4*kBlockSpacing + 3*kBlockSize; 216 static const int kCol3X = 4*kBlockSpacing + 3*kBlockSize;
192 static const int kWidth = 5*kBlockSpacing + 4*kBlockSize; 217 static const int kWidth = 5*kBlockSpacing + 4*kBlockSize;
193 218
194 static const int kRow0Y = kBlockSpacing; 219 static const int kRow0Y = kBlockSpacing;
195 static const int kRow1Y = 2*kBlockSpacing + kBlockSize; 220 static const int kRow1Y = 2*kBlockSpacing + kBlockSize;
196 static const int kRow2Y = 3*kBlockSpacing + 2*kBlockSize; 221 static const int kRow2Y = 3*kBlockSpacing + 2*kBlockSize;
197 static const int kHeight = 4*kBlockSpacing + 3*kBlockSize; 222 static const int kRow3Y = 4*kBlockSpacing + 3*kBlockSize;
223 static const int kHeight = 5*kBlockSpacing + 4*kBlockSize;
198 224
199 static const int kSmallTextureSize = 4; 225 static const int kSmallTextureSize = 4;
200 static const int kMaxTextureSize = 32; 226 static const int kMaxTextureSize = 32;
201 227
202 SkBitmap fBitmapSmall; 228 SkBitmap fBitmapSmall;
203 SkBitmap fBitmapBig; 229 SkBitmap fBitmapBig;
204 230
205 typedef GM INHERITED; 231 typedef GM INHERITED;
206 }; 232 };
207 233
208 DEF_GM( return new BleedGM(); ) 234 DEF_GM( return new BleedGM(); )
OLDNEW
« no previous file with comments | « no previous file | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698