Added gpu AA clipping to old shader path
http://codereview.appspot.com/6139065/ git-svn-id: http://skia.googlecode.com/svn/trunk@3812 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
f0a062bc45
commit
a72eef322c
@ -11,6 +11,10 @@
|
||||
#include "GrRenderTarget.h"
|
||||
#include "GrStencilBuffer.h"
|
||||
#include "GrPathRenderer.h"
|
||||
#include "GrPaint.h"
|
||||
|
||||
//#define GR_AA_CLIP 1
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void ScissoringSettings::setupScissoring(GrGpu* gpu) {
|
||||
@ -22,6 +26,34 @@ void ScissoringSettings::setupScissoring(GrGpu* gpu) {
|
||||
gpu->enableScissoring(fScissorRect);
|
||||
}
|
||||
|
||||
namespace {
|
||||
// set up the draw state to enable the aa clipping mask. Besides setting up the
|
||||
// sampler matrix this also alters the vertex layout
|
||||
void setupDrawStateAAClip(GrGpu* gpu, GrTexture* result, const GrRect &bound) {
|
||||
GrDrawState* drawState = gpu->drawState();
|
||||
GrAssert(drawState);
|
||||
|
||||
static const int maskStage = GrPaint::kTotalStages+1;
|
||||
|
||||
GrMatrix mat;
|
||||
mat.setIDiv(result->width(), result->height());
|
||||
mat.preTranslate(-bound.fLeft, -bound.fTop);
|
||||
mat.preConcat(drawState->getViewMatrix());
|
||||
|
||||
drawState->sampler(maskStage)->reset(GrSamplerState::kClamp_WrapMode,
|
||||
GrSamplerState::kNearest_Filter,
|
||||
mat);
|
||||
|
||||
drawState->setTexture(maskStage, result);
|
||||
|
||||
// The AA clipping determination happens long after the geometry has
|
||||
// been set up to draw. Here we directly enable the AA clip mask stage
|
||||
gpu->addToVertexLayout(
|
||||
GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(maskStage));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// sort out what kind of clip mask needs to be created: alpha, stencil
|
||||
// or scissor
|
||||
@ -53,8 +85,12 @@ bool GrClipMaskManager::createClipMask(GrGpu* gpu,
|
||||
// size for the mask (rather than being bound by the size of the
|
||||
// render target) we aren't going to use scissoring like the stencil
|
||||
// path does (see scissorSettings below)
|
||||
if (this->createAlphaClipMask(gpu, clipIn)) {
|
||||
GrTexture* result = NULL;
|
||||
GrRect bound;
|
||||
if (this->createAlphaClipMask(gpu, clipIn, &result, &bound)) {
|
||||
fClipMaskInAlpha = true;
|
||||
|
||||
setupDrawStateAAClip(gpu, result, bound);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -319,7 +355,10 @@ void clear(GrGpu* gpu,
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Create a 8-bit clip mask in alpha
|
||||
bool GrClipMaskManager::createAlphaClipMask(GrGpu* gpu, const GrClip& clipIn) {
|
||||
bool GrClipMaskManager::createAlphaClipMask(GrGpu* gpu,
|
||||
const GrClip& clipIn,
|
||||
GrTexture** result,
|
||||
GrRect *resultBounds) {
|
||||
|
||||
GrDrawState* origDrawState = gpu->drawState();
|
||||
GrAssert(origDrawState->isClipState());
|
||||
@ -353,6 +392,8 @@ bool GrClipMaskManager::createAlphaClipMask(GrGpu* gpu, const GrClip& clipIn) {
|
||||
// path doesn't leave any room for antialiasing (esp. w.r.t. rects)
|
||||
bounds.outset(SkIntToScalar(1), SkIntToScalar(1));
|
||||
|
||||
// TODO: make sure we don't outset if bounds are still 0,0 @ min
|
||||
|
||||
GrAssert(SkScalarIsInt(bounds.width()));
|
||||
GrAssert(SkScalarIsInt(bounds.height()));
|
||||
|
||||
@ -464,6 +505,8 @@ bool GrClipMaskManager::createAlphaClipMask(GrGpu* gpu, const GrClip& clipIn) {
|
||||
}
|
||||
}
|
||||
|
||||
*result = accum;
|
||||
*resultBounds = bounds;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,10 @@ private:
|
||||
const GrClip& clip,
|
||||
const GrRect& bounds,
|
||||
ScissoringSettings* scissorSettings);
|
||||
bool createAlphaClipMask(GrGpu* gpu, const GrClip& clipIn);
|
||||
bool createAlphaClipMask(GrGpu* gpu,
|
||||
const GrClip& clipIn,
|
||||
GrTexture** result,
|
||||
GrRect *resultBounds);
|
||||
|
||||
bool drawPath(GrGpu* gpu,
|
||||
const SkPath& path,
|
||||
|
@ -331,7 +331,7 @@ public:
|
||||
////
|
||||
|
||||
/**
|
||||
* Sets the matrix applied to veretx positions.
|
||||
* Sets the matrix applied to vertex positions.
|
||||
*
|
||||
* In the post-view-matrix space the rectangle [0,w]x[0,h]
|
||||
* fully covers the render target. (w and h are the width and height of the
|
||||
|
@ -20,7 +20,7 @@ namespace {
|
||||
/**
|
||||
* This function generates some masks that we like to have known at compile
|
||||
* time. When the number of stages or tex coords is bumped or the way bits
|
||||
* are defined in GrDrawTarget.h changes this funcion should be rerun to
|
||||
* are defined in GrDrawTarget.h changes this function should be rerun to
|
||||
* generate the new masks. (We attempted to force the compiler to generate the
|
||||
* masks using recursive templates but always wound up with static initializers
|
||||
* under gcc, even if they were just a series of immediate->memory moves.)
|
||||
|
@ -209,6 +209,19 @@ public:
|
||||
return (1 << (TEX_COORD_BIT_CNT + stage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the existing vertex layout. Realistically the only thing that
|
||||
* can be added w/o recomputing the vertex layout is one of the
|
||||
* StagePosAsTexCoordVertexLayoutBit flags
|
||||
*/
|
||||
void addToVertexLayout(int flag) {
|
||||
GrAssert((1 << TEX_COORD_BIT_CNT) == flag ||
|
||||
(1 << (TEX_COORD_BIT_CNT + 1)) == flag ||
|
||||
(1 << (TEX_COORD_BIT_CNT + 2)) == flag ||
|
||||
(1 << (TEX_COORD_BIT_CNT + 3)) == flag);
|
||||
fGeoSrcStateStack.back().fVertexLayout |= flag;
|
||||
}
|
||||
|
||||
private:
|
||||
static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT +
|
||||
GrDrawState::kNumStages;
|
||||
|
Loading…
Reference in New Issue
Block a user