зеркало из https://github.com/mozilla/moz-skia.git
Move setPaint from GrContext to GrDrawState.
R=robertphillips@google.com Review URL: https://codereview.appspot.com/6624045 git-svn-id: http://skia.googlecode.com/svn/trunk@5823 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
dda28c9bde
Коммит
af84e748ce
|
@ -63,6 +63,7 @@
|
|||
'<(skia_src_path)/gpu/GrCustomStage.cpp',
|
||||
'<(skia_src_path)/gpu/GrDefaultPathRenderer.cpp',
|
||||
'<(skia_src_path)/gpu/GrDefaultPathRenderer.h',
|
||||
'<(skia_src_path)/gpu/GrDrawState.cpp',
|
||||
'<(skia_src_path)/gpu/GrDrawState.h',
|
||||
'<(skia_src_path)/gpu/GrDrawTarget.cpp',
|
||||
'<(skia_src_path)/gpu/GrDrawTarget.h',
|
||||
|
|
|
@ -841,8 +841,6 @@ private:
|
|||
|
||||
void flushDrawBuffer();
|
||||
|
||||
void setPaint(const GrPaint& paint);
|
||||
|
||||
/// Sets the paint and returns the target to draw into. The paint can be NULL in which case the
|
||||
/// draw state is left unmodified.
|
||||
GrDrawTarget* prepareToDraw(const GrPaint*, BufferedDraw);
|
||||
|
|
|
@ -1588,59 +1588,20 @@ void GrContext::writeRenderTargetPixels(GrRenderTarget* target,
|
|||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void GrContext::setPaint(const GrPaint& paint) {
|
||||
GrAssert(fDrawState->stagesDisabled());
|
||||
|
||||
for (int i = 0; i < GrPaint::kMaxTextures; ++i) {
|
||||
int s = i + GrPaint::kFirstTextureStage;
|
||||
if (paint.isTextureStageEnabled(i)) {
|
||||
*fDrawState->sampler(s) = paint.getTextureSampler(i);
|
||||
}
|
||||
}
|
||||
|
||||
fDrawState->setFirstCoverageStage(GrPaint::kFirstMaskStage);
|
||||
|
||||
for (int i = 0; i < GrPaint::kMaxMasks; ++i) {
|
||||
int s = i + GrPaint::kFirstMaskStage;
|
||||
if (paint.isMaskStageEnabled(i)) {
|
||||
*fDrawState->sampler(s) = paint.getMaskSampler(i);
|
||||
}
|
||||
}
|
||||
|
||||
// disable all stages not accessible via the paint
|
||||
for (int s = GrPaint::kTotalStages; s < GrDrawState::kNumStages; ++s) {
|
||||
fDrawState->disableStage(s);
|
||||
}
|
||||
|
||||
fDrawState->setColor(paint.fColor);
|
||||
|
||||
fDrawState->setState(GrDrawState::kDither_StateBit, paint.fDither);
|
||||
fDrawState->setState(GrDrawState::kHWAntialias_StateBit, paint.fAntiAlias);
|
||||
|
||||
if (paint.fColorMatrixEnabled) {
|
||||
fDrawState->enableState(GrDrawState::kColorMatrix_StateBit);
|
||||
fDrawState->setColorMatrix(paint.fColorMatrix);
|
||||
} else {
|
||||
fDrawState->disableState(GrDrawState::kColorMatrix_StateBit);
|
||||
}
|
||||
fDrawState->setBlendFunc(paint.fSrcBlendCoeff, paint.fDstBlendCoeff);
|
||||
fDrawState->setColorFilter(paint.fColorFilterColor, paint.fColorFilterXfermode);
|
||||
fDrawState->setCoverage(paint.fCoverage);
|
||||
#if GR_DEBUG_PARTIAL_COVERAGE_CHECK
|
||||
if ((paint.hasMask() || 0xff != paint.fCoverage) &&
|
||||
!fGpu->canApplyCoverage()) {
|
||||
GrPrintf("Partial pixel coverage will be incorrectly blended.\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, BufferedDraw buffered) {
|
||||
if (kNo_BufferedDraw == buffered && kYes_BufferedDraw == fLastDrawWasBuffered) {
|
||||
this->flushDrawBuffer();
|
||||
fLastDrawWasBuffered = kNo_BufferedDraw;
|
||||
}
|
||||
if (NULL != paint) {
|
||||
this->setPaint(*paint);
|
||||
GrAssert(fDrawState->stagesDisabled());
|
||||
fDrawState->setFromPaint(*paint);
|
||||
#if GR_DEBUG_PARTIAL_COVERAGE_CHECK
|
||||
if ((paint->hasMask() || 0xff != paint->fCoverage) &&
|
||||
!fGpu->canApplyCoverage()) {
|
||||
GrPrintf("Partial pixel coverage will be incorrectly blended.\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (kYes_BufferedDraw == buffered) {
|
||||
fDrawBuffer->setClip(fGpu->getClip());
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "GrDrawState.h"
|
||||
|
||||
#include "GrPaint.h"
|
||||
|
||||
void GrDrawState::setFromPaint(const GrPaint& paint) {
|
||||
for (int i = 0; i < GrPaint::kMaxTextures; ++i) {
|
||||
int s = i + GrPaint::kFirstTextureStage;
|
||||
if (paint.isTextureStageEnabled(i)) {
|
||||
*this->sampler(s) = paint.getTextureSampler(i);
|
||||
}
|
||||
}
|
||||
|
||||
this->setFirstCoverageStage(GrPaint::kFirstMaskStage);
|
||||
|
||||
for (int i = 0; i < GrPaint::kMaxMasks; ++i) {
|
||||
int s = i + GrPaint::kFirstMaskStage;
|
||||
if (paint.isMaskStageEnabled(i)) {
|
||||
*this->sampler(s) = paint.getMaskSampler(i);
|
||||
}
|
||||
}
|
||||
|
||||
// disable all stages not accessible via the paint
|
||||
for (int s = GrPaint::kTotalStages; s < GrDrawState::kNumStages; ++s) {
|
||||
this->disableStage(s);
|
||||
}
|
||||
|
||||
this->setColor(paint.fColor);
|
||||
|
||||
this->setState(GrDrawState::kDither_StateBit, paint.fDither);
|
||||
this->setState(GrDrawState::kHWAntialias_StateBit, paint.fAntiAlias);
|
||||
|
||||
if (paint.fColorMatrixEnabled) {
|
||||
this->enableState(GrDrawState::kColorMatrix_StateBit);
|
||||
this->setColorMatrix(paint.fColorMatrix);
|
||||
} else {
|
||||
this->disableState(GrDrawState::kColorMatrix_StateBit);
|
||||
}
|
||||
this->setBlendFunc(paint.fSrcBlendCoeff, paint.fDstBlendCoeff);
|
||||
this->setColorFilter(paint.fColorFilterColor, paint.fColorFilterXfermode);
|
||||
this->setCoverage(paint.fCoverage);
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "SkXfermode.h"
|
||||
|
||||
class GrPaint;
|
||||
|
||||
class GrDrawState : public GrRefCnt {
|
||||
public:
|
||||
|
@ -89,7 +90,15 @@ public:
|
|||
fColorFilterMode = SkXfermode::kDst_Mode;
|
||||
fColorFilterColor = 0x0;
|
||||
fDrawFace = kBoth_DrawFace;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the GrDrawState based on a GrPaint. Note that GrDrawState
|
||||
* encompases more than GrPaint. Aspects of GrDrawState that have no
|
||||
* GrPaint equivalents are not modified. GrPaint has fewer stages than
|
||||
* GrDrawState. The extra GrDrawState stages are disabled.
|
||||
*/
|
||||
void setFromPaint(const GrPaint& paint);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// @name Color
|
||||
|
|
Загрузка…
Ссылка в новой задаче