OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 | |
10 #ifndef SkBitmapProcShader_DEFINED | 8 #ifndef SkBitmapProcShader_DEFINED |
11 #define SkBitmapProcShader_DEFINED | 9 #define SkBitmapProcShader_DEFINED |
12 | 10 |
13 #include "SkShader.h" | 11 #include "SkShader.h" |
14 #include "SkSmallAllocator.h" | 12 #include "SkSmallAllocator.h" |
15 | 13 |
16 struct SkBitmapProcState; | 14 struct SkBitmapProcState; |
17 class SkBitmapProvider; | 15 class SkBitmapProvider; |
18 | 16 |
19 class SkBitmapProcShader : public SkShader { | 17 class SkBitmapProcShader : public SkShader { |
20 public: | 18 public: |
21 SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty, | 19 SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty, |
22 const SkMatrix* localMatrix = nullptr); | 20 const SkMatrix* localMatrix = nullptr); |
23 | 21 |
24 bool isOpaque() const override; | 22 bool isOpaque() const override; |
25 | 23 |
26 size_t contextSize(const ContextRec&) const override { return ContextSize();
} | 24 size_t contextSize(const ContextRec& rec) const override { return ContextSiz
e(rec); } |
27 | 25 |
28 SK_TO_STRING_OVERRIDE() | 26 SK_TO_STRING_OVERRIDE() |
29 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader) | 27 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader) |
30 | 28 |
31 #if SK_SUPPORT_GPU | 29 #if SK_SUPPORT_GPU |
32 const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& v
iewM, | 30 const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& v
iewM, |
33 const SkMatrix*, SkFilterQual
ity) const override; | 31 const SkMatrix*, SkFilterQual
ity) const override; |
34 #endif | 32 #endif |
35 | 33 |
36 protected: | 34 protected: |
37 class BitmapProcShaderContext : public SkShader::Context { | |
38 public: | |
39 // The context takes ownership of the state. It will call its destructor | |
40 // but will NOT free the memory. | |
41 BitmapProcShaderContext(const SkShader&, const ContextRec&, SkBitmapProc
State*); | |
42 ~BitmapProcShaderContext() override; | |
43 | |
44 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override; | |
45 ShadeProc asAShadeProc(void** ctx) override; | |
46 | |
47 uint32_t getFlags() const override { return fFlags; } | |
48 | |
49 private: | |
50 SkBitmapProcState* fState; | |
51 uint32_t fFlags; | |
52 | |
53 typedef SkShader::Context INHERITED; | |
54 }; | |
55 | |
56 void flatten(SkWriteBuffer&) const override; | 35 void flatten(SkWriteBuffer&) const override; |
57 Context* onCreateContext(const ContextRec&, void* storage) const override; | 36 Context* onCreateContext(const ContextRec&, void* storage) const override; |
58 bool onIsABitmap(SkBitmap*, SkMatrix*, TileMode*) const override; | 37 bool onIsABitmap(SkBitmap*, SkMatrix*, TileMode*) const override; |
59 | 38 |
60 SkBitmap fRawBitmap; // experimental for RLE encoding | 39 SkBitmap fRawBitmap; // experimental for RLE encoding |
61 uint8_t fTileModeX, fTileModeY; | 40 uint8_t fTileModeX, fTileModeY; |
62 | 41 |
63 private: | 42 private: |
64 friend class SkImageShader; | 43 friend class SkImageShader; |
65 | 44 |
66 static size_t ContextSize(); | 45 static size_t ContextSize(const ContextRec&); |
67 static Context* MakeContext(const SkShader&, TileMode tmx, TileMode tmy, | 46 static Context* MakeContext(const SkShader&, TileMode tmx, TileMode tmy, |
68 const SkBitmapProvider&, const ContextRec&, void
* storage); | 47 const SkBitmapProvider&, const ContextRec&, void
* storage); |
69 | 48 |
70 typedef SkShader INHERITED; | 49 typedef SkShader INHERITED; |
71 }; | 50 }; |
72 | 51 |
73 // 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 3 object
s. The total |
74 // 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, its context siz
e plus the size of |
75 // an Sk3DBlitter in SkDraw.cpp | 54 // an Sk3DBlitter in SkDraw.cpp |
76 // Note that some contexts may contain other contexts (e.g. for compose shaders)
, but we've not | 55 // Note that some contexts may contain other contexts (e.g. for compose shaders)
, but we've not |
77 // yet found a situation where the size below isn't big enough. | 56 // yet found a situation where the size below isn't big enough. |
78 typedef SkSmallAllocator<3, 1500> SkTBlitterAllocator; | 57 typedef SkSmallAllocator<3, 1500> SkTBlitterAllocator; |
79 | 58 |
80 // If alloc is non-nullptr, it will be used to allocate the returned SkShader, a
nd MUST outlive | 59 // If alloc is non-nullptr, it will be used to allocate the returned SkShader, a
nd MUST outlive |
81 // the SkShader. | 60 // the SkShader. |
82 SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader
::TileMode, | 61 SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader
::TileMode, |
83 const SkMatrix* localMatrix, SkTBlitterAllocator*
alloc); | 62 const SkMatrix* localMatrix, SkTBlitterAllocator*
alloc); |
84 | 63 |
85 #endif | 64 #endif |
OLD | NEW |