blob: d42da0c2f32aaab77ed14c55c9c4968d92496c08 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkComposeShader_DEFINED
11#define SkComposeShader_DEFINED
12
13#include "SkShader.h"
14
15class SkXfermode;
16
17///////////////////////////////////////////////////////////////////////////////////////////
18
19/** \class SkComposeShader
commit-bot@chromium.org5d0b1502014-04-14 15:02:19 +000020 This subclass of shader returns the composition of two other shaders, combined by
reed@android.com8a1c16f2008-12-17 15:59:43 +000021 a xfermode.
22*/
ctguil@chromium.orgc7d9f9d2011-05-20 22:16:08 +000023class SK_API SkComposeShader : public SkShader {
reed@android.com8a1c16f2008-12-17 15:59:43 +000024public:
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.org5d0b1502014-04-14 15:02:19 +000027 "dst", and the result from shader B as its "src".
reed@android.com8a1c16f2008-12-17 15:59:43 +000028 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.comfbfcd562012-08-23 18:09:54 +000036
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000037 virtual bool validContext(const SkBitmap&, const SkPaint&,
38 const SkMatrix&, SkMatrix* totalInverse = NULL) const SK_OVERRIDE;
39 virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&,
40 const SkMatrix&, void*) const SK_OVERRIDE;
41 virtual size_t contextSize() const SK_OVERRIDE;
42
43 class ComposeShaderContext : public SkShader::Context {
44 public:
45 // When this object gets destroyed, it will call contextA and contextB's destructor
46 // but it will NOT free the memory.
47 ComposeShaderContext(const SkComposeShader&, const SkBitmap&,
48 const SkPaint&, const SkMatrix&,
49 SkShader::Context* contextA, SkShader::Context* contextB);
50
51 SkShader::Context* getShaderContextA() const { return fShaderContextA; }
52 SkShader::Context* getShaderContextB() const { return fShaderContextB; }
53
54 virtual ~ComposeShaderContext();
55
56 virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
57
58 private:
59 SkShader::Context* fShaderContextA;
60 SkShader::Context* fShaderContextB;
61
62 typedef SkShader::Context INHERITED;
63 };
64
65#ifdef SK_DEBUG
66 SkShader* getShaderA() { return fShaderA; }
67 SkShader* getShaderB() { return fShaderB; }
68#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000069
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +000070 SK_TO_STRING_OVERRIDE()
djsollen@google.comba28d032012-03-26 17:57:35 +000071 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeShader)
72
reed@android.com8a1c16f2008-12-17 15:59:43 +000073protected:
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000074 SkComposeShader(SkReadBuffer& );
75 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000076
77private:
reed@android.com8a1c16f2008-12-17 15:59:43 +000078 SkShader* fShaderA;
79 SkShader* fShaderB;
80 SkXfermode* fMode;
81
82 typedef SkShader INHERITED;
83};
84
85#endif