Use a single GrDrawState in GrContext for direct and buffered drawing
Review URL: http://codereview.appspot.com/5933043/ git-svn-id: http://skia.googlecode.com/svn/trunk@3507 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
a5d056ae0b
commit
a5d2203f58
@ -17,6 +17,7 @@
|
|||||||
#include "GrRenderTarget.h"
|
#include "GrRenderTarget.h"
|
||||||
|
|
||||||
class GrAutoScratchTexture;
|
class GrAutoScratchTexture;
|
||||||
|
class GrDrawState;
|
||||||
class GrDrawTarget;
|
class GrDrawTarget;
|
||||||
class GrFontCache;
|
class GrFontCache;
|
||||||
class GrGpu;
|
class GrGpu;
|
||||||
@ -671,6 +672,8 @@ private:
|
|||||||
DrawCategory fLastDrawCategory;
|
DrawCategory fLastDrawCategory;
|
||||||
|
|
||||||
GrGpu* fGpu;
|
GrGpu* fGpu;
|
||||||
|
GrDrawState* fDrawState;
|
||||||
|
|
||||||
GrResourceCache* fTextureCache;
|
GrResourceCache* fTextureCache;
|
||||||
GrFontCache* fFontCache;
|
GrFontCache* fFontCache;
|
||||||
|
|
||||||
@ -704,7 +707,7 @@ private:
|
|||||||
|
|
||||||
void flushDrawBuffer();
|
void flushDrawBuffer();
|
||||||
|
|
||||||
void setPaint(const GrPaint& paint, GrDrawTarget* target);
|
void setPaint(const GrPaint& paint);
|
||||||
|
|
||||||
GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
|
GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ GrContext::~GrContext() {
|
|||||||
GrSafeUnref(fAAStrokeRectIndexBuffer);
|
GrSafeUnref(fAAStrokeRectIndexBuffer);
|
||||||
fGpu->unref();
|
fGpu->unref();
|
||||||
GrSafeUnref(fPathRendererChain);
|
GrSafeUnref(fPathRendererChain);
|
||||||
|
fDrawState->unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrContext::contextLost() {
|
void GrContext::contextLost() {
|
||||||
@ -655,7 +656,7 @@ const GrClip& GrContext::getClip() const { return fGpu->getClip(); }
|
|||||||
|
|
||||||
void GrContext::setClip(const GrClip& clip) {
|
void GrContext::setClip(const GrClip& clip) {
|
||||||
fGpu->setClip(clip);
|
fGpu->setClip(clip);
|
||||||
fGpu->drawState()->enableState(GrDrawState::kClip_StateBit);
|
fDrawState->enableState(GrDrawState::kClip_StateBit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrContext::setClip(const GrIRect& rect) {
|
void GrContext::setClip(const GrIRect& rect) {
|
||||||
@ -681,21 +682,20 @@ void GrContext::drawPaint(const GrPaint& paint) {
|
|||||||
GrMatrix inverse;
|
GrMatrix inverse;
|
||||||
SkTLazy<GrPaint> tmpPaint;
|
SkTLazy<GrPaint> tmpPaint;
|
||||||
const GrPaint* p = &paint;
|
const GrPaint* p = &paint;
|
||||||
GrDrawState* drawState = fGpu->drawState();
|
|
||||||
GrAutoMatrix am;
|
GrAutoMatrix am;
|
||||||
|
|
||||||
// We attempt to map r by the inverse matrix and draw that. mapRect will
|
// We attempt to map r by the inverse matrix and draw that. mapRect will
|
||||||
// map the four corners and bound them with a new rect. This will not
|
// map the four corners and bound them with a new rect. This will not
|
||||||
// produce a correct result for some perspective matrices.
|
// produce a correct result for some perspective matrices.
|
||||||
if (!this->getMatrix().hasPerspective()) {
|
if (!this->getMatrix().hasPerspective()) {
|
||||||
if (!drawState->getViewInverse(&inverse)) {
|
if (!fDrawState->getViewInverse(&inverse)) {
|
||||||
GrPrintf("Could not invert matrix");
|
GrPrintf("Could not invert matrix");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
inverse.mapRect(&r);
|
inverse.mapRect(&r);
|
||||||
} else {
|
} else {
|
||||||
if (paint.getActiveMaskStageMask() || paint.getActiveStageMask()) {
|
if (paint.getActiveMaskStageMask() || paint.getActiveStageMask()) {
|
||||||
if (!drawState->getViewInverse(&inverse)) {
|
if (!fDrawState->getViewInverse(&inverse)) {
|
||||||
GrPrintf("Could not invert matrix");
|
GrPrintf("Could not invert matrix");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1640,7 +1640,7 @@ bool GrContext::internalReadRenderTargetPixels(GrRenderTarget* target,
|
|||||||
ASSERT_OWNED_RESOURCE(target);
|
ASSERT_OWNED_RESOURCE(target);
|
||||||
|
|
||||||
if (NULL == target) {
|
if (NULL == target) {
|
||||||
target = fGpu->drawState()->getRenderTarget();
|
target = fDrawState->getRenderTarget();
|
||||||
if (NULL == target) {
|
if (NULL == target) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1894,57 +1894,57 @@ void GrContext::internalWriteRenderTargetPixels(GrRenderTarget* target,
|
|||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void GrContext::setPaint(const GrPaint& paint, GrDrawTarget* target) {
|
void GrContext::setPaint(const GrPaint& paint) {
|
||||||
GrDrawState* drawState = target->drawState();
|
|
||||||
|
|
||||||
for (int i = 0; i < GrPaint::kMaxTextures; ++i) {
|
for (int i = 0; i < GrPaint::kMaxTextures; ++i) {
|
||||||
int s = i + GrPaint::kFirstTextureStage;
|
int s = i + GrPaint::kFirstTextureStage;
|
||||||
drawState->setTexture(s, paint.getTexture(i));
|
fDrawState->setTexture(s, paint.getTexture(i));
|
||||||
ASSERT_OWNED_RESOURCE(paint.getTexture(i));
|
ASSERT_OWNED_RESOURCE(paint.getTexture(i));
|
||||||
if (paint.getTexture(i)) {
|
if (paint.getTexture(i)) {
|
||||||
*drawState->sampler(s) = paint.getTextureSampler(i);
|
*fDrawState->sampler(s) = paint.getTextureSampler(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drawState->setFirstCoverageStage(GrPaint::kFirstMaskStage);
|
fDrawState->setFirstCoverageStage(GrPaint::kFirstMaskStage);
|
||||||
|
|
||||||
for (int i = 0; i < GrPaint::kMaxMasks; ++i) {
|
for (int i = 0; i < GrPaint::kMaxMasks; ++i) {
|
||||||
int s = i + GrPaint::kFirstMaskStage;
|
int s = i + GrPaint::kFirstMaskStage;
|
||||||
drawState->setTexture(s, paint.getMask(i));
|
fDrawState->setTexture(s, paint.getMask(i));
|
||||||
ASSERT_OWNED_RESOURCE(paint.getMask(i));
|
ASSERT_OWNED_RESOURCE(paint.getMask(i));
|
||||||
if (paint.getMask(i)) {
|
if (paint.getMask(i)) {
|
||||||
*drawState->sampler(s) = paint.getMaskSampler(i);
|
*fDrawState->sampler(s) = paint.getMaskSampler(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable all stages not accessible via the paint
|
// disable all stages not accessible via the paint
|
||||||
for (int s = GrPaint::kTotalStages; s < GrDrawState::kNumStages; ++s) {
|
for (int s = GrPaint::kTotalStages; s < GrDrawState::kNumStages; ++s) {
|
||||||
drawState->setTexture(s, NULL);
|
fDrawState->setTexture(s, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawState->setColor(paint.fColor);
|
fDrawState->setColor(paint.fColor);
|
||||||
|
|
||||||
if (paint.fDither) {
|
if (paint.fDither) {
|
||||||
drawState->enableState(GrDrawState::kDither_StateBit);
|
fDrawState->enableState(GrDrawState::kDither_StateBit);
|
||||||
} else {
|
} else {
|
||||||
drawState->disableState(GrDrawState::kDither_StateBit);
|
fDrawState->disableState(GrDrawState::kDither_StateBit);
|
||||||
}
|
}
|
||||||
if (paint.fAntiAlias) {
|
if (paint.fAntiAlias) {
|
||||||
drawState->enableState(GrDrawState::kHWAntialias_StateBit);
|
fDrawState->enableState(GrDrawState::kHWAntialias_StateBit);
|
||||||
} else {
|
} else {
|
||||||
drawState->disableState(GrDrawState::kHWAntialias_StateBit);
|
fDrawState->disableState(GrDrawState::kHWAntialias_StateBit);
|
||||||
}
|
}
|
||||||
if (paint.fColorMatrixEnabled) {
|
if (paint.fColorMatrixEnabled) {
|
||||||
drawState->enableState(GrDrawState::kColorMatrix_StateBit);
|
fDrawState->enableState(GrDrawState::kColorMatrix_StateBit);
|
||||||
drawState->setColorMatrix(paint.fColorMatrix);
|
fDrawState->setColorMatrix(paint.fColorMatrix);
|
||||||
} else {
|
} else {
|
||||||
drawState->disableState(GrDrawState::kColorMatrix_StateBit);
|
fDrawState->disableState(GrDrawState::kColorMatrix_StateBit);
|
||||||
}
|
}
|
||||||
drawState->setBlendFunc(paint.fSrcBlendCoeff, paint.fDstBlendCoeff);
|
fDrawState->setBlendFunc(paint.fSrcBlendCoeff, paint.fDstBlendCoeff);
|
||||||
drawState->setColorFilter(paint.fColorFilterColor, paint.fColorFilterXfermode);
|
fDrawState->setColorFilter(paint.fColorFilterColor, paint.fColorFilterXfermode);
|
||||||
drawState->setCoverage(paint.fCoverage);
|
fDrawState->setCoverage(paint.fCoverage);
|
||||||
|
|
||||||
if (paint.getActiveMaskStageMask() && !target->canApplyCoverage()) {
|
if ((paint.getActiveMaskStageMask() || 0xffffffff != paint.fCoverage) &&
|
||||||
|
!fGpu->canApplyCoverage()) {
|
||||||
GrPrintf("Partial pixel coverage will be incorrectly blended.\n");
|
GrPrintf("Partial pixel coverage will be incorrectly blended.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1955,13 +1955,13 @@ GrDrawTarget* GrContext::prepareToDraw(const GrPaint& paint,
|
|||||||
this->flushDrawBuffer();
|
this->flushDrawBuffer();
|
||||||
fLastDrawCategory = category;
|
fLastDrawCategory = category;
|
||||||
}
|
}
|
||||||
this->setPaint(paint, fGpu);
|
this->setPaint(paint);
|
||||||
GrDrawTarget* target = fGpu;
|
GrDrawTarget* target = fGpu;
|
||||||
switch (category) {
|
switch (category) {
|
||||||
case kText_DrawCategory:
|
case kText_DrawCategory:
|
||||||
#if DEFER_TEXT_RENDERING
|
#if DEFER_TEXT_RENDERING
|
||||||
target = fDrawBuffer;
|
target = fDrawBuffer;
|
||||||
fDrawBuffer->initializeDrawStateAndClip(*fGpu);
|
fDrawBuffer->setClip(fGpu->getClip());
|
||||||
#else
|
#else
|
||||||
target = fGpu;
|
target = fGpu;
|
||||||
#endif
|
#endif
|
||||||
@ -1971,7 +1971,7 @@ GrDrawTarget* GrContext::prepareToDraw(const GrPaint& paint,
|
|||||||
break;
|
break;
|
||||||
case kBuffered_DrawCategory:
|
case kBuffered_DrawCategory:
|
||||||
target = fDrawBuffer;
|
target = fDrawBuffer;
|
||||||
fDrawBuffer->initializeDrawStateAndClip(*fGpu);
|
fDrawBuffer->setClip(fGpu->getClip());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
@ -1992,30 +1992,30 @@ GrPathRenderer* GrContext::getPathRenderer(const GrPath& path,
|
|||||||
|
|
||||||
void GrContext::setRenderTarget(GrRenderTarget* target) {
|
void GrContext::setRenderTarget(GrRenderTarget* target) {
|
||||||
ASSERT_OWNED_RESOURCE(target);
|
ASSERT_OWNED_RESOURCE(target);
|
||||||
if (fGpu->drawState()->getRenderTarget() != target) {
|
if (fDrawState->getRenderTarget() != target) {
|
||||||
this->flush(false);
|
this->flush(false);
|
||||||
fGpu->drawState()->setRenderTarget(target);
|
fDrawState->setRenderTarget(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GrRenderTarget* GrContext::getRenderTarget() {
|
GrRenderTarget* GrContext::getRenderTarget() {
|
||||||
return fGpu->drawState()->getRenderTarget();
|
return fDrawState->getRenderTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
const GrRenderTarget* GrContext::getRenderTarget() const {
|
const GrRenderTarget* GrContext::getRenderTarget() const {
|
||||||
return fGpu->getDrawState().getRenderTarget();
|
return fDrawState->getRenderTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
const GrMatrix& GrContext::getMatrix() const {
|
const GrMatrix& GrContext::getMatrix() const {
|
||||||
return fGpu->getDrawState().getViewMatrix();
|
return fDrawState->getViewMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrContext::setMatrix(const GrMatrix& m) {
|
void GrContext::setMatrix(const GrMatrix& m) {
|
||||||
fGpu->drawState()->setViewMatrix(m);
|
fDrawState->setViewMatrix(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrContext::concatMatrix(const GrMatrix& m) const {
|
void GrContext::concatMatrix(const GrMatrix& m) const {
|
||||||
fGpu->drawState()->preConcatViewMatrix(m);
|
fDrawState->preConcatViewMatrix(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline intptr_t setOrClear(intptr_t bits, int shift, intptr_t pred) {
|
static inline intptr_t setOrClear(intptr_t bits, int shift, intptr_t pred) {
|
||||||
@ -2045,6 +2045,9 @@ GrContext::GrContext(GrGpu* gpu) {
|
|||||||
fGpu->ref();
|
fGpu->ref();
|
||||||
fGpu->setContext(this);
|
fGpu->setContext(this);
|
||||||
|
|
||||||
|
fDrawState = new GrDrawState();
|
||||||
|
fGpu->setDrawState(fDrawState);
|
||||||
|
|
||||||
fPathRendererChain = NULL;
|
fPathRendererChain = NULL;
|
||||||
|
|
||||||
fTextureCache = new GrResourceCache(MAX_TEXTURE_CACHE_COUNT,
|
fTextureCache = new GrResourceCache(MAX_TEXTURE_CACHE_COUNT,
|
||||||
@ -2059,7 +2062,7 @@ GrContext::GrContext(GrGpu* gpu) {
|
|||||||
|
|
||||||
fAAFillRectIndexBuffer = NULL;
|
fAAFillRectIndexBuffer = NULL;
|
||||||
fAAStrokeRectIndexBuffer = NULL;
|
fAAStrokeRectIndexBuffer = NULL;
|
||||||
|
|
||||||
this->setupDrawBuffer();
|
this->setupDrawBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2088,17 +2091,15 @@ void GrContext::setupDrawBuffer() {
|
|||||||
fDrawBuffer->setQuadIndexBuffer(this->getQuadIndexBuffer());
|
fDrawBuffer->setQuadIndexBuffer(this->getQuadIndexBuffer());
|
||||||
#endif
|
#endif
|
||||||
fDrawBuffer->setAutoFlushTarget(fGpu);
|
fDrawBuffer->setAutoFlushTarget(fGpu);
|
||||||
|
fDrawBuffer->setDrawState(fDrawState);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrDrawTarget* GrContext::getTextTarget(const GrPaint& paint) {
|
GrDrawTarget* GrContext::getTextTarget(const GrPaint& paint) {
|
||||||
GrDrawTarget* target;
|
|
||||||
#if DEFER_TEXT_RENDERING
|
#if DEFER_TEXT_RENDERING
|
||||||
target = prepareToDraw(paint, kText_DrawCategory);
|
return prepareToDraw(paint, kText_DrawCategory);
|
||||||
#else
|
#else
|
||||||
target = prepareToDraw(paint, kUnbuffered_DrawCategory);
|
return prepareToDraw(paint, kUnbuffered_DrawCategory);
|
||||||
#endif
|
#endif
|
||||||
this->setPaint(paint, target);
|
|
||||||
return target;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {
|
const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "GrInOrderDrawBuffer.h"
|
#include "GrInOrderDrawBuffer.h"
|
||||||
#include "GrRenderTarget.h"
|
#include "GrRenderTarget.h"
|
||||||
#include "GrTexture.h"
|
#include "GrTexture.h"
|
||||||
@ -53,11 +52,6 @@ GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
|
|||||||
GrSafeUnref(fAutoFlushTarget);
|
GrSafeUnref(fAutoFlushTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrInOrderDrawBuffer::initializeDrawStateAndClip(const GrDrawTarget& target) {
|
|
||||||
this->copyDrawState(target);
|
|
||||||
this->setClip(target.getClip());
|
|
||||||
}
|
|
||||||
|
|
||||||
void GrInOrderDrawBuffer::setQuadIndexBuffer(const GrIndexBuffer* indexBuffer) {
|
void GrInOrderDrawBuffer::setQuadIndexBuffer(const GrIndexBuffer* indexBuffer) {
|
||||||
bool newIdxBuffer = fQuadIndexBuffer != indexBuffer;
|
bool newIdxBuffer = fQuadIndexBuffer != indexBuffer;
|
||||||
if (newIdxBuffer) {
|
if (newIdxBuffer) {
|
||||||
|
@ -52,13 +52,6 @@ public:
|
|||||||
|
|
||||||
virtual ~GrInOrderDrawBuffer();
|
virtual ~GrInOrderDrawBuffer();
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the draw state and clip from target to this draw buffer.
|
|
||||||
*
|
|
||||||
* @param target the target whose clip and state should be copied.
|
|
||||||
*/
|
|
||||||
void initializeDrawStateAndClip(const GrDrawTarget& target);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the buffer with an index buffer that can be used for quad rendering.
|
* Provides the buffer with an index buffer that can be used for quad rendering.
|
||||||
* The buffer may be able to batch consecutive drawRects if this is provided.
|
* The buffer may be able to batch consecutive drawRects if this is provided.
|
||||||
|
Loading…
Reference in New Issue
Block a user