skia2/include/gpu/GrPaint.h

171 lines
6.2 KiB
C
Raw Normal View History

Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00
#ifndef GrPaint_DEFINED
#define GrPaint_DEFINED
#include "GrColor.h"
#include "GrProcessorDataManager.h"
#include "GrXferProcessor.h"
#include "effects/GrPorterDuffXferProcessor.h"
#include "GrFragmentProcessor.h"
#include "SkRegion.h"
#include "SkXfermode.h"
/**
* The paint describes how color and coverage are computed at each pixel by GrContext draw
* functions and the how color is blended with the destination pixel.
*
* The paint allows installation of custom color and coverage stages. New types of stages are
* created by subclassing GrProcessor.
*
* The primitive color computation starts with the color specified by setColor(). This color is the
* input to the first color stage. Each color stage feeds its output to the next color stage.
*
* Fractional pixel coverage follows a similar flow. The coverage is initially the value specified
* by setCoverage(). This is input to the first coverage stage. Coverage stages are chained
* together in the same manner as color stages. The output of the last stage is modulated by any
* fractional coverage produced by anti-aliasing. This last step produces the final coverage, C.
*
* setXPFactory is used to control blending between the output color and dest. It also implements
* the application of fractional coverage from the coverage pipeline.
*/
class GrPaint {
public:
GrPaint();
GrPaint(const GrPaint& paint) { *this = paint; }
~GrPaint() { this->resetFragmentProcessors(); }
/**
* The initial color of the drawn primitive. Defaults to solid white.
*/
void setColor(GrColor color) { fColor = color; }
GrColor getColor() const { return fColor; }
/**
* Should primitives be anti-aliased or not. Defaults to false.
*/
void setAntiAlias(bool aa) { fAntiAlias = aa; }
bool isAntiAlias() const { return fAntiAlias; }
const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
fXPFactory.reset(SkRef(xpFactory));
return xpFactory;
}
void setPorterDuffXPFactory(SkXfermode::Mode mode) {
fXPFactory.reset(GrPorterDuffXPFactory::Create(mode));
}
void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false);
/**
* Appends an additional color processor to the color computation.
*/
const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcessor* fp) {
SkASSERT(fp);
fColorFragmentProcessors.push_back(SkRef(fp));
return fp;
}
/**
* Appends an additional coverage processor to the coverage computation.
*/
const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* fp) {
SkASSERT(fp);
fCoverageFragmentProcessors.push_back(SkRef(fp));
return fp;
}
/**
* Helpers for adding color or coverage effects that sample a texture. The matrix is applied
* to the src space position to compute texture coordinates.
*/
void addColorTextureProcessor(GrTexture*, const SkMatrix&);
void addCoverageTextureProcessor(GrTexture*, const SkMatrix&);
void addColorTextureProcessor(GrTexture*, const SkMatrix&, const GrTextureParams&);
void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrTextureParams&);
int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); }
int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); }
int numTotalFragmentProcessors() const { return this->numColorFragmentProcessors() +
this->numCoverageFragmentProcessors(); }
const GrXPFactory* getXPFactory() const {
if (!fXPFactory) {
fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
}
return fXPFactory.get();
}
const GrFragmentProcessor* getColorFragmentProcessor(int i) const {
return fColorFragmentProcessors[i];
}
const GrFragmentProcessor* getCoverageFragmentProcessor(int i) const {
return fCoverageFragmentProcessors[i];
}
GrPaint& operator=(const GrPaint& paint) {
fAntiAlias = paint.fAntiAlias;
fColor = paint.fColor;
this->resetFragmentProcessors();
fColorFragmentProcessors = paint.fColorFragmentProcessors;
fCoverageFragmentProcessors = paint.fCoverageFragmentProcessors;
for (int i = 0; i < fColorFragmentProcessors.count(); ++i) {
fColorFragmentProcessors[i]->ref();
}
for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) {
fCoverageFragmentProcessors[i]->ref();
}
fXPFactory.reset(SkRef(paint.getXPFactory()));
return *this;
}
/**
* Returns true if the paint's output color will be constant after blending. If the result is
* true, constantColor will be updated to contain the constant color. Note that we can conflate
* coverage and color, so the actual values written to pixels with partial coverage may still
* not seem constant, even if this function returns true.
*/
bool isConstantBlendedColor(GrColor* constantColor) const;
GrProcessorDataManager* getProcessorDataManager() { return &fProcDataManager; }
const GrProcessorDataManager* processorDataManager() const { return &fProcDataManager; }
private:
void resetFragmentProcessors() {
for (int i = 0; i < fColorFragmentProcessors.count(); ++i) {
fColorFragmentProcessors[i]->unref();
}
for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) {
fCoverageFragmentProcessors[i]->unref();
}
fColorFragmentProcessors.reset();
fCoverageFragmentProcessors.reset();
}
mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
SkSTArray<4, const GrFragmentProcessor*, true> fColorFragmentProcessors;
SkSTArray<2, const GrFragmentProcessor*, true> fCoverageFragmentProcessors;
bool fAntiAlias;
GrColor fColor;
GrProcessorDataManager fProcDataManager;
};
#endif