epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2006 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #ifndef SkBitmapProcShader_DEFINED |
| 11 | #define SkBitmapProcShader_DEFINED |
| 12 | |
| 13 | #include "SkShader.h" |
| 14 | #include "SkBitmapProcState.h" |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 15 | #include "SkSmallAllocator.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | |
| 17 | class SkBitmapProcShader : public SkShader { |
| 18 | public: |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 19 | SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty, |
| 20 | const SkMatrix* localMatrix = NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | |
| 22 | // overrides from SkShader |
junov@chromium.org | b6e1619 | 2011-12-09 15:48:03 +0000 | [diff] [blame] | 23 | virtual bool isOpaque() const SK_OVERRIDE; |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 24 | virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 26 | virtual size_t contextSize() const SK_OVERRIDE; |
| 27 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty); |
skia.committer@gmail.com | ff21c2e | 2013-01-16 07:05:56 +0000 | [diff] [blame] | 29 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 30 | SK_TO_STRING_OVERRIDE() |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 31 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | |
bsalomon@google.com | e197cbf | 2013-01-14 16:46:26 +0000 | [diff] [blame] | 33 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 34 | GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE; |
bsalomon@google.com | e197cbf | 2013-01-14 16:46:26 +0000 | [diff] [blame] | 35 | #endif |
| 36 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 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. |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 41 | BitmapProcShaderContext(const SkBitmapProcShader&, const ContextRec&, SkBitmapProcState*); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 42 | virtual ~BitmapProcShaderContext(); |
| 43 | |
| 44 | virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE; |
| 45 | virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE; |
| 46 | virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE; |
| 47 | |
| 48 | virtual uint32_t getFlags() const SK_OVERRIDE { return fFlags; } |
| 49 | |
| 50 | private: |
| 51 | SkBitmapProcState* fState; |
| 52 | uint32_t fFlags; |
| 53 | |
| 54 | typedef SkShader::Context INHERITED; |
| 55 | }; |
| 56 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | protected: |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 58 | SkBitmapProcShader(SkReadBuffer& ); |
| 59 | virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame^] | 60 | virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 62 | SkBitmap fRawBitmap; // experimental for RLE encoding |
| 63 | uint8_t fTileModeX, fTileModeY; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | |
reed@google.com | 7c2f27d | 2011-03-07 19:29:00 +0000 | [diff] [blame] | 65 | private: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | typedef SkShader INHERITED; |
| 67 | }; |
| 68 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 69 | // Commonly used allocator. It currently is only used to allocate up to 3 objects. The total |
| 70 | // bytes requested is calculated using one of our large shaders, its context size plus the size of |
| 71 | // an Sk3DBlitter in SkDraw.cpp |
| 72 | // Note that some contexts may contain other contexts (e.g. for compose shaders), but we've not |
| 73 | // yet found a situation where the size below isn't big enough. |
| 74 | typedef SkSmallAllocator<3, sizeof(SkBitmapProcShader) + |
| 75 | sizeof(SkBitmapProcShader::BitmapProcShaderContext) + |
| 76 | sizeof(SkBitmapProcState) + |
| 77 | sizeof(void*) * 2> SkTBlitterAllocator; |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 78 | |
| 79 | // If alloc is non-NULL, it will be used to allocate the returned SkShader, and MUST outlive |
| 80 | // the SkShader. |
| 81 | SkShader* CreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::TileMode, |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 82 | const SkMatrix* localMatrix, SkTBlitterAllocator* alloc); |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 83 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 84 | #endif |