GrPaint.cpp revision 4a339529612a43871d021877e58698e067d6c4cd
1
2/*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "GrPaint.h"
10
11#include "GrProcOptInfo.h"
12#include "effects/GrCoverageSetOpXP.h"
13#include "effects/GrPorterDuffXferProcessor.h"
14#include "effects/GrSimpleTextureEffect.h"
15
16GrPaint::GrPaint()
17    : fAntiAlias(false)
18    , fColor(GrColor_WHITE) {}
19
20void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
21    fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
22}
23
24void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
25    this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
26}
27
28void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
29    this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
30}
31
32void GrPaint::addColorTextureProcessor(GrTexture* texture,
33                                       const SkMatrix& matrix,
34                                       const GrTextureParams& params) {
35    this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture,
36                                                                  matrix, params))->unref();
37}
38
39void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
40                                          const SkMatrix& matrix,
41                                          const GrTextureParams& params) {
42    this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture,
43                                                                     matrix, params))->unref();
44}
45
46bool GrPaint::isConstantBlendedColor(GrColor* color) const {
47    GrProcOptInfo colorProcInfo;
48    colorProcInfo.calcWithInitialValues(fColorFragmentProcessors.begin(),
49                                        this->numColorFragmentProcessors(), fColor,
50                                        kRGBA_GrColorComponentFlags, false);
51
52    GrXPFactory::InvariantBlendedColor blendedColor;
53    fXPFactory->getInvariantBlendedColor(colorProcInfo, &blendedColor);
54
55    if (kRGBA_GrColorComponentFlags == blendedColor.fKnownColorFlags) {
56        *color = blendedColor.fKnownColor;
57        return true;
58    }
59    return false;
60}
61