OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkSpecialImage.h" | 9 #include "SkSpecialImage.h" |
10 #include "SkSpecialSurface.h" | 10 #include "SkSpecialSurface.h" |
11 | 11 |
12 /////////////////////////////////////////////////////////////////////////////// | 12 /////////////////////////////////////////////////////////////////////////////// |
13 class SkSpecialImage_Base : public SkSpecialImage { | 13 class SkSpecialImage_Base : public SkSpecialImage { |
14 public: | 14 public: |
15 SkSpecialImage_Base(const SkIRect& subset) : INHERITED(subset) { } | 15 SkSpecialImage_Base(const SkIRect& subset) : INHERITED(subset) { } |
16 virtual ~SkSpecialImage_Base() { } | 16 virtual ~SkSpecialImage_Base() { } |
17 | 17 |
18 virtual void onDraw(SkCanvas*, int x, int y, const SkPaint*) const = 0; | 18 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const
= 0; |
19 | 19 |
20 virtual bool onPeekPixels(SkPixmap*) const { return false; } | 20 virtual bool onPeekPixels(SkPixmap*) const { return false; } |
21 | 21 |
22 virtual GrTexture* onPeekTexture() const { return nullptr; } | 22 virtual GrTexture* onPeekTexture() const { return nullptr; } |
23 | 23 |
24 virtual SkSpecialSurface* onNewSurface(const SkImageInfo& info) const { retu
rn nullptr; } | 24 virtual SkSpecialSurface* onNewSurface(const SkImageInfo& info) const { retu
rn nullptr; } |
25 | 25 |
26 private: | 26 private: |
27 typedef SkSpecialImage INHERITED; | 27 typedef SkSpecialImage INHERITED; |
28 }; | 28 }; |
29 | 29 |
30 /////////////////////////////////////////////////////////////////////////////// | 30 /////////////////////////////////////////////////////////////////////////////// |
31 static inline const SkSpecialImage_Base* as_IB(const SkSpecialImage* image) { | 31 static inline const SkSpecialImage_Base* as_IB(const SkSpecialImage* image) { |
32 return static_cast<const SkSpecialImage_Base*>(image); | 32 return static_cast<const SkSpecialImage_Base*>(image); |
33 } | 33 } |
34 | 34 |
35 void SkSpecialImage::draw(SkCanvas* canvas, int x, int y, const SkPaint* paint)
const { | 35 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain
t* paint) const { |
36 return as_IB(this)->onDraw(canvas, x, y, paint); | 36 return as_IB(this)->onDraw(canvas, x, y, paint); |
37 } | 37 } |
38 | 38 |
39 bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { | 39 bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { |
40 return as_IB(this)->onPeekPixels(pixmap); | 40 return as_IB(this)->onPeekPixels(pixmap); |
41 } | 41 } |
42 | 42 |
43 GrTexture* SkSpecialImage::peekTexture() const { | 43 GrTexture* SkSpecialImage::peekTexture() const { |
44 return as_IB(this)->onPeekTexture(); | 44 return as_IB(this)->onPeekTexture(); |
45 } | 45 } |
(...skipping 11 matching lines...) Expand all Loading... |
57 | 57 |
58 class SkSpecialImage_Image : public SkSpecialImage_Base { | 58 class SkSpecialImage_Image : public SkSpecialImage_Base { |
59 public: | 59 public: |
60 SkSpecialImage_Image(const SkIRect& subset, const SkImage* image) | 60 SkSpecialImage_Image(const SkIRect& subset, const SkImage* image) |
61 : INHERITED(subset) | 61 : INHERITED(subset) |
62 , fImage(SkRef(image)) { | 62 , fImage(SkRef(image)) { |
63 } | 63 } |
64 | 64 |
65 ~SkSpecialImage_Image() override { } | 65 ~SkSpecialImage_Image() override { } |
66 | 66 |
67 void onDraw(SkCanvas* canvas, int x, int y, const SkPaint* paint) const over
ride { | 67 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
68 SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset
().height()); | 68 SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset
().height()); |
69 | 69 |
70 canvas->drawImageRect(fImage, this->subset(), | 70 canvas->drawImageRect(fImage, this->subset(), |
71 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 71 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
72 } | 72 } |
73 | 73 |
74 bool onPeekPixels(SkPixmap* pixmap) const override { | 74 bool onPeekPixels(SkPixmap* pixmap) const override { |
75 return fImage->peekPixels(pixmap); | 75 return fImage->peekPixels(pixmap); |
76 } | 76 } |
77 | 77 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 , fBitmap(bm) { | 122 , fBitmap(bm) { |
123 if (bm.pixelRef()->isPreLocked()) { | 123 if (bm.pixelRef()->isPreLocked()) { |
124 // we only preemptively lock if there is no chance of triggering som
ething expensive | 124 // we only preemptively lock if there is no chance of triggering som
ething expensive |
125 // like a lazy decode or imagegenerator. PreLocked means it is flat
pixels already. | 125 // like a lazy decode or imagegenerator. PreLocked means it is flat
pixels already. |
126 fBitmap.lockPixels(); | 126 fBitmap.lockPixels(); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 ~SkSpecialImage_Raster() override { } | 130 ~SkSpecialImage_Raster() override { } |
131 | 131 |
132 void onDraw(SkCanvas* canvas, int x, int y, const SkPaint* paint) const over
ride { | 132 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
133 SkRect dst = SkRect::MakeXYWH(x, y, | 133 SkRect dst = SkRect::MakeXYWH(x, y, |
134 this->subset().width(), this->subset().hei
ght()); | 134 this->subset().width(), this->subset().hei
ght()); |
135 | 135 |
136 canvas->drawBitmapRect(fBitmap, this->subset(), | 136 canvas->drawBitmapRect(fBitmap, this->subset(), |
137 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 137 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
138 } | 138 } |
139 | 139 |
140 bool onPeekPixels(SkPixmap* pixmap) const override { | 140 bool onPeekPixels(SkPixmap* pixmap) const override { |
141 const SkImageInfo info = fBitmap.info(); | 141 const SkImageInfo info = fBitmap.info(); |
142 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels())
{ | 142 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels())
{ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 class SkSpecialImage_Gpu : public SkSpecialImage_Base { | 175 class SkSpecialImage_Gpu : public SkSpecialImage_Base { |
176 public: | 176 public: |
177 SkSpecialImage_Gpu(const SkIRect& subset, GrTexture* tex) | 177 SkSpecialImage_Gpu(const SkIRect& subset, GrTexture* tex) |
178 : INHERITED(subset) | 178 : INHERITED(subset) |
179 , fTexture(SkRef(tex)) { | 179 , fTexture(SkRef(tex)) { |
180 } | 180 } |
181 | 181 |
182 ~SkSpecialImage_Gpu() override { } | 182 ~SkSpecialImage_Gpu() override { } |
183 | 183 |
184 void onDraw(SkCanvas* canvas, int x, int y, const SkPaint* paint) const over
ride { | 184 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
185 SkRect dst = SkRect::MakeXYWH(x, y, | 185 SkRect dst = SkRect::MakeXYWH(x, y, |
186 this->subset().width(), this->subset().hei
ght()); | 186 this->subset().width(), this->subset().hei
ght()); |
187 | 187 |
188 SkBitmap bm; | 188 SkBitmap bm; |
189 | 189 |
190 static const bool kUnknownOpacity = false; | 190 static const bool kUnknownOpacity = false; |
191 GrWrapTextureInBitmap(fTexture, | 191 GrWrapTextureInBitmap(fTexture, |
192 fTexture->width(), fTexture->height(), kUnknownOpa
city, &bm); | 192 fTexture->width(), fTexture->height(), kUnknownOpa
city, &bm); |
193 | 193 |
194 canvas->drawBitmapRect(bm, this->subset(), | 194 canvas->drawBitmapRect(bm, this->subset(), |
(...skipping 20 matching lines...) Expand all Loading... |
215 return new SkSpecialImage_Gpu(subset, tex); | 215 return new SkSpecialImage_Gpu(subset, tex); |
216 } | 216 } |
217 | 217 |
218 #else | 218 #else |
219 | 219 |
220 SkSpecialImage* SkSpecialImage::NewFromGpu(const SkIRect& subset, GrTexture* tex
) { | 220 SkSpecialImage* SkSpecialImage::NewFromGpu(const SkIRect& subset, GrTexture* tex
) { |
221 return nullptr; | 221 return nullptr; |
222 } | 222 } |
223 | 223 |
224 #endif | 224 #endif |
OLD | NEW |