blob: 2d2dc1a1475dda732610fb4bd8d5c0765bb8ba3b [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) {
13 for (int i = 0; i < GrPaint::kMaxTextures; ++i) {
14 int s = i + GrPaint::kFirstTextureStage;
15 if (paint.isTextureStageEnabled(i)) {
16 *this->sampler(s) = paint.getTextureSampler(i);
17 }
18 }
19
20 this->setFirstCoverageStage(GrPaint::kFirstMaskStage);
21
22 for (int i = 0; i < GrPaint::kMaxMasks; ++i) {
23 int s = i + GrPaint::kFirstMaskStage;
24 if (paint.isMaskStageEnabled(i)) {
25 *this->sampler(s) = paint.getMaskSampler(i);
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}