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

Side by Side Diff: gm/bleed.cpp

Issue 23261003: Update tiled bitmap path to respect bleed flag (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Now address clamped & filtered case 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 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 82
83 virtual void onOnceBeforeDraw() SK_OVERRIDE { 83 virtual void onOnceBeforeDraw() SK_OVERRIDE {
84 make_red_ringed_bitmap(&fBitmapSmall, kSmallTextureSize, kSmallTextureSi ze); 84 make_red_ringed_bitmap(&fBitmapSmall, kSmallTextureSize, kSmallTextureSi ze);
85 85
86 // To exercise the GPU's tiling path we need a texture 86 // To exercise the GPU's tiling path we need a texture
87 // too big for the GPU to handle in one go 87 // too big for the GPU to handle in one go
88 make_red_ringed_bitmap(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize ); 88 make_red_ringed_bitmap(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize );
89 } 89 }
90 90
91 // Draw only the center of the small bitmap
92 void drawCase1(SkCanvas* canvas, int transX, int transY,
93 SkCanvas::DrawBitmapRectFlags flags, bool filter) {
94 SkRect src = SkRect::MakeXYWH(1, 1,
95 kSmallTextureSize-2,
96 kSmallTextureSize-2);
97 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc alar(kBlockSize));
98
99 SkPaint paint;
100 paint.setFilterBitmap(filter);
101
102 canvas->save();
103 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
104 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags);
105 canvas->restore();
106 }
107
108 // Draw almost all of the large bitmap
109 void drawCase2(SkCanvas* canvas, int transX, int transY,
110 SkCanvas::DrawBitmapRectFlags flags, bool filter) {
111 SkRect src = SkRect::MakeXYWH(1, 1,
112 SkIntToScalar(fBitmapBig.width()-2),
113 SkIntToScalar(fBitmapBig.height()-2));
114 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc alar(kBlockSize));
115
116 SkPaint paint;
117 paint.setFilterBitmap(filter);
118
119 canvas->save();
120 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
121 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags);
122 canvas->restore();
123 }
124
125 // Draw ~1/4 of the large bitmap
126 void drawCase3(SkCanvas* canvas, int transX, int transY,
127 SkCanvas::DrawBitmapRectFlags flags, bool filter) {
128 SkRect src = SkRect::MakeXYWH(1, 1,
129 SkIntToScalar(fBitmapBig.width()/2-1),
130 SkIntToScalar(fBitmapBig.height()/2-1));
131 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc alar(kBlockSize));
132
133 SkPaint paint;
134 paint.setFilterBitmap(filter);
135
136 canvas->save();
137 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
138 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags);
139 canvas->restore();
140 }
141
91 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 142 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
143
144 canvas->clear(SK_ColorGRAY);
145
146 // First draw a column with no bleeding, tiling, or filtering
147 this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kNone_DrawBitmapRectfl ag, false);
148 this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kNone_DrawBitmapRectfl ag, false);
149 this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kNone_DrawBitmapRectfl ag, false);
150
151 // Then draw a column with no bleeding or tiling but with filtering
152 this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kNone_DrawBitmapRectfl ag, true);
153 this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kNone_DrawBitmapRectfl ag, true);
154 this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kNone_DrawBitmapRectfl ag, true);
155
156
92 #if SK_SUPPORT_GPU 157 #if SK_SUPPORT_GPU
93 GrContext* ctx = skiagm::GetGr(); 158 GrContext* ctx = skiagm::GetGr();
94 int oldMaxTextureSize = 0; 159 int oldMaxTextureSize = 0;
95 if (NULL != ctx) { 160 if (NULL != ctx) {
96 // shrink the max texture size so all our textures can be reasonably sized 161 // shrink the max texture size so all our textures can be reasonably sized
97 oldMaxTextureSize = ctx->getMaxTextureSize(); 162 oldMaxTextureSize = ctx->getMaxTextureSize();
98 ctx->setMaxTextureSizeOverride(kMaxTextureSize); 163 ctx->setMaxTextureSizeOverride(kMaxTextureSize);
99 } 164 }
100 #endif 165 #endif
101 166
102 canvas->clear(SK_ColorGRAY); 167 // Then draw a column with no bleeding but with tiling and filtering
168 this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kNone_DrawBitmapRectfl ag, true);
169 this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kNone_DrawBitmapRectfl ag, true);
170 this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kNone_DrawBitmapRectfl ag, true);
103 171
104 SkPaint paint; 172 // Finally draw a column with all three (bleeding, tiling, and filtering )
105 173 this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kBleed_DrawBitmapRectF lag, true);
106 // Bleeding only comes into play when filtering 174 this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kBleed_DrawBitmapRectF lag, true);
107 paint.setFilterBitmap(true); 175 this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kBleed_DrawBitmapRectF lag, true);
108
109 // carve out the center of the small bitmap
110 SkRect src = SkRect::MakeXYWH(1, 1,
111 kSmallTextureSize-2,
112 kSmallTextureSize-2);
113 SkRect dst = SkRect::MakeXYWH(10, 10, 100, 100);
114
115 // first draw without bleeding
116 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint);
117
118 // then draw with bleeding
119 dst = SkRect::MakeXYWH(120, 10, 100, 100);
120 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint,
121 SkCanvas::kBleed_DrawBitmapRectFlag);
122
123 // Next test out the GPU's tiling of large textures
124
125 // first draw almost the whole thing
126 src = SkRect::MakeXYWH(1, 1,
127 SkIntToScalar(fBitmapBig.width()-2),
128 SkIntToScalar(fBitmapBig.height()-2));
129 dst = SkRect::MakeXYWH(10, 120, 100, 100);
130
131 // first without bleeding
132 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint);
133
134 // then with bleeding
135 dst = SkRect::MakeXYWH(120, 120, 100, 100);
136 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint,
137 SkCanvas::kBleed_DrawBitmapRectFlag);
138
139 // next draw ~1/4 of the bitmap
140 src = SkRect::MakeXYWH(1, 1,
141 SkIntToScalar(fBitmapBig.width()/2-1),
142 SkIntToScalar(fBitmapBig.height()/2-1));
143 dst = SkRect::MakeXYWH(10, 230, 100, 100);
144
145 // first without bleeding
146 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint);
147
148 // then with bleeding
149 dst = SkRect::MakeXYWH(120, 230, 100, 100);
150 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint,
151 SkCanvas::kBleed_DrawBitmapRectFlag);
152 176
153 #if SK_SUPPORT_GPU 177 #if SK_SUPPORT_GPU
154 if (NULL != ctx) { 178 if (NULL != ctx) {
155 ctx->setMaxTextureSizeOverride(oldMaxTextureSize); 179 ctx->setMaxTextureSizeOverride(oldMaxTextureSize);
156 } 180 }
157 #endif 181 #endif
158 } 182 }
159 183
160 private: 184 private:
161 static const int kWidth = 230; 185 static const int kBlockSize = 90;
162 static const int kHeight = 340; 186 static const int kBlockSpacing = 10;
187
188 static const int kCol0X = kBlockSpacing;
189 static const int kCol1X = 2*kBlockSpacing + kBlockSize;
190 static const int kCol2X = 3*kBlockSpacing + 2*kBlockSize;
191 static const int kCol3X = 4*kBlockSpacing + 3*kBlockSize;
192 static const int kWidth = 5*kBlockSpacing + 4*kBlockSize;
193
194 static const int kRow0Y = kBlockSpacing;
195 static const int kRow1Y = 2*kBlockSpacing + kBlockSize;
196 static const int kRow2Y = 3*kBlockSpacing + 2*kBlockSize;
197 static const int kHeight = 4*kBlockSpacing + 3*kBlockSize;
163 198
164 static const int kSmallTextureSize = 4; 199 static const int kSmallTextureSize = 4;
165 static const int kMaxTextureSize = 32; 200 static const int kMaxTextureSize = 32;
166 201
167 SkBitmap fBitmapSmall; 202 SkBitmap fBitmapSmall;
168 SkBitmap fBitmapBig; 203 SkBitmap fBitmapBig;
169 204
170 typedef GM INHERITED; 205 typedef GM INHERITED;
171 }; 206 };
172 207
173 DEF_GM( return new BleedGM(); ) 208 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