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

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

Issue 2216403002: use SkMakeBitmapShader to not force copies when possible (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix ref-count manually for allocator Created 4 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
« no previous file with comments | « no previous file | 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 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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkConfig8888.h" 9 #include "SkConfig8888.h"
10 #include "SkDraw.h" 10 #include "SkDraw.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } else { 315 } else {
316 USE_DRAWBITMAP: 316 USE_DRAWBITMAP:
317 // We can go faster by just calling drawBitmap, which will concat the 317 // We can go faster by just calling drawBitmap, which will concat the
318 // matrix with the CTM, and try to call drawSprite if it can. If not, 318 // matrix with the CTM, and try to call drawSprite if it can. If not,
319 // it will make a shader and call drawRect, as we do below. 319 // it will make a shader and call drawRect, as we do below.
320 draw.drawBitmap(*bitmapPtr, matrix, dstPtr, paint); 320 draw.drawBitmap(*bitmapPtr, matrix, dstPtr, paint);
321 return; 321 return;
322 } 322 }
323 323
324 USE_SHADER: 324 USE_SHADER:
325
326 // Since the shader need only live for our stack-frame, pass in a custom all ocator. This
327 // can save malloc calls, and signals to SkMakeBitmapShader to not try to co py the bitmap
328 // if its mutable, since that precaution is not needed (give the short lifet ime of the shader).
329 SkTBlitterAllocator allocator;
325 // construct a shader, so we can call drawRect with the dst 330 // construct a shader, so we can call drawRect with the dst
326 auto s = SkShader::MakeBitmapShader(*bitmapPtr, SkShader::kClamp_TileMode, 331 auto s = SkMakeBitmapShader(*bitmapPtr, SkShader::kClamp_TileMode, SkShader: :kClamp_TileMode,
327 SkShader::kClamp_TileMode, &matrix); 332 &matrix, &allocator);
328 if (!s) { 333 if (!s) {
329 return; 334 return;
330 } 335 }
336 // we deliberately add a ref, since the allocator wants to be the last owner
337 s.get()->ref();
331 338
332 SkPaint paintWithShader(paint); 339 SkPaint paintWithShader(paint);
333 paintWithShader.setStyle(SkPaint::kFill_Style); 340 paintWithShader.setStyle(SkPaint::kFill_Style);
334 paintWithShader.setShader(std::move(s)); 341 paintWithShader.setShader(s);
335 342
336 // Call ourself, in case the subclass wanted to share this setup code 343 // Call ourself, in case the subclass wanted to share this setup code
337 // but handle the drawRect code themselves. 344 // but handle the drawRect code themselves.
338 this->drawRect(draw, *dstPtr, paintWithShader); 345 this->drawRect(draw, *dstPtr, paintWithShader);
339 } 346 }
340 347
341 void SkBitmapDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, 348 void SkBitmapDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
342 int x, int y, const SkPaint& paint) { 349 int x, int y, const SkPaint& paint) {
343 draw.drawSprite(bitmap, x, y, paint); 350 draw.drawSprite(bitmap, x, y, paint);
344 } 351 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 paint.getRasterizer() || 441 paint.getRasterizer() ||
435 paint.getPathEffect() || 442 paint.getPathEffect() ||
436 paint.isFakeBoldText() || 443 paint.isFakeBoldText() ||
437 paint.getStyle() != SkPaint::kFill_Style || 444 paint.getStyle() != SkPaint::kFill_Style ||
438 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) 445 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode))
439 { 446 {
440 return true; 447 return true;
441 } 448 }
442 return false; 449 return false;
443 } 450 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698