| bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +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" |
| 21 | #include "GrColor.h" |
| 22 | #include "GrSamplerState.h" |
| 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) |
| 32 | GrBlendCoeff fSrcBlendCoeff; |
| 33 | GrBlendCoeff fDstBlendCoeff; |
| 34 | bool fAntiAlias; |
| 35 | bool fDither; |
| 36 | |
| 37 | GrColor fColor; |
| 38 | |
| 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 | |
| 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() { |
| 83 | fSrcBlendCoeff = kOne_BlendCoeff; |
| 84 | fDstBlendCoeff = kZero_BlendCoeff; |
| 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); |
| 98 | fSampler.setClampNoFilter(); |
| 99 | } |
| 100 | |
| 101 | }; |
| 102 | |
| 103 | #endif |