Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 bool pathIsMutable) { | 226 bool pathIsMutable) { |
| 227 draw.drawPath(path, paint, prePathMatrix, pathIsMutable); | 227 draw.drawPath(path, paint, prePathMatrix, pathIsMutable); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, | 230 void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, |
| 231 const SkMatrix& matrix, const SkPaint& paint) { | 231 const SkMatrix& matrix, const SkPaint& paint) { |
| 232 LogDrawScaleFactor(SkMatrix::Concat(*draw.fMatrix, matrix), paint.getFilterQ uality()); | 232 LogDrawScaleFactor(SkMatrix::Concat(*draw.fMatrix, matrix), paint.getFilterQ uality()); |
| 233 draw.drawBitmap(bitmap, matrix, nullptr, paint); | 233 draw.drawBitmap(bitmap, matrix, nullptr, paint); |
| 234 } | 234 } |
| 235 | 235 |
| 236 static inline bool CanApplyDstMatrixAsCTM(const SkMatrix& m, const SkPaint& pain t) { | |
| 237 if (!paint.getMaskFilter()) { | |
|
f(malita)
2016/08/26 19:19:10
Is there anything else downstream that may care ab
| |
| 238 return true; | |
| 239 } | |
| 240 | |
| 241 // Some mask filters parameters (sigma) depend on the CTM/scale. | |
| 242 return m.getType() <= SkMatrix::kTranslate_Mask; | |
| 243 } | |
| 244 | |
| 236 void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, | 245 void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
| 237 const SkRect* src, const SkRect& dst, | 246 const SkRect* src, const SkRect& dst, |
| 238 const SkPaint& paint, SkCanvas::SrcRectConst raint constraint) { | 247 const SkPaint& paint, SkCanvas::SrcRectConst raint constraint) { |
| 239 SkMatrix matrix; | 248 SkMatrix matrix; |
| 240 SkRect bitmapBounds, tmpSrc, tmpDst; | 249 SkRect bitmapBounds, tmpSrc, tmpDst; |
| 241 SkBitmap tmpBitmap; | 250 SkBitmap tmpBitmap; |
| 242 | 251 |
| 243 bitmapBounds.isetWH(bitmap.width(), bitmap.height()); | 252 bitmapBounds.isetWH(bitmap.width(), bitmap.height()); |
| 244 | 253 |
| 245 // Compute matrix from the two rectangles | 254 // Compute matrix from the two rectangles |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 extractedBitmapBounds.isetWH(bitmapPtr->width(), bitmapPtr->height()); | 311 extractedBitmapBounds.isetWH(bitmapPtr->width(), bitmapPtr->height()); |
| 303 if (extractedBitmapBounds == tmpSrc) { | 312 if (extractedBitmapBounds == tmpSrc) { |
| 304 // no fractional part in src, we can just call drawBitmap | 313 // no fractional part in src, we can just call drawBitmap |
| 305 goto USE_DRAWBITMAP; | 314 goto USE_DRAWBITMAP; |
| 306 } | 315 } |
| 307 } else { | 316 } else { |
| 308 USE_DRAWBITMAP: | 317 USE_DRAWBITMAP: |
| 309 // We can go faster by just calling drawBitmap, which will concat the | 318 // We can go faster by just calling drawBitmap, which will concat the |
| 310 // matrix with the CTM, and try to call drawSprite if it can. If not, | 319 // matrix with the CTM, and try to call drawSprite if it can. If not, |
| 311 // it will make a shader and call drawRect, as we do below. | 320 // it will make a shader and call drawRect, as we do below. |
| 312 draw.drawBitmap(*bitmapPtr, matrix, dstPtr, paint); | 321 if (CanApplyDstMatrixAsCTM(matrix, paint)) { |
| 313 return; | 322 draw.drawBitmap(*bitmapPtr, matrix, dstPtr, paint); |
| 323 return; | |
| 324 } | |
| 314 } | 325 } |
| 315 | 326 |
| 316 USE_SHADER: | 327 USE_SHADER: |
| 317 | 328 |
| 318 // Since the shader need only live for our stack-frame, pass in a custom all ocator. This | 329 // Since the shader need only live for our stack-frame, pass in a custom all ocator. This |
| 319 // can save malloc calls, and signals to SkMakeBitmapShader to not try to co py the bitmap | 330 // can save malloc calls, and signals to SkMakeBitmapShader to not try to co py the bitmap |
| 320 // if its mutable, since that precaution is not needed (give the short lifet ime of the shader). | 331 // if its mutable, since that precaution is not needed (give the short lifet ime of the shader). |
| 321 SkTBlitterAllocator allocator; | 332 SkTBlitterAllocator allocator; |
| 322 // construct a shader, so we can call drawRect with the dst | 333 // construct a shader, so we can call drawRect with the dst |
| 323 auto s = SkMakeBitmapShader(*bitmapPtr, SkShader::kClamp_TileMode, SkShader: :kClamp_TileMode, | 334 auto s = SkMakeBitmapShader(*bitmapPtr, SkShader::kClamp_TileMode, SkShader: :kClamp_TileMode, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 paint.getRasterizer() || | 444 paint.getRasterizer() || |
| 434 paint.getPathEffect() || | 445 paint.getPathEffect() || |
| 435 paint.isFakeBoldText() || | 446 paint.isFakeBoldText() || |
| 436 paint.getStyle() != SkPaint::kFill_Style || | 447 paint.getStyle() != SkPaint::kFill_Style || |
| 437 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) | 448 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) |
| 438 { | 449 { |
| 439 return true; | 450 return true; |
| 440 } | 451 } |
| 441 return false; | 452 return false; |
| 442 } | 453 } |
| OLD | NEW |