OLD | NEW |
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 | 7 |
8 #include "SkDraw.h" | 8 #include "SkDraw.h" |
9 #include "SkBlitter.h" | 9 #include "SkBlitter.h" |
10 #include "SkBounder.h" | 10 #include "SkBounder.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 }; | 65 }; |
66 #define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose) | 66 #define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose) |
67 | 67 |
68 /** | 68 /** |
69 * Since we are providing the storage for the shader (to avoid the perf cost | 69 * Since we are providing the storage for the shader (to avoid the perf cost |
70 * of calling new) we insist that in our destructor we can account for all | 70 * of calling new) we insist that in our destructor we can account for all |
71 * owners of the shader. | 71 * owners of the shader. |
72 */ | 72 */ |
73 class SkAutoBitmapShaderInstall : SkNoncopyable { | 73 class SkAutoBitmapShaderInstall : SkNoncopyable { |
74 public: | 74 public: |
75 SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint) | 75 SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint, |
| 76 const SkMatrix* localMatrix = NULL) |
76 : fPaint(paint) /* makes a copy of the paint */ { | 77 : fPaint(paint) /* makes a copy of the paint */ { |
77 fPaint.setShader(CreateBitmapShader(src, SkShader::kClamp_TileMode, | 78 fPaint.setShader(CreateBitmapShader(src, SkShader::kClamp_TileMode, |
78 SkShader::kClamp_TileMode, | 79 SkShader::kClamp_TileMode, |
79 &fAllocator)); | 80 localMatrix, &fAllocator)); |
80 // we deliberately left the shader with an owner-count of 2 | 81 // we deliberately left the shader with an owner-count of 2 |
81 SkASSERT(2 == fPaint.getShader()->getRefCnt()); | 82 SkASSERT(2 == fPaint.getShader()->getRefCnt()); |
82 } | 83 } |
83 | 84 |
84 ~SkAutoBitmapShaderInstall() { | 85 ~SkAutoBitmapShaderInstall() { |
85 // since fAllocator will destroy shader, we insist that owners == 2 | 86 // since fAllocator will destroy shader, we insist that owners == 2 |
86 SkASSERT(2 == fPaint.getShader()->getRefCnt()); | 87 SkASSERT(2 == fPaint.getShader()->getRefCnt()); |
87 | 88 |
88 fPaint.setShader(NULL); // unref the shader by 1 | 89 fPaint.setShader(NULL); // unref the shader by 1 |
89 | 90 |
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 if (blitter) { | 1368 if (blitter) { |
1368 if (fBounder && !fBounder->doIRect(bounds)) { | 1369 if (fBounder && !fBounder->doIRect(bounds)) { |
1369 return; | 1370 return; |
1370 } | 1371 } |
1371 | 1372 |
1372 SkScan::FillIRect(bounds, *fRC, blitter); | 1373 SkScan::FillIRect(bounds, *fRC, blitter); |
1373 return; | 1374 return; |
1374 } | 1375 } |
1375 } | 1376 } |
1376 | 1377 |
1377 SkAutoBitmapShaderInstall install(bitmap, paint); | |
1378 const SkPaint& shaderPaint = install.paintWithShader(); | |
1379 | |
1380 SkMatrix matrix; | 1378 SkMatrix matrix; |
1381 SkRect r; | 1379 SkRect r; |
1382 | 1380 |
1383 // get a scalar version of our rect | 1381 // get a scalar version of our rect |
1384 r.set(bounds); | 1382 r.set(bounds); |
1385 | 1383 |
1386 // tell the shader our offset | 1384 // create shader with offset |
1387 matrix.setTranslate(r.fLeft, r.fTop); | 1385 matrix.setTranslate(r.fLeft, r.fTop); |
1388 shaderPaint.getShader()->setLocalMatrix(matrix); | 1386 SkAutoBitmapShaderInstall install(bitmap, paint, &matrix); |
| 1387 const SkPaint& shaderPaint = install.paintWithShader(); |
1389 | 1388 |
1390 SkDraw draw(*this); | 1389 SkDraw draw(*this); |
1391 matrix.reset(); | 1390 matrix.reset(); |
1392 draw.fMatrix = &matrix; | 1391 draw.fMatrix = &matrix; |
1393 // call ourself with a rect | 1392 // call ourself with a rect |
1394 // is this OK if paint has a rasterizer? | 1393 // is this OK if paint has a rasterizer? |
1395 draw.drawRect(r, shaderPaint); | 1394 draw.drawRect(r, shaderPaint); |
1396 } | 1395 } |
1397 | 1396 |
1398 /////////////////////////////////////////////////////////////////////////////// | 1397 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2834 mask->fImage = SkMask::AllocImage(size); | 2833 mask->fImage = SkMask::AllocImage(size); |
2835 memset(mask->fImage, 0, mask->computeImageSize()); | 2834 memset(mask->fImage, 0, mask->computeImageSize()); |
2836 } | 2835 } |
2837 | 2836 |
2838 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2837 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
2839 draw_into_mask(*mask, devPath, style); | 2838 draw_into_mask(*mask, devPath, style); |
2840 } | 2839 } |
2841 | 2840 |
2842 return true; | 2841 return true; |
2843 } | 2842 } |
OLD | NEW |