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