| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "SkCanvas.h" | |
| 9 #include "SkPicture.h" | |
| 10 | |
| 11 class SkPrerollCanvas : public SkCanvas { | |
| 12 public: | |
| 13 SkPrerollCanvas(int width, int height, const SkSurfaceProps* props) | |
| 14 : SkCanvas(width, height, props) | |
| 15 {} | |
| 16 | |
| 17 protected: | |
| 18 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint& paint) SK_O
VERRIDE { | |
| 19 this->handlePaint(paint); | |
| 20 } | |
| 21 | |
| 22 void onDrawText(const void*, size_t, SkScalar, SkScalar, const SkPaint& pain
t) SK_OVERRIDE { | |
| 23 this->handlePaint(paint); | |
| 24 } | |
| 25 | |
| 26 void onDrawPosText(const void*, size_t, const SkPoint[], const SkPaint& pain
t) SK_OVERRIDE { | |
| 27 this->handlePaint(paint); | |
| 28 } | |
| 29 | |
| 30 void onDrawPosTextH(const void*, size_t, const SkScalar[], SkScalar, | |
| 31 const SkPaint& paint) SK_OVERRIDE { | |
| 32 this->handlePaint(paint); | |
| 33 } | |
| 34 | |
| 35 void onDrawTextOnPath(const void*, size_t, const SkPath&, const SkMatrix*, | |
| 36 const SkPaint& paint) SK_OVERRIDE { | |
| 37 this->handlePaint(paint); | |
| 38 } | |
| 39 | |
| 40 void onDrawTextBlob(const SkTextBlob*, SkScalar, SkScalar, const SkPaint& pa
int) SK_OVERRIDE { | |
| 41 this->handlePaint(paint); | |
| 42 } | |
| 43 | |
| 44 void onDrawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkXf
ermode*, | |
| 45 const SkPaint& paint) SK_OVERRIDE { | |
| 46 this->handlePaint(paint); | |
| 47 } | |
| 48 | |
| 49 void onDrawPaint(const SkPaint& paint) SK_OVERRIDE { | |
| 50 this->handlePaint(paint); | |
| 51 } | |
| 52 | |
| 53 void onDrawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE { | |
| 54 this->handlePaint(paint); | |
| 55 } | |
| 56 | |
| 57 void onDrawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE { | |
| 58 this->handlePaint(paint); | |
| 59 } | |
| 60 | |
| 61 void onDrawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE { | |
| 62 this->handlePaint(paint); | |
| 63 } | |
| 64 | |
| 65 void onDrawPoints(PointMode, size_t, const SkPoint[], const SkPaint& paint)
SK_OVERRIDE { | |
| 66 this->handlePaint(paint); | |
| 67 } | |
| 68 | |
| 69 void onDrawVertices(VertexMode, int, const SkPoint[], const SkPoint[], const
SkColor[], | |
| 70 SkXfermode*, const uint16_t[], int, const SkPaint& paint
) SK_OVERRIDE { | |
| 71 this->handlePaint(paint); | |
| 72 } | |
| 73 | |
| 74 void onDrawPath(const SkPath&, const SkPaint& paint) SK_OVERRIDE { | |
| 75 this->handlePaint(paint); | |
| 76 } | |
| 77 | |
| 78 void onDrawImage(const SkImage* image, SkScalar, SkScalar, const SkPaint* pa
int) SK_OVERRIDE { | |
| 79 this->handleImage(image); | |
| 80 if (paint) { | |
| 81 this->handlePaint(*paint); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 void onDrawImageRect(const SkImage* image, const SkRect*, const SkRect&, | |
| 86 const SkPaint* paint) SK_OVERRIDE { | |
| 87 this->handleImage(image); | |
| 88 if (paint) { | |
| 89 this->handlePaint(*paint); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 void onDrawBitmap(const SkBitmap& bm, SkScalar, SkScalar, const SkPaint* pai
nt) SK_OVERRIDE { | |
| 94 this->handleBitmap(bm); | |
| 95 if (paint) { | |
| 96 this->handlePaint(*paint); | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 void onDrawBitmapRect(const SkBitmap& bm, const SkRect*, const SkRect&, cons
t SkPaint* paint, | |
| 101 DrawBitmapRectFlags) SK_OVERRIDE { | |
| 102 this->handleBitmap(bm); | |
| 103 if (paint) { | |
| 104 this->handlePaint(*paint); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 void onDrawBitmapNine(const SkBitmap& bm, const SkIRect&, const SkRect&, | |
| 109 const SkPaint* paint) SK_OVERRIDE { | |
| 110 this->handleBitmap(bm); | |
| 111 if (paint) { | |
| 112 this->handlePaint(*paint); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 void onDrawSprite(const SkBitmap& bm, int, int, const SkPaint* paint) SK_OVE
RRIDE { | |
| 117 this->handleBitmap(bm); | |
| 118 if (paint) { | |
| 119 this->handlePaint(*paint); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 private: | |
| 124 void handlePaint(const SkPaint& paint) { | |
| 125 const SkShader* shader = paint.getShader(); | |
| 126 if (shader) { | |
| 127 shader->preroll(); | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 void handleImage(const SkImage* image) { | |
| 132 image->preroll(); | |
| 133 } | |
| 134 | |
| 135 void handleBitmap(const SkBitmap& bitmap) { | |
| 136 SkBitmap bm(bitmap); | |
| 137 bm.lockPixels(); | |
| 138 } | |
| 139 | |
| 140 typedef SkCanvas INHERITED; | |
| 141 }; | |
| 142 | |
| 143 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | |
| 144 | |
| 145 void SkPicture::preroll(const SkRect* srcBounds, const SkMatrix* initialMatrix, | |
| 146 const SkSurfaceProps* props, void* gpuCacheAccessor) con
st { | |
| 147 SkRect bounds = this->cullRect(); | |
| 148 if (srcBounds && !bounds.intersect(*srcBounds)) { | |
| 149 return; | |
| 150 } | |
| 151 | |
| 152 const SkIRect ibounds = bounds.roundOut(); | |
| 153 if (ibounds.isEmpty()) { | |
| 154 return; | |
| 155 } | |
| 156 | |
| 157 SkPrerollCanvas canvas(ibounds.width(), ibounds.height(), props); | |
| 158 | |
| 159 canvas.translate(-SkIntToScalar(ibounds.left()), -SkIntToScalar(ibounds.top(
))); | |
| 160 canvas.drawPicture(this, initialMatrix, NULL); | |
| 161 } | |
| 162 | |
| OLD | NEW |