GrPaint.cpp revision 080e673b10ac607305f140ddb245e140ccde40c6
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/GrPorterDuffXferProcessor.h"
13#include "effects/GrSimpleTextureEffect.h"
14
15void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
16    this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
17}
18
19void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
20    this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
21}
22
23void GrPaint::addColorTextureProcessor(GrTexture* texture,
24                                    const SkMatrix& matrix,
25                                    const GrTextureParams& params) {
26    this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
27}
28
29void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
30                                       const SkMatrix& matrix,
31                                       const GrTextureParams& params) {
32    this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
33}
34
35bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const {
36    GrProcOptInfo coverageProcInfo;
37    coverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->numCoverageStages(),
38                                           0xFFFFFFFF, kRGBA_GrColorComponentFlags, true);
39    GrProcOptInfo colorProcInfo;
40    colorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), fColor,
41                                        kRGBA_GrColorComponentFlags, false);
42
43    GrXPFactory::InvariantOutput output;
44    fXPFactory->getInvariantOutput(colorProcInfo, coverageProcInfo, &output);
45
46    if (kRGBA_GrColorComponentFlags == output.fBlendedColorFlags &&
47        0xFF == GrColorUnpackA(output.fBlendedColor)) {
48        *color = output.fBlendedColor;
49        return true;
50    }
51    return false;
52}
53
54void GrPaint::resetStages() {
55    fColorStages.reset();
56    fCoverageStages.reset();
57    fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
58}
59
60