blob: bd6e2685bb45bb796bee2849eb15238eb498f7ed [file] [log] [blame]
bsalomon@google.comaf84e742012-10-05 13:23:24 +00001/*
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
12void GrDrawState::setFromPaint(const GrPaint& paint) {
bsalomon@google.com88becf42012-10-05 14:54:42 +000013 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.comaf84e742012-10-05 13:23:24 +000017 }
18 }
19
bsalomon@google.com88becf42012-10-05 14:54:42 +000020 this->setFirstCoverageStage(GrPaint::kFirstCoverageStage);
bsalomon@google.comaf84e742012-10-05 13:23:24 +000021
bsalomon@google.com88becf42012-10-05 14:54:42 +000022 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.comaf84e742012-10-05 13:23:24 +000026 }
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}