blob: 23902a8488ee98a5231d8709aab2531815c870ea [file] [log] [blame]
bsalomon@google.com5782d712011-01-21 21:03:59 +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 "GrSamplerState.h"
22#include "GrDrawTarget.h"
23
24/**
25 * The paint describes how pixels are colored when the context draws to
26 * them.
27 */
28class GrPaint {
29public:
30
31 // All the paint fields are public except texture (it's ref-counted)
32 GrDrawTarget::BlendCoeff fSrcBlendCoeff;
33 GrDrawTarget::BlendCoeff fDstBlendCoeff;
34 bool fAntiAlias;
35 bool fDither;
36
37 GrColor fColor;
38
39 GrMatrix fTextureMatrix;
40 GrSamplerState fSampler;
41
42 void setTexture(GrTexture* texture) {
43 GrSafeRef(texture);
44 GrSafeUnref(fTexture);
45 fTexture = texture;
46 }
47
48 GrTexture* getTexture() const { return fTexture; }
49
50 // uninitialized
51 GrPaint() {
52 fTexture = NULL;
53 }
54
55 GrPaint(const GrPaint& paint) {
56 fSrcBlendCoeff = paint.fSrcBlendCoeff;
57 fDstBlendCoeff = paint.fDstBlendCoeff;
58 fAntiAlias = paint.fAntiAlias;
59 fDither = paint.fDither;
60
61 fColor = paint.fColor;
62
63 fTextureMatrix = paint.fTextureMatrix;
64 fSampler = paint.fSampler;
65 fTexture = paint.fTexture;
66 GrSafeRef(fTexture);
67 }
68
69 ~GrPaint() {
70 GrSafeUnref(fTexture);
71 }
72
73 // sets paint to src-over, solid white, no texture
74 void reset() {
75 resetBlend();
76 resetOptions();
77 resetColor();
78 resetTexture();
79 }
80
81private:
82 GrTexture* fTexture;
83
84 void resetBlend() {
85 fSrcBlendCoeff = GrDrawTarget::kOne_BlendCoeff;
86 fDstBlendCoeff = GrDrawTarget::kZero_BlendCoeff;
87 }
88
89 void resetOptions() {
90 fAntiAlias = false;
91 fDither = false;
92 }
93
94 void resetColor() {
95 fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
96 }
97
98 void resetTexture() {
99 setTexture(NULL);
100 fTextureMatrix = GrMatrix::I();
101 fSampler.setClampNoFilter();
102 }
103
104};
105
106#endif