bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrDrawState.h" |
| 9 | |
| 10 | #include "GrPaint.h" |
| 11 | |
| 12 | void GrDrawState::setFromPaint(const GrPaint& paint) { |
bsalomon@google.com | 88becf4 | 2012-10-05 14:54:42 +0000 | [diff] [blame] | 13 | for (int i = 0; i < GrPaint::kMaxColorStages; ++i) { |
| 14 | int s = i + GrPaint::kFirstColorStage; |
| 15 | if (paint.isColorStageEnabled(i)) { |
| 16 | *this->sampler(s) = paint.getColorSampler(i); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 17 | } |
| 18 | } |
| 19 | |
bsalomon@google.com | 88becf4 | 2012-10-05 14:54:42 +0000 | [diff] [blame] | 20 | this->setFirstCoverageStage(GrPaint::kFirstCoverageStage); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 21 | |
bsalomon@google.com | 88becf4 | 2012-10-05 14:54:42 +0000 | [diff] [blame] | 22 | for (int i = 0; i < GrPaint::kMaxCoverageStages; ++i) { |
| 23 | int s = i + GrPaint::kFirstCoverageStage; |
| 24 | if (paint.isCoverageStageEnabled(i)) { |
| 25 | *this->sampler(s) = paint.getCoverageSampler(i); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 26 | } |
| 27 | } |
| 28 | |
| 29 | // disable all stages not accessible via the paint |
| 30 | for (int s = GrPaint::kTotalStages; s < GrDrawState::kNumStages; ++s) { |
| 31 | this->disableStage(s); |
| 32 | } |
| 33 | |
| 34 | this->setColor(paint.fColor); |
| 35 | |
| 36 | this->setState(GrDrawState::kDither_StateBit, paint.fDither); |
| 37 | this->setState(GrDrawState::kHWAntialias_StateBit, paint.fAntiAlias); |
| 38 | |
| 39 | if (paint.fColorMatrixEnabled) { |
| 40 | this->enableState(GrDrawState::kColorMatrix_StateBit); |
| 41 | this->setColorMatrix(paint.fColorMatrix); |
| 42 | } else { |
| 43 | this->disableState(GrDrawState::kColorMatrix_StateBit); |
| 44 | } |
| 45 | this->setBlendFunc(paint.fSrcBlendCoeff, paint.fDstBlendCoeff); |
| 46 | this->setColorFilter(paint.fColorFilterColor, paint.fColorFilterXfermode); |
| 47 | this->setCoverage(paint.fCoverage); |
| 48 | } |