OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 SkBitmapProcShader_DEFINED | 8 #ifndef SkBitmapProcShader_DEFINED |
9 #define SkBitmapProcShader_DEFINED | 9 #define SkBitmapProcShader_DEFINED |
10 | 10 |
11 #include "SkShader.h" | 11 #include "SkShader.h" |
12 #include "SkSmallAllocator.h" | 12 #include "SkSmallAllocator.h" |
13 | 13 |
14 struct SkBitmapProcState; | 14 struct SkBitmapProcState; |
15 class SkBitmapProvider; | 15 class SkBitmapProvider; |
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 = nullptr); | 20 const SkMatrix* localMatrix = nullptr); |
21 | 21 |
22 bool isOpaque() const override; | 22 bool isOpaque() const override; |
23 | 23 |
24 size_t onContextSize(const ContextRec& rec) const override { return ContextS
ize(rec); } | |
25 | |
26 SK_TO_STRING_OVERRIDE() | 24 SK_TO_STRING_OVERRIDE() |
27 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader) | 25 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader) |
28 | 26 |
29 #if SK_SUPPORT_GPU | 27 #if SK_SUPPORT_GPU |
30 const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& v
iewM, | 28 const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& v
iewM, |
31 const SkMatrix*, SkFilterQual
ity) const override; | 29 const SkMatrix*, SkFilterQual
ity) const override; |
32 #endif | 30 #endif |
33 | 31 |
34 protected: | 32 protected: |
35 void flatten(SkWriteBuffer&) const override; | 33 void flatten(SkWriteBuffer&) const override; |
| 34 size_t onContextSize(const ContextRec& rec) const override { |
| 35 return ContextSize(rec, fRawBitmap.info()); |
| 36 } |
36 Context* onCreateContext(const ContextRec&, void* storage) const override; | 37 Context* onCreateContext(const ContextRec&, void* storage) const override; |
37 bool onIsABitmap(SkBitmap*, SkMatrix*, TileMode*) const override; | 38 bool onIsABitmap(SkBitmap*, SkMatrix*, TileMode*) const override; |
38 | 39 |
39 SkBitmap fRawBitmap; // experimental for RLE encoding | 40 SkBitmap fRawBitmap; |
40 uint8_t fTileModeX, fTileModeY; | 41 uint8_t fTileModeX, fTileModeY; |
41 | 42 |
42 private: | 43 private: |
43 friend class SkImageShader; | 44 friend class SkImageShader; |
44 | 45 |
45 static size_t ContextSize(const ContextRec&); | 46 static size_t ContextSize(const ContextRec&, const SkImageInfo& srcInfo); |
46 static Context* MakeContext(const SkShader&, TileMode tmx, TileMode tmy, | 47 static Context* MakeContext(const SkShader&, TileMode tmx, TileMode tmy, |
47 const SkBitmapProvider&, const ContextRec&, void
* storage); | 48 const SkBitmapProvider&, const ContextRec&, void
* storage); |
48 | 49 |
49 typedef SkShader INHERITED; | 50 typedef SkShader INHERITED; |
50 }; | 51 }; |
51 | 52 |
52 // Commonly used allocator. It currently is only used to allocate up to 3 object
s. The total | 53 // Commonly used allocator. It currently is only used to allocate up to 3 object
s. The total |
53 // bytes requested is calculated using one of our large shaders, its context siz
e plus the size of | 54 // bytes requested is calculated using one of our large shaders, its context siz
e plus the size of |
54 // an Sk3DBlitter in SkDraw.cpp | 55 // an Sk3DBlitter in SkDraw.cpp |
55 // Note that some contexts may contain other contexts (e.g. for compose shaders)
, but we've not | 56 // Note that some contexts may contain other contexts (e.g. for compose shaders)
, but we've not |
56 // yet found a situation where the size below isn't big enough. | 57 // yet found a situation where the size below isn't big enough. |
57 typedef SkSmallAllocator<3, 1500> SkTBlitterAllocator; | 58 typedef SkSmallAllocator<3, 2100> SkTBlitterAllocator; |
58 | 59 |
59 // If alloc is non-nullptr, it will be used to allocate the returned SkShader, a
nd MUST outlive | 60 // If alloc is non-nullptr, it will be used to allocate the returned SkShader, a
nd MUST outlive |
60 // the SkShader. | 61 // the SkShader. |
61 SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader
::TileMode, | 62 SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader
::TileMode, |
62 const SkMatrix* localMatrix, SkTBlitterAllocator*
alloc); | 63 const SkMatrix* localMatrix, SkTBlitterAllocator*
alloc); |
63 | 64 |
64 #endif | 65 #endif |
OLD | NEW |