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

Side by Side Diff: src/gpu/SkGpuDevice.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 | « gm/bleed.cpp ('k') | no next file » | 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 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 #include "SkGpuDevice.h" 8 #include "SkGpuDevice.h"
9 9
10 #include "effects/GrTextureDomainEffect.h" 10 #include "effects/GrTextureDomainEffect.h"
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 params.setFilterMode(textureFilterMode); 1171 params.setFilterMode(textureFilterMode);
1172 1172
1173 if (!this->shouldTileBitmap(bitmap, params, srcRectPtr)) { 1173 if (!this->shouldTileBitmap(bitmap, params, srcRectPtr)) {
1174 // take the simple case 1174 // take the simple case
1175 this->internalDrawBitmap(bitmap, srcRect, m, params, paint, flags); 1175 this->internalDrawBitmap(bitmap, srcRect, m, params, paint, flags);
1176 } else { 1176 } else {
1177 this->drawTiledBitmap(bitmap, srcRect, m, params, paint, flags); 1177 this->drawTiledBitmap(bitmap, srcRect, m, params, paint, flags);
1178 } 1178 }
1179 } 1179 }
1180 1180
1181 // This method outsets 'iRect' by 1 all around and then clamps its extents to
1182 // 'clamp'. 'offset' is adjusted to remain positioned over the top-left corner
1183 // of 'iRect' despite the possible outsets/clamps.
1184 static inline void clamped_unit_outset_with_offset(SkIRect* iRect, SkPoint* offs et,
1185 const SkIRect& clamp) {
1186 iRect->outset(1, 1);
1187
1188 if (iRect->fLeft < clamp.fLeft) {
1189 iRect->fLeft = clamp.fLeft;
1190 } else {
1191 offset->fX -= SK_Scalar1;
1192 }
1193 if (iRect->fTop < clamp.fTop) {
1194 iRect->fTop = clamp.fTop;
1195 } else {
1196 offset->fY -= SK_Scalar1;
1197 }
1198
1199 if (iRect->fRight > clamp.fRight) {
1200 iRect->fRight = clamp.fRight;
1201 }
1202 if (iRect->fBottom > clamp.fBottom) {
1203 iRect->fBottom = clamp.fBottom;
1204 }
1205 }
1206
1181 // Break 'bitmap' into several tiles to draw it since it has already 1207 // Break 'bitmap' into several tiles to draw it since it has already
1182 // been determined to be too large to fit in VRAM 1208 // been determined to be too large to fit in VRAM
1183 void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, 1209 void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
1184 const SkRect& srcRect, 1210 const SkRect& srcRect,
1185 const SkMatrix& m, 1211 const SkMatrix& m,
1186 const GrTextureParams& params, 1212 const GrTextureParams& params,
1187 const SkPaint& paint, 1213 const SkPaint& paint,
1188 SkCanvas::DrawBitmapRectFlags flags) { 1214 SkCanvas::DrawBitmapRectFlags flags) {
1189 // TODO: this method needs to be updated to respect the bleed flag 1215 int maxTextureSize = fContext->getMaxTextureSize();
1190 const int maxTextureSize = fContext->getMaxTextureSize(); 1216 if (SkPaint::kNone_FilterLevel != paint.getFilterLevel()) {
1217 // We may need a skosh more room if we have to bump out the tile
1218 // by 1 pixel all around
1219 maxTextureSize -= 2;
1220 }
1191 1221
1192 int tileSize = determine_tile_size(bitmap, srcRect, maxTextureSize); 1222 int tileSize = determine_tile_size(bitmap, srcRect, maxTextureSize);
1193 1223
1194 // compute clip bounds in local coordinates 1224 // compute clip bounds in local coordinates
1195 SkRect clipRect; 1225 SkRect clipRect;
1196 { 1226 {
1197 const GrRenderTarget* rt = fContext->getRenderTarget(); 1227 const GrRenderTarget* rt = fContext->getRenderTarget();
1198 clipRect.setWH(SkIntToScalar(rt->width()), SkIntToScalar(rt->height())); 1228 clipRect.setWH(SkIntToScalar(rt->width()), SkIntToScalar(rt->height()));
1199 if (!fContext->getClip()->fClipStack->intersectRectWithClip(&clipRect)) { 1229 if (!fContext->getClip()->fClipStack->intersectRectWithClip(&clipRect)) {
1200 return; 1230 return;
(...skipping 20 matching lines...) Expand all
1221 continue; 1251 continue;
1222 } 1252 }
1223 1253
1224 if (!tileR.intersect(srcRect)) { 1254 if (!tileR.intersect(srcRect)) {
1225 continue; 1255 continue;
1226 } 1256 }
1227 1257
1228 SkBitmap tmpB; 1258 SkBitmap tmpB;
1229 SkIRect iTileR; 1259 SkIRect iTileR;
1230 tileR.roundOut(&iTileR); 1260 tileR.roundOut(&iTileR);
1261 SkPoint offset = SkPoint::Make(SkIntToScalar(iTileR.fLeft),
1262 SkIntToScalar(iTileR.fTop));
1263
1264 if (SkPaint::kNone_FilterLevel != paint.getFilterLevel()) {
1265 SkIRect iClampRect;
1266
1267 if (SkCanvas::kBleed_DrawBitmapRectFlag & flags) {
1268 // In bleed mode we want to always expand the tile on all ed ges
1269 // but stay within the bitmap bounds
1270 iClampRect = SkIRect::MakeWH(bitmap.width(), bitmap.height() );
1271 } else {
1272 // In texture-domain/clamp mode we only want to expand the
1273 // tile on edges interior to "srcRect" (i.e., we want to
1274 // not bleed across the original clamped edges)
1275 srcRect.roundOut(&iClampRect);
1276 }
1277
1278 clamped_unit_outset_with_offset(&iTileR, &offset, iClampRect);
1279 }
1280
1231 if (bitmap.extractSubset(&tmpB, iTileR)) { 1281 if (bitmap.extractSubset(&tmpB, iTileR)) {
1232 // now offset it to make it "local" to our tmp bitmap 1282 // now offset it to make it "local" to our tmp bitmap
1233 tileR.offset(SkIntToScalar(-iTileR.fLeft), SkIntToScalar(-iTileR .fTop)); 1283 tileR.offset(-offset.fX, -offset.fY);
1234 SkMatrix tmpM(m); 1284 SkMatrix tmpM(m);
1235 tmpM.preTranslate(SkIntToScalar(iTileR.fLeft), 1285 tmpM.preTranslate(offset.fX, offset.fY);
1236 SkIntToScalar(iTileR.fTop));
1237 1286
1238 this->internalDrawBitmap(tmpB, tileR, tmpM, params, paint, flags ); 1287 this->internalDrawBitmap(tmpB, tileR, tmpM, params, paint, flags );
1239 } 1288 }
1240 } 1289 }
1241 } 1290 }
1242 } 1291 }
1243 1292
1244 static bool has_aligned_samples(const SkRect& srcRect, 1293 static bool has_aligned_samples(const SkRect& srcRect,
1245 const SkRect& transformedRect) { 1294 const SkRect& transformedRect) {
1246 // detect pixel disalignment 1295 // detect pixel disalignment
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 GrTexture* texture, 1846 GrTexture* texture,
1798 bool needClear) 1847 bool needClear)
1799 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { 1848 : SkDevice(make_bitmap(context, texture->asRenderTarget())) {
1800 1849
1801 SkASSERT(texture && texture->asRenderTarget()); 1850 SkASSERT(texture && texture->asRenderTarget());
1802 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture 1851 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture
1803 // cache. We pass true for the third argument so that it will get unlocked. 1852 // cache. We pass true for the third argument so that it will get unlocked.
1804 this->initFromRenderTarget(context, texture->asRenderTarget(), true); 1853 this->initFromRenderTarget(context, texture->asRenderTarget(), true);
1805 fNeedClear = needClear; 1854 fNeedClear = needClear;
1806 } 1855 }
OLDNEW
« no previous file with comments | « gm/bleed.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698