3 * Copyright 2006 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkComposeShader_DEFINED
11 #define SkComposeShader_DEFINED
17 ///////////////////////////////////////////////////////////////////////////////////////////
19 /** \class SkComposeShader
20 This subclass of shader returns the composition of two other shaders, combined by
23 class SK_API SkComposeShader : public SkShader {
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 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.
34 SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode = NULL);
35 virtual ~SkComposeShader();
37 virtual size_t contextSize() const SK_OVERRIDE;
39 class ComposeShaderContext : public SkShader::Context {
41 // When this object gets destroyed, it will call contextA and contextB's destructor
42 // but it will NOT free the memory.
43 ComposeShaderContext(const SkComposeShader&, const ContextRec&,
44 SkShader::Context* contextA, SkShader::Context* contextB);
46 SkShader::Context* getShaderContextA() const { return fShaderContextA; }
47 SkShader::Context* getShaderContextB() const { return fShaderContextB; }
49 virtual ~ComposeShaderContext();
51 virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
54 SkShader::Context* fShaderContextA;
55 SkShader::Context* fShaderContextB;
57 typedef SkShader::Context INHERITED;
61 SkShader* getShaderA() { return fShaderA; }
62 SkShader* getShaderB() { return fShaderB; }
65 SK_TO_STRING_OVERRIDE()
66 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeShader)
69 SkComposeShader(SkReadBuffer& );
70 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
71 virtual Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE;
78 typedef SkShader INHERITED;