blob: 3035ca1b677831ee7c5ec87ca39203a24cc028f2 [file] [log] [blame]
bsalomon@google.com27847de2011-02-22 20:59:41 +00001/*
2 Copyright 2011 Google Inc.
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 GrPaint_DEFINED
18#define GrPaint_DEFINED
19
20#include "GrTexture.h"
21#include "GrColor.h"
22#include "GrSamplerState.h"
23
Scroggo97c88c22011-05-11 14:05:25 +000024#include "SkXfermode.h"
25
bsalomon@google.com27847de2011-02-22 20:59:41 +000026/**
27 * The paint describes how pixels are colored when the context draws to
28 * them.
29 */
30class GrPaint {
31public:
32
33 // All the paint fields are public except texture (it's ref-counted)
34 GrBlendCoeff fSrcBlendCoeff;
35 GrBlendCoeff fDstBlendCoeff;
36 bool fAntiAlias;
37 bool fDither;
38
39 GrColor fColor;
40
41 GrSamplerState fSampler;
42
Scroggo97c88c22011-05-11 14:05:25 +000043 GrColor fColorFilterColor;
44 SkXfermode::Mode fColorFilterXfermode;
45
bsalomon@google.com27847de2011-02-22 20:59:41 +000046 void setTexture(GrTexture* texture) {
47 GrSafeRef(texture);
48 GrSafeUnref(fTexture);
49 fTexture = texture;
50 }
51
52 GrTexture* getTexture() const { return fTexture; }
53
54 // uninitialized
55 GrPaint() {
56 fTexture = NULL;
57 }
58
59 GrPaint(const GrPaint& paint) {
60 fSrcBlendCoeff = paint.fSrcBlendCoeff;
61 fDstBlendCoeff = paint.fDstBlendCoeff;
62 fAntiAlias = paint.fAntiAlias;
63 fDither = paint.fDither;
64
65 fColor = paint.fColor;
66
Scroggo97c88c22011-05-11 14:05:25 +000067 fColorFilterColor = paint.fColorFilterColor;
68 fColorFilterXfermode = paint.fColorFilterXfermode;
69
bsalomon@google.com27847de2011-02-22 20:59:41 +000070 fSampler = paint.fSampler;
71 fTexture = paint.fTexture;
72 GrSafeRef(fTexture);
73 }
74
75 ~GrPaint() {
76 GrSafeUnref(fTexture);
77 }
78
79 // sets paint to src-over, solid white, no texture
80 void reset() {
81 resetBlend();
82 resetOptions();
83 resetColor();
84 resetTexture();
Scroggo97c88c22011-05-11 14:05:25 +000085 resetColorFilter();
86 }
87
88 void resetColorFilter() {
89 fColorFilterXfermode = SkXfermode::kDst_Mode;
90 fColorFilterColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
bsalomon@google.com27847de2011-02-22 20:59:41 +000091 }
92
93private:
94 GrTexture* fTexture;
95
96 void resetBlend() {
97 fSrcBlendCoeff = kOne_BlendCoeff;
98 fDstBlendCoeff = kZero_BlendCoeff;
99 }
100
101 void resetOptions() {
102 fAntiAlias = false;
103 fDither = false;
104 }
105
106 void resetColor() {
107 fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
108 }
109
110 void resetTexture() {
111 setTexture(NULL);
112 fSampler.setClampNoFilter();
113 }
114
115};
116
117#endif