blob: f2439542a163554d9471648dc7715aad0807ccf6 [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
20 This subclass of shader returns the coposition of two other shaders, combined by
21 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
27 "dst", and the result of from shader B as its "src".
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();
36
37 // override
38 virtual bool setContext(const SkBitmap& device, const SkPaint& paint, const SkMatrix& matrix);
39 virtual void shadeSpan(int x, int y, SkPMColor result[], int count);
40 virtual void beginSession();
41 virtual void endSession();
42
43protected:
44 SkComposeShader(SkFlattenableReadBuffer& );
45 virtual void flatten(SkFlattenableWriteBuffer& );
46 virtual Factory getFactory() { return CreateProc; }
47
48private:
49 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
50 return SkNEW_ARGS(SkComposeShader, (buffer)); }
51
52 SkShader* fShaderA;
53 SkShader* fShaderB;
54 SkXfermode* fMode;
55
56 typedef SkShader INHERITED;
57};
58
59#endif