| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1 | /*
|
| 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.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 21 | #include "GrColor.h"
|
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 22 | #include "GrSamplerState.h"
|
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 23 |
|
| 24 | /**
|
| 25 | * The paint describes how pixels are colored when the context draws to
|
| 26 | * them.
|
| 27 | */
|
| 28 | class GrPaint {
|
| 29 | public:
|
| 30 |
|
| 31 | // All the paint fields are public except texture (it's ref-counted)
|
| bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 32 | GrBlendCoeff fSrcBlendCoeff;
|
| 33 | GrBlendCoeff fDstBlendCoeff;
|
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 34 | bool fAntiAlias;
|
| 35 | bool fDither;
|
| 36 |
|
| 37 | GrColor fColor;
|
| 38 |
|
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 39 | 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.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 62 | 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 |
|
| 79 | private:
|
| 80 | GrTexture* fTexture;
|
| 81 |
|
| 82 | void resetBlend() {
|
| bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 83 | fSrcBlendCoeff = kOne_BlendCoeff;
|
| 84 | fDstBlendCoeff = kZero_BlendCoeff;
|
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 85 | }
|
| 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.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 98 | fSampler.setClampNoFilter();
|
| 99 | }
|
| 100 |
|
| 101 | };
|
| 102 |
|
| 103 | #endif
|