OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkBitmapProcShader_DEFINED | 10 #ifndef SkBitmapProcShader_DEFINED |
11 #define SkBitmapProcShader_DEFINED | 11 #define SkBitmapProcShader_DEFINED |
12 | 12 |
13 #include "SkShader.h" | 13 #include "SkShader.h" |
14 #include "SkBitmapProcState.h" | 14 #include "SkBitmapProcState.h" |
15 #include "SkSmallAllocator.h" | 15 #include "SkSmallAllocator.h" |
16 | 16 |
17 class SkBitmapProcShader : public SkShader { | 17 class SkBitmapProcShader : public SkShader { |
18 public: | 18 public: |
19 SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty, | 19 SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty, |
20 const SkMatrix* localMatrix = NULL); | 20 const SkMatrix* localMatrix = NULL); |
21 | 21 |
22 // overrides from SkShader | 22 // overrides from SkShader |
23 virtual bool isOpaque() const SK_OVERRIDE; | 23 virtual bool isOpaque() const SK_OVERRIDE; |
24 virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERR
IDE; | 24 virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERR
IDE; |
25 | 25 |
26 virtual bool validContext(const SkBitmap& device, | 26 virtual bool validContext(const ContextRec&, SkMatrix* totalInverse) const S
K_OVERRIDE; |
27 const SkPaint& paint, | 27 virtual SkShader::Context* createContext(const ContextRec&, void* storage) c
onst SK_OVERRIDE; |
28 const SkMatrix& matrix, | |
29 SkMatrix* totalInverse = NULL) const SK_OVERRIDE; | |
30 virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&, | |
31 const SkMatrix&, void* storage) con
st SK_OVERRIDE; | |
32 virtual size_t contextSize() const SK_OVERRIDE; | 28 virtual size_t contextSize() const SK_OVERRIDE; |
33 | 29 |
34 static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty); | 30 static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty); |
35 | 31 |
36 SK_TO_STRING_OVERRIDE() | 32 SK_TO_STRING_OVERRIDE() |
37 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader) | 33 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader) |
38 | 34 |
39 #if SK_SUPPORT_GPU | 35 #if SK_SUPPORT_GPU |
40 GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE; | 36 GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE; |
41 #endif | 37 #endif |
42 | 38 |
43 class BitmapProcShaderContext : public SkShader::Context { | 39 class BitmapProcShaderContext : public SkShader::Context { |
44 public: | 40 public: |
45 // The context takes ownership of the state. It will call its destructor | 41 // The context takes ownership of the state. It will call its destructor |
46 // but will NOT free the memory. | 42 // but will NOT free the memory. |
47 BitmapProcShaderContext(const SkBitmapProcShader& shader, | 43 BitmapProcShaderContext(const SkBitmapProcShader&, const ContextRec&, Sk
BitmapProcState*); |
48 const SkBitmap& device, | |
49 const SkPaint& paint, | |
50 const SkMatrix& matrix, | |
51 SkBitmapProcState* state); | |
52 virtual ~BitmapProcShaderContext(); | 44 virtual ~BitmapProcShaderContext(); |
53 | 45 |
54 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVE
RRIDE; | 46 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVE
RRIDE; |
55 virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE; | 47 virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE; |
56 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OV
ERRIDE; | 48 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OV
ERRIDE; |
57 | 49 |
58 virtual uint32_t getFlags() const SK_OVERRIDE { return fFlags; } | 50 virtual uint32_t getFlags() const SK_OVERRIDE { return fFlags; } |
59 | 51 |
60 private: | 52 private: |
61 SkBitmapProcState* fState; | 53 SkBitmapProcState* fState; |
62 uint32_t fFlags; | 54 uint32_t fFlags; |
63 | 55 |
64 typedef SkShader::Context INHERITED; | 56 typedef SkShader::Context INHERITED; |
65 }; | 57 }; |
66 | 58 |
67 protected: | 59 protected: |
68 SkBitmapProcShader(SkReadBuffer& ); | 60 SkBitmapProcShader(SkReadBuffer& ); |
69 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 61 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
70 | 62 |
71 SkBitmap fRawBitmap; // experimental for RLE encoding | 63 SkBitmap fRawBitmap; // experimental for RLE encoding |
72 uint8_t fTileModeX, fTileModeY; | 64 uint8_t fTileModeX, fTileModeY; |
73 | 65 |
74 private: | 66 private: |
75 bool validInternal(const SkBitmap& device, const SkPaint& paint, | 67 bool validInternal(const ContextRec&, SkMatrix* totalInverse, SkBitmapProcSt
ate*) const; |
76 const SkMatrix& matrix, SkMatrix* totalInverse, | |
77 SkBitmapProcState* state) const; | |
78 | 68 |
79 typedef SkShader INHERITED; | 69 typedef SkShader INHERITED; |
80 }; | 70 }; |
81 | 71 |
82 // Commonly used allocator. It currently is only used to allocate up to 3 object
s. The total | 72 // Commonly used allocator. It currently is only used to allocate up to 3 object
s. The total |
83 // bytes requested is calculated using one of our large shaders, its context siz
e plus the size of | 73 // bytes requested is calculated using one of our large shaders, its context siz
e plus the size of |
84 // an Sk3DBlitter in SkDraw.cpp | 74 // an Sk3DBlitter in SkDraw.cpp |
85 // Note that some contexts may contain other contexts (e.g. for compose shaders)
, but we've not | 75 // Note that some contexts may contain other contexts (e.g. for compose shaders)
, but we've not |
86 // yet found a situation where the size below isn't big enough. | 76 // yet found a situation where the size below isn't big enough. |
87 typedef SkSmallAllocator<3, sizeof(SkBitmapProcShader) + | 77 typedef SkSmallAllocator<3, sizeof(SkBitmapProcShader) + |
88 sizeof(SkBitmapProcShader::BitmapProcShaderContext)
+ | 78 sizeof(SkBitmapProcShader::BitmapProcShaderContext)
+ |
89 sizeof(SkBitmapProcState) + | 79 sizeof(SkBitmapProcState) + |
90 sizeof(void*) * 2> SkTBlitterAllocator; | 80 sizeof(void*) * 2> SkTBlitterAllocator; |
91 | 81 |
92 // If alloc is non-NULL, it will be used to allocate the returned SkShader, and
MUST outlive | 82 // If alloc is non-NULL, it will be used to allocate the returned SkShader, and
MUST outlive |
93 // the SkShader. | 83 // the SkShader. |
94 SkShader* CreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::
TileMode, | 84 SkShader* CreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::
TileMode, |
95 const SkMatrix* localMatrix, SkTBlitterAllocator* a
lloc); | 85 const SkMatrix* localMatrix, SkTBlitterAllocator* a
lloc); |
96 | 86 |
97 #endif | 87 #endif |
OLD | NEW |