• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SkComposeShader_DEFINED
18 #define SkComposeShader_DEFINED
19 
20 #include "SkShader.h"
21 
22 class SkXfermode;
23 
24 ///////////////////////////////////////////////////////////////////////////////////////////
25 
26 /** \class SkComposeShader
27     This subclass of shader returns the coposition of two other shaders, combined by
28     a xfermode.
29 */
30 class SkComposeShader : public SkShader {
31 public:
32     /** Create a new compose shader, given shaders A, B, and a combining xfermode mode.
33         When the xfermode is called, it will be given the result from shader A as its
34         "dst", and the result of from shader B as its "src".
35         mode->xfer32(sA_result, sB_result, ...)
36         @param shaderA  The colors from this shader are seen as the "dst" by the xfermode
37         @param shaderB  The colors from this shader are seen as the "src" by the xfermode
38         @param mode     The xfermode that combines the colors from the two shaders. If mode
39                         is null, then SRC_OVER is assumed.
40     */
41     SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode = NULL);
42     virtual ~SkComposeShader();
43 
44     // override
45     virtual bool setContext(const SkBitmap& device, const SkPaint& paint, const SkMatrix& matrix);
46     virtual void shadeSpan(int x, int y, SkPMColor result[], int count);
47     virtual void beginSession();
48     virtual void endSession();
49 
50 protected:
51     SkComposeShader(SkFlattenableReadBuffer& );
52     virtual void flatten(SkFlattenableWriteBuffer& );
getFactory()53     virtual Factory getFactory() { return CreateProc; }
54 
55 private:
CreateProc(SkFlattenableReadBuffer & buffer)56     static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
57         return SkNEW_ARGS(SkComposeShader, (buffer)); }
58 
59     SkShader*   fShaderA;
60     SkShader*   fShaderB;
61     SkXfermode* fMode;
62 
63     typedef SkShader INHERITED;
64 };
65 
66 #endif
67