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 #ifndef SkImage_Base_DEFINED | 8 #ifndef SkImage_Base_DEFINED |
9 #define SkImage_Base_DEFINED | 9 #define SkImage_Base_DEFINED |
10 | 10 |
11 #include "SkImage.h" | 11 #include "SkImage.h" |
| 12 #include "SkSurface.h" |
| 13 |
| 14 static SkSurfaceProps copy_or_safe_defaults(const SkSurfaceProps* props) { |
| 15 return props ? *props : SkSurfaceProps(0, kUnknown_SkPixelGeometry); |
| 16 } |
12 | 17 |
13 class SkImage_Base : public SkImage { | 18 class SkImage_Base : public SkImage { |
14 public: | 19 public: |
15 SkImage_Base(int width, int height) : INHERITED(width, height) {} | 20 SkImage_Base(int width, int height, const SkSurfaceProps* props) |
| 21 : INHERITED(width, height) |
| 22 , fProps(copy_or_safe_defaults(props)) |
| 23 {} |
| 24 |
| 25 /** |
| 26 * If the props weren't know at constructor time, call this but only before
the image is |
| 27 * ever released into the wild (since the props field must appear to be imm
utable). |
| 28 */ |
| 29 void initWithProps(const SkSurfaceProps& props) { |
| 30 SkASSERT(this->unique()); // only viewed by one thread |
| 31 SkSurfaceProps* mutableProps = const_cast<SkSurfaceProps*>(&fProps); |
| 32 SkASSERT(mutableProps != &props); // check for self-assignment |
| 33 mutableProps->~SkSurfaceProps(); |
| 34 new (mutableProps) SkSurfaceProps(props); |
| 35 } |
| 36 |
| 37 const SkSurfaceProps& props() const { return fProps; } |
16 | 38 |
17 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const
= 0; | 39 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const
= 0; |
18 virtual void onDrawRect(SkCanvas*, const SkRect* src, | 40 virtual void onDrawRect(SkCanvas*, const SkRect* src, |
19 const SkRect& dst, const SkPaint*) const = 0; | 41 const SkRect& dst, const SkPaint*) const = 0; |
| 42 virtual SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) c
onst = 0; |
20 | 43 |
21 // Default impl calls onDraw | 44 // Default impl calls onDraw |
22 virtual bool onReadPixels(SkBitmap*, const SkIRect& subset) const; | 45 virtual bool onReadPixels(SkBitmap*, const SkIRect& subset) const; |
23 | 46 |
24 virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const { | 47 virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const { |
25 return NULL; | 48 return NULL; |
26 } | 49 } |
27 | 50 |
28 virtual GrTexture* onGetTexture() const { return NULL; } | 51 virtual GrTexture* onGetTexture() const { return NULL; } |
29 | 52 |
30 // return a read-only copy of the pixels. We promise to not modify them, | 53 // return a read-only copy of the pixels. We promise to not modify them, |
31 // but only inspect them (or encode them). | 54 // but only inspect them (or encode them). |
32 virtual bool getROPixels(SkBitmap*) const { return false; } | 55 virtual bool getROPixels(SkBitmap*) const { return false; } |
33 | 56 |
34 virtual SkShader* onNewShader(SkShader::TileMode, | 57 virtual SkShader* onNewShader(SkShader::TileMode, |
35 SkShader::TileMode, | 58 SkShader::TileMode, |
36 const SkMatrix* localMatrix) const { return NU
LL; }; | 59 const SkMatrix* localMatrix) const { return NU
LL; }; |
| 60 |
37 private: | 61 private: |
| 62 const SkSurfaceProps fProps; |
| 63 |
38 typedef SkImage INHERITED; | 64 typedef SkImage INHERITED; |
39 }; | 65 }; |
40 | 66 |
| 67 static inline SkImage_Base* as_IB(SkImage* image) { |
| 68 return static_cast<SkImage_Base*>(image); |
| 69 } |
| 70 |
| 71 static inline const SkImage_Base* as_IB(const SkImage* image) { |
| 72 return static_cast<const SkImage_Base*>(image); |
| 73 } |
| 74 |
41 #endif | 75 #endif |
OLD | NEW |