| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkImagePriv.h" | 8 #include "SkImagePriv.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkPicture.h" | 10 #include "SkPicture.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } else { | 62 } else { |
| 63 bm.lockPixels(); | 63 bm.lockPixels(); |
| 64 if (bm.getPixels()) { | 64 if (bm.getPixels()) { |
| 65 image = SkImage::NewRasterCopy(info, bm.getPixels(), bm.rowBytes()); | 65 image = SkImage::NewRasterCopy(info, bm.getPixels(), bm.rowBytes()); |
| 66 } | 66 } |
| 67 bm.unlockPixels(); | 67 bm.unlockPixels(); |
| 68 } | 68 } |
| 69 return image; | 69 return image; |
| 70 } | 70 } |
| 71 | 71 |
| 72 static bool needs_layer(const SkPaint& paint) { | |
| 73 return 0xFF != paint.getAlpha() || | |
| 74 paint.getColorFilter() || | |
| 75 paint.getImageFilter() || | |
| 76 SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode); | |
| 77 } | |
| 78 | |
| 79 void SkImagePrivDrawPicture(SkCanvas* canvas, SkPicture* picture, | |
| 80 SkScalar x, SkScalar y, const SkPaint* paint) { | |
| 81 int saveCount = canvas->getSaveCount(); | |
| 82 | |
| 83 if (paint && needs_layer(*paint)) { | |
| 84 SkRect bounds; | |
| 85 bounds.set(x, y, | |
| 86 x + SkIntToScalar(picture->width()), | |
| 87 y + SkIntToScalar(picture->height())); | |
| 88 canvas->saveLayer(&bounds, paint); | |
| 89 canvas->translate(x, y); | |
| 90 } else if (x || y) { | |
| 91 canvas->save(); | |
| 92 canvas->translate(x, y); | |
| 93 } | |
| 94 | |
| 95 canvas->drawPicture(*picture); | |
| 96 canvas->restoreToCount(saveCount); | |
| 97 } | |
| 98 | |
| 99 void SkImagePrivDrawPicture(SkCanvas* canvas, SkPicture* picture, | |
| 100 const SkRect* src, const SkRect& dst, const SkPaint
* paint) { | |
| 101 int saveCount = canvas->getSaveCount(); | |
| 102 | |
| 103 SkMatrix matrix; | |
| 104 SkRect tmpSrc; | |
| 105 | |
| 106 if (NULL != src) { | |
| 107 tmpSrc = *src; | |
| 108 } else { | |
| 109 tmpSrc.set(0, 0, | |
| 110 SkIntToScalar(picture->width()), | |
| 111 SkIntToScalar(picture->height())); | |
| 112 } | |
| 113 | |
| 114 matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); | |
| 115 if (paint && needs_layer(*paint)) { | |
| 116 canvas->saveLayer(&dst, paint); | |
| 117 } else { | |
| 118 canvas->save(); | |
| 119 } | |
| 120 canvas->concat(matrix); | |
| 121 if (!paint || !needs_layer(*paint)) { | |
| 122 canvas->clipRect(tmpSrc); | |
| 123 } | |
| 124 | |
| 125 canvas->drawPicture(*picture); | |
| 126 canvas->restoreToCount(saveCount); | |
| 127 } | |
| OLD | NEW |