blob: a34cbaf445bdaced00d138f1437949f1d55732cd [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"
bsalomon@google.comffca4002011-02-22 20:34:01 +000021#include "GrColor.h"
bsalomon@google.com5782d712011-01-21 21:03:59 +000022#include "GrSamplerState.h"
bsalomon@google.com5782d712011-01-21 21:03:59 +000023
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)
bsalomon@google.comffca4002011-02-22 20:34:01 +000032 GrBlendCoeff fSrcBlendCoeff;
33 GrBlendCoeff fDstBlendCoeff;
bsalomon@google.com5782d712011-01-21 21:03:59 +000034 bool fAntiAlias;
35 bool fDither;
36
37 GrColor fColor;
38
bsalomon@google.com5782d712011-01-21 21:03:59 +000039 GrSamplerState fSampler;
40
41 void setTexture(GrTexture* texture) {
42 GrSafeRef(texture);
43 GrSafeUnref(fTexture);
44 fTexture = texture;
45 }
46
47 GrTexture* getTexture() const { return fTexture; }
48
49 // uninitialized
50 GrPaint() {
51 fTexture = NULL;
52 }
53
54 GrPaint(const GrPaint& paint) {
55 fSrcBlendCoeff = paint.fSrcBlendCoeff;
56 fDstBlendCoeff = paint.fDstBlendCoeff;
57 fAntiAlias = paint.fAntiAlias;
58 fDither = paint.fDither;
59
60 fColor = paint.fColor;
61
bsalomon@google.com5782d712011-01-21 21:03:59 +000062 fSampler = paint.fSampler;
63 fTexture = paint.fTexture;
64 GrSafeRef(fTexture);
65 }
66
67 ~GrPaint() {
68 GrSafeUnref(fTexture);
69 }
70
71 // sets paint to src-over, solid white, no texture
72 void reset() {
73 resetBlend();
74 resetOptions();
75 resetColor();
76 resetTexture();
77 }
78
79private:
80 GrTexture* fTexture;
81
82 void resetBlend() {
bsalomon@google.comffca4002011-02-22 20:34:01 +000083 fSrcBlendCoeff = kOne_BlendCoeff;
84 fDstBlendCoeff = kZero_BlendCoeff;
bsalomon@google.com5782d712011-01-21 21:03:59 +000085 }
86
87 void resetOptions() {
88 fAntiAlias = false;
89 fDither = false;
90 }
91
92 void resetColor() {
93 fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
94 }
95
96 void resetTexture() {
97 setTexture(NULL);
bsalomon@google.com5782d712011-01-21 21:03:59 +000098 fSampler.setClampNoFilter();
99 }
100
101};
102
103#endif