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

Side by Side Diff: src/core/SkDraw.cpp

Issue 1156713004: remove bitmaps entirely from sprite blits (as source) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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 | « src/core/SkBlitter_Sprite.cpp ('k') | src/core/SkSpriteBlitter.h » ('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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 #define __STDC_LIMIT_MACROS 7 #define __STDC_LIMIT_MACROS
8 8
9 #include "SkDraw.h" 9 #include "SkDraw.h"
10 #include "SkBlitter.h" 10 #include "SkBlitter.h"
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 return c.quickReject(dstR.roundOut()); 1235 return c.quickReject(dstR.roundOut());
1236 } 1236 }
1237 1237
1238 static bool clipped_out(const SkMatrix& matrix, const SkRasterClip& clip, 1238 static bool clipped_out(const SkMatrix& matrix, const SkRasterClip& clip,
1239 int width, int height) { 1239 int width, int height) {
1240 SkRect r; 1240 SkRect r;
1241 r.set(0, 0, SkIntToScalar(width), SkIntToScalar(height)); 1241 r.set(0, 0, SkIntToScalar(width), SkIntToScalar(height));
1242 return clipped_out(matrix, clip, r); 1242 return clipped_out(matrix, clip, r);
1243 } 1243 }
1244 1244
1245 static bool clipHandlesSprite(const SkRasterClip& clip, int x, int y, 1245 static bool clipHandlesSprite(const SkRasterClip& clip, int x, int y, const SkPi xmap& pmap) {
1246 const SkBitmap& bitmap) { 1246 return clip.isBW() || clip.quickContains(x, y, x + pmap.width(), y + pmap.he ight());
1247 return clip.isBW() ||
1248 clip.quickContains(x, y, x + bitmap.width(), y + bitmap.height());
1249 } 1247 }
1250 1248
1251 void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix, 1249 void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix,
1252 const SkRect* dstBounds, const SkPaint& origPaint) const { 1250 const SkRect* dstBounds, const SkPaint& origPaint) const {
1253 SkDEBUGCODE(this->validate();) 1251 SkDEBUGCODE(this->validate();)
1254 1252
1255 // nothing to draw 1253 // nothing to draw
1256 if (fRC->isEmpty() || 1254 if (fRC->isEmpty() ||
1257 bitmap.width() == 0 || bitmap.height() == 0 || 1255 bitmap.width() == 0 || bitmap.height() == 0 ||
1258 bitmap.colorType() == kUnknown_SkColorType) { 1256 bitmap.colorType() == kUnknown_SkColorType) {
1259 return; 1257 return;
1260 } 1258 }
1261 1259
1262 SkPaint paint(origPaint); 1260 SkPaint paint(origPaint);
1263 paint.setStyle(SkPaint::kFill_Style); 1261 paint.setStyle(SkPaint::kFill_Style);
1264 1262
1265 SkMatrix matrix; 1263 SkMatrix matrix;
1266 matrix.setConcat(*fMatrix, prematrix); 1264 matrix.setConcat(*fMatrix, prematrix);
1267 1265
1268 if (clipped_out(matrix, *fRC, bitmap.width(), bitmap.height())) { 1266 if (clipped_out(matrix, *fRC, bitmap.width(), bitmap.height())) {
1269 return; 1267 return;
1270 } 1268 }
1271 1269
1272 if (bitmap.colorType() != kAlpha_8_SkColorType && just_translate(matrix, bit map)) { 1270 if (bitmap.colorType() != kAlpha_8_SkColorType && just_translate(matrix, bit map)) {
1273 // 1271 //
1274 // It is safe to call lock pixels now, since we know the matrix is 1272 // It is safe to call lock pixels now, since we know the matrix is
1275 // (more or less) identity. 1273 // (more or less) identity.
1276 // 1274 //
1277 SkAutoLockPixels alp(bitmap); 1275 SkAutoPixmapUnlock unlocker;
1278 if (!bitmap.readyToDraw()) { 1276 if (!bitmap.requestLock(&unlocker)) {
1279 return; 1277 return;
1280 } 1278 }
1279 const SkPixmap& pmap = unlocker.pixmap();
1281 int ix = SkScalarRoundToInt(matrix.getTranslateX()); 1280 int ix = SkScalarRoundToInt(matrix.getTranslateX());
1282 int iy = SkScalarRoundToInt(matrix.getTranslateY()); 1281 int iy = SkScalarRoundToInt(matrix.getTranslateY());
1283 if (clipHandlesSprite(*fRC, ix, iy, bitmap)) { 1282 if (clipHandlesSprite(*fRC, ix, iy, pmap)) {
1284 SkTBlitterAllocator allocator; 1283 SkTBlitterAllocator allocator;
1285 // blitter will be owned by the allocator. 1284 // blitter will be owned by the allocator.
1286 SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap , 1285 SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, pmap, ix, iy, &allocator);
1287 ix, iy, &allocator);
1288 if (blitter) { 1286 if (blitter) {
1289 SkIRect ir; 1287 SkScan::FillIRect(SkIRect::MakeXYWH(ix, iy, pmap.width(), pmap.h eight()),
1290 ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 1288 *fRC, blitter);
1291
1292 SkScan::FillIRect(ir, *fRC, blitter);
1293 return; 1289 return;
1294 } 1290 }
1291 // if !blitter, then we fall-through to the slower case
1295 } 1292 }
1296 } 1293 }
1297 1294
1298 // now make a temp draw on the stack, and use it 1295 // now make a temp draw on the stack, and use it
1299 // 1296 //
1300 SkDraw draw(*this); 1297 SkDraw draw(*this);
1301 draw.fMatrix = &matrix; 1298 draw.fMatrix = &matrix;
1302 1299
1303 if (bitmap.colorType() == kAlpha_8_SkColorType) { 1300 if (bitmap.colorType() == kAlpha_8_SkColorType) {
1304 draw.drawBitmapAsMask(bitmap, paint); 1301 draw.drawBitmapAsMask(bitmap, paint);
1305 } else { 1302 } else {
1306 SkAutoBitmapShaderInstall install(bitmap, paint); 1303 SkAutoBitmapShaderInstall install(bitmap, paint);
1307 const SkPaint& paintWithShader = install.paintWithShader(); 1304 const SkPaint& paintWithShader = install.paintWithShader();
1308 const SkRect srcBounds = SkRect::MakeIWH(bitmap.width(), bitmap.height() ); 1305 const SkRect srcBounds = SkRect::MakeIWH(bitmap.width(), bitmap.height() );
1309 if (dstBounds) { 1306 if (dstBounds) {
1310 this->drawRect(srcBounds, paintWithShader, &prematrix, dstBounds); 1307 this->drawRect(srcBounds, paintWithShader, &prematrix, dstBounds);
1311 } else { 1308 } else {
1312 draw.drawRect(srcBounds, paintWithShader); 1309 draw.drawRect(srcBounds, paintWithShader);
1313 } 1310 }
1314 } 1311 }
1315 } 1312 }
1316 1313
1317 void SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, 1314 void SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint& ori gPaint) const {
1318 const SkPaint& origPaint) const {
1319 SkDEBUGCODE(this->validate();) 1315 SkDEBUGCODE(this->validate();)
1320 1316
1321 // nothing to draw 1317 // nothing to draw
1322 if (fRC->isEmpty() || 1318 if (fRC->isEmpty() ||
1323 bitmap.width() == 0 || bitmap.height() == 0 || 1319 bitmap.width() == 0 || bitmap.height() == 0 ||
1324 bitmap.colorType() == kUnknown_SkColorType) { 1320 bitmap.colorType() == kUnknown_SkColorType) {
1325 return; 1321 return;
1326 } 1322 }
1327 1323
1328 SkIRect bounds; 1324 const SkIRect bounds = SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height ());
1329 bounds.set(x, y, x + bitmap.width(), y + bitmap.height());
1330 1325
1331 if (fRC->quickReject(bounds)) { 1326 if (fRC->quickReject(bounds)) {
1332 return; // nothing to draw 1327 return; // nothing to draw
1333 } 1328 }
1334 1329
1335 SkPaint paint(origPaint); 1330 SkPaint paint(origPaint);
1336 paint.setStyle(SkPaint::kFill_Style); 1331 paint.setStyle(SkPaint::kFill_Style);
1337 1332
1338 if (NULL == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, bitmap)) { 1333 SkAutoPixmapUnlock unlocker;
1334 if (!bitmap.requestLock(&unlocker)) {
1335 return;
1336 }
1337 const SkPixmap& pmap = unlocker.pixmap();
1338
1339 if (NULL == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, pmap)) {
1339 SkTBlitterAllocator allocator; 1340 SkTBlitterAllocator allocator;
1340 // blitter will be owned by the allocator. 1341 // blitter will be owned by the allocator.
1341 SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap, 1342 SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, pmap, x, y , &allocator);
1342 x, y, &allocator);
1343
1344 if (blitter) { 1343 if (blitter) {
1345 SkScan::FillIRect(bounds, *fRC, blitter); 1344 SkScan::FillIRect(bounds, *fRC, blitter);
1346 return; 1345 return;
1347 } 1346 }
1348 } 1347 }
1349 1348
1350 SkMatrix matrix; 1349 SkMatrix matrix;
1351 SkRect r; 1350 SkRect r;
1352 1351
1353 // get a scalar version of our rect 1352 // get a scalar version of our rect
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
2268 mask->fImage = SkMask::AllocImage(size); 2267 mask->fImage = SkMask::AllocImage(size);
2269 memset(mask->fImage, 0, mask->computeImageSize()); 2268 memset(mask->fImage, 0, mask->computeImageSize());
2270 } 2269 }
2271 2270
2272 if (SkMask::kJustComputeBounds_CreateMode != mode) { 2271 if (SkMask::kJustComputeBounds_CreateMode != mode) {
2273 draw_into_mask(*mask, devPath, style); 2272 draw_into_mask(*mask, devPath, style);
2274 } 2273 }
2275 2274
2276 return true; 2275 return true;
2277 } 2276 }
OLDNEW
« no previous file with comments | « src/core/SkBlitter_Sprite.cpp ('k') | src/core/SkSpriteBlitter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698