blob: f798cda59c1cd37fb978805205282d7a4bae83a7 [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
bsalomon@google.comc7448ce2012-10-05 19:04:13 +000034 this->setColor(paint.getColor());
bsalomon@google.comaf84e742012-10-05 13:23:24 +000035
bsalomon@google.comc7448ce2012-10-05 19:04:13 +000036 this->setState(GrDrawState::kDither_StateBit, paint.isDither());
37 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias());
bsalomon@google.comaf84e742012-10-05 13:23:24 +000038
bsalomon@google.comc7448ce2012-10-05 19:04:13 +000039 if (paint.isColorMatrixEnabled()) {
bsalomon@google.comaf84e742012-10-05 13:23:24 +000040 this->enableState(GrDrawState::kColorMatrix_StateBit);
bsalomon@google.comc7448ce2012-10-05 19:04:13 +000041 this->setColorMatrix(paint.getColorMatrix());
bsalomon@google.comaf84e742012-10-05 13:23:24 +000042 } else {
43 this->disableState(GrDrawState::kColorMatrix_StateBit);
44 }
bsalomon@google.comc7448ce2012-10-05 19:04:13 +000045 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff());
46 this->setColorFilter(paint.getColorFilterColor(), paint.getColorFilterMode());
47 this->setCoverage(paint.getCoverage());
bsalomon@google.comaf84e742012-10-05 13:23:24 +000048}