epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkComposeShader_DEFINED |
| 11 | #define SkComposeShader_DEFINED |
| 12 | |
| 13 | #include "SkShader.h" |
| 14 | |
| 15 | class SkXfermode; |
| 16 | |
| 17 | /////////////////////////////////////////////////////////////////////////////////////////// |
| 18 | |
| 19 | /** \class SkComposeShader |
commit-bot@chromium.org | 5d0b150 | 2014-04-14 15:02:19 +0000 | [diff] [blame] | 20 | This subclass of shader returns the composition of two other shaders, combined by |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | a xfermode. |
| 22 | */ |
ctguil@chromium.org | c7d9f9d | 2011-05-20 22:16:08 +0000 | [diff] [blame] | 23 | class SK_API SkComposeShader : public SkShader { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | public: |
| 25 | /** Create a new compose shader, given shaders A, B, and a combining xfermode mode. |
| 26 | When the xfermode is called, it will be given the result from shader A as its |
commit-bot@chromium.org | 5d0b150 | 2014-04-14 15:02:19 +0000 | [diff] [blame] | 27 | "dst", and the result from shader B as its "src". |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | mode->xfer32(sA_result, sB_result, ...) |
| 29 | @param shaderA The colors from this shader are seen as the "dst" by the xfermode |
| 30 | @param shaderB The colors from this shader are seen as the "src" by the xfermode |
| 31 | @param mode The xfermode that combines the colors from the two shaders. If mode |
| 32 | is null, then SRC_OVER is assumed. |
| 33 | */ |
| 34 | SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode = NULL); |
| 35 | virtual ~SkComposeShader(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 36 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 37 | virtual size_t contextSize() const SK_OVERRIDE; |
| 38 | |
| 39 | class ComposeShaderContext : public SkShader::Context { |
| 40 | public: |
| 41 | // When this object gets destroyed, it will call contextA and contextB's destructor |
| 42 | // but it will NOT free the memory. |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 43 | ComposeShaderContext(const SkComposeShader&, const ContextRec&, |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 44 | SkShader::Context* contextA, SkShader::Context* contextB); |
| 45 | |
| 46 | SkShader::Context* getShaderContextA() const { return fShaderContextA; } |
| 47 | SkShader::Context* getShaderContextB() const { return fShaderContextB; } |
| 48 | |
| 49 | virtual ~ComposeShaderContext(); |
| 50 | |
| 51 | virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE; |
| 52 | |
| 53 | private: |
| 54 | SkShader::Context* fShaderContextA; |
| 55 | SkShader::Context* fShaderContextB; |
| 56 | |
| 57 | typedef SkShader::Context INHERITED; |
| 58 | }; |
| 59 | |
| 60 | #ifdef SK_DEBUG |
| 61 | SkShader* getShaderA() { return fShaderA; } |
| 62 | SkShader* getShaderB() { return fShaderB; } |
| 63 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | |
commit-bot@chromium.org | 7959055 | 2014-05-13 18:14:45 +0000 | [diff] [blame^] | 65 | virtual bool asACompose(ComposeRec* rec) const SK_OVERRIDE; |
| 66 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 67 | SK_TO_STRING_OVERRIDE() |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 68 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeShader) |
| 69 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 70 | protected: |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 71 | SkComposeShader(SkReadBuffer& ); |
| 72 | virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 73 | virtual Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 74 | |
| 75 | private: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | SkShader* fShaderA; |
| 77 | SkShader* fShaderB; |
| 78 | SkXfermode* fMode; |
| 79 | |
| 80 | typedef SkShader INHERITED; |
| 81 | }; |
| 82 | |
| 83 | #endif |