aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/gpu/GrClipMaskManager.cpp127
-rw-r--r--src/gpu/GrClipMaskManager.h50
-rw-r--r--src/gpu/GrDrawTarget.cpp38
-rw-r--r--src/gpu/GrDrawTarget.h23
-rw-r--r--src/gpu/GrGpu.cpp40
-rw-r--r--src/gpu/GrGpu.h13
6 files changed, 150 insertions, 141 deletions
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index 743f191f24..8bd4fabac4 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -11,7 +11,6 @@
#include "GrAAHairLinePathRenderer.h"
#include "GrAARectRenderer.h"
#include "GrDrawTargetCaps.h"
-#include "GrGpu.h"
#include "GrPaint.h"
#include "GrPathRenderer.h"
#include "GrRenderTarget.h"
@@ -32,7 +31,7 @@ typedef SkClipStack::Element Element;
namespace {
// set up the draw state to enable the aa clipping mask. Besides setting up the
// stage matrix this also alters the vertex layout
-void setup_drawstate_aaclip(GrGpu* gpu,
+void setup_drawstate_aaclip(GrDrawTarget* gpu,
GrTexture* result,
const SkIRect &devBound) {
GrDrawState* drawState = gpu->drawState();
@@ -59,7 +58,7 @@ void setup_drawstate_aaclip(GrGpu* gpu,
}
bool path_needs_SW_renderer(GrContext* context,
- GrGpu* gpu,
+ GrDrawTarget* gpu,
const SkPath& origPath,
const SkStrokeRec& stroke,
bool doAA) {
@@ -97,7 +96,8 @@ bool GrClipMaskManager::useSWOnlyPath(const GrReducedClip::ElementList& elements
if (Element::kRect_Type != element->getType()) {
SkPath path;
element->asPath(&path);
- if (path_needs_SW_renderer(this->getContext(), fGpu, path, stroke, element->isAA())) {
+ if (path_needs_SW_renderer(this->getContext(), fClipTarget, path, stroke,
+ element->isAA())) {
return true;
}
}
@@ -110,7 +110,7 @@ bool GrClipMaskManager::installClipEffects(const GrReducedClip::ElementList& ele
const SkVector& clipToRTOffset,
const SkRect* drawBounds) {
- GrDrawState* drawState = fGpu->drawState();
+ GrDrawState* drawState = fClipTarget->drawState();
SkRect boundsInClipSpace;
if (drawBounds) {
boundsInClipSpace = *drawBounds;
@@ -188,10 +188,10 @@ bool GrClipMaskManager::installClipEffects(const GrReducedClip::ElementList& ele
}
if (fp) {
if (!setARE) {
- are->set(fGpu->drawState());
+ are->set(fClipTarget->drawState());
setARE = true;
}
- fGpu->drawState()->addCoverageProcessor(fp);
+ fClipTarget->drawState()->addCoverageProcessor(fp);
} else {
failed = true;
break;
@@ -223,7 +223,7 @@ bool GrClipMaskManager::setupClipping(const GrClipData* clipDataIn,
SkIRect clipSpaceIBounds;
bool requiresAA;
- GrDrawState* drawState = fGpu->drawState();
+ GrDrawState* drawState = fClipTarget->drawState();
const GrRenderTarget* rt = drawState->getRenderTarget();
// GrDrawTarget should have filtered this for us
@@ -302,8 +302,8 @@ bool GrClipMaskManager::setupClipping(const GrClipData* clipDataIn,
// clipSpace bounds. We determine the mask's position WRT to the render target here.
SkIRect rtSpaceMaskBounds = clipSpaceIBounds;
rtSpaceMaskBounds.offset(-clipDataIn->fOrigin);
- are->set(fGpu->drawState());
- setup_drawstate_aaclip(fGpu, result, rtSpaceMaskBounds);
+ are->set(fClipTarget->drawState());
+ setup_drawstate_aaclip(fClipTarget, result, rtSpaceMaskBounds);
this->setDrawStateStencil(ars);
return true;
}
@@ -384,7 +384,7 @@ void setup_boolean_blendcoeffs(GrDrawState* drawState, SkRegion::Op op) {
bool GrClipMaskManager::drawElement(GrTexture* target,
const SkClipStack::Element* element,
GrPathRenderer* pr) {
- GrDrawState* drawState = fGpu->drawState();
+ GrDrawState* drawState = fClipTarget->drawState();
drawState->setRenderTarget(target->asRenderTarget());
@@ -397,12 +397,12 @@ bool GrClipMaskManager::drawElement(GrTexture* target,
// TODO: Do rects directly to the accumulator using a aa-rect GrProcessor that covers
// the entire mask bounds and writes 0 outside the rect.
if (element->isAA()) {
- this->getContext()->getAARectRenderer()->fillAARect(fGpu,
+ this->getContext()->getAARectRenderer()->fillAARect(fClipTarget,
element->getRect(),
SkMatrix::I(),
element->getRect());
} else {
- fGpu->drawSimpleRect(element->getRect());
+ fClipTarget->drawSimpleRect(element->getRect());
}
return true;
default: {
@@ -417,12 +417,12 @@ bool GrClipMaskManager::drawElement(GrTexture* target,
GrPathRendererChain::DrawType type;
type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_DrawType :
GrPathRendererChain::kColor_DrawType;
- pr = this->getContext()->getPathRenderer(path, stroke, fGpu, false, type);
+ pr = this->getContext()->getPathRenderer(path, stroke, fClipTarget, false, type);
}
if (NULL == pr) {
return false;
}
- pr->drawPath(path, stroke, fGpu, element->isAA());
+ pr->drawPath(path, stroke, fClipTarget, element->isAA());
break;
}
}
@@ -432,7 +432,7 @@ bool GrClipMaskManager::drawElement(GrTexture* target,
bool GrClipMaskManager::canStencilAndDrawElement(GrTexture* target,
const SkClipStack::Element* element,
GrPathRenderer** pr) {
- GrDrawState* drawState = fGpu->drawState();
+ GrDrawState* drawState = fClipTarget->drawState();
drawState->setRenderTarget(target->asRenderTarget());
if (Element::kRect_Type == element->getType()) {
@@ -449,7 +449,7 @@ bool GrClipMaskManager::canStencilAndDrawElement(GrTexture* target,
GrPathRendererChain::DrawType type = element->isAA() ?
GrPathRendererChain::kStencilAndColorAntiAlias_DrawType :
GrPathRendererChain::kStencilAndColor_DrawType;
- *pr = this->getContext()->getPathRenderer(path, stroke, fGpu, false, type);
+ *pr = this->getContext()->getPathRenderer(path, stroke, fClipTarget, false, type);
return SkToBool(*pr);
}
}
@@ -460,7 +460,7 @@ void GrClipMaskManager::mergeMask(GrTexture* dstMask,
const SkIRect& dstBound,
const SkIRect& srcBound) {
GrDrawState::AutoViewMatrixRestore avmr;
- GrDrawState* drawState = fGpu->drawState();
+ GrDrawState* drawState = fClipTarget->drawState();
SkAssertResult(avmr.setIdentity(drawState));
GrDrawState::AutoRestoreEffects are(drawState);
@@ -477,7 +477,7 @@ void GrClipMaskManager::mergeMask(GrTexture* dstMask,
GrTextureDomain::MakeTexelDomain(srcMask, srcBound),
GrTextureDomain::kDecal_Mode,
GrTextureParams::kNone_FilterMode))->unref();
- fGpu->drawSimpleRect(SkRect::Make(dstBound));
+ fClipTarget->drawSimpleRect(SkRect::Make(dstBound));
}
GrTexture* GrClipMaskManager::createTempMask(int width, int height) {
@@ -487,7 +487,7 @@ GrTexture* GrClipMaskManager::createTempMask(int width, int height) {
desc.fHeight = height;
desc.fConfig = kAlpha_8_GrPixelConfig;
- return fGpu->getContext()->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch);
+ return this->getContext()->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch);
}
////////////////////////////////////////////////////////////////////////////////
@@ -560,25 +560,26 @@ GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID,
// Set the matrix so that rendered clip elements are transformed to mask space from clip space.
SkMatrix translate;
translate.setTranslate(clipToMaskOffset);
- GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRInit, &translate);
+ GrDrawTarget::AutoGeometryAndStatePush agasp(fClipTarget, GrDrawTarget::kReset_ASRInit,
+ &translate);
- GrDrawState* drawState = fGpu->drawState();
+ GrDrawState* drawState = fClipTarget->drawState();
// We're drawing a coverage mask and want coverage to be run through the blend function.
drawState->enableState(GrDrawState::kCoverageDrawing_StateBit);
// The scratch texture that we are drawing into can be substantially larger than the mask. Only
// clear the part that we care about.
- fGpu->clear(&maskSpaceIBounds,
- GrReducedClip::kAllIn_InitialState == initialState ? 0xffffffff : 0x00000000,
- true,
- result->asRenderTarget());
+ fClipTarget->clear(&maskSpaceIBounds,
+ GrReducedClip::kAllIn_InitialState == initialState ? 0xffffffff : 0x00000000,
+ true,
+ result->asRenderTarget());
// When we use the stencil in the below loop it is important to have this clip installed.
// The second pass that zeros the stencil buffer renders the rect maskSpaceIBounds so the first
// pass must not set values outside of this bounds or stencil values outside the rect won't be
// cleared.
- GrDrawTarget::AutoClipRestore acr(fGpu, maskSpaceIBounds);
+ GrDrawTarget::AutoClipRestore acr(fClipTarget, maskSpaceIBounds);
drawState->enableState(GrDrawState::kClip_StateBit);
SkAutoTUnref<GrTexture> temp;
@@ -617,7 +618,7 @@ GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID,
}
dst = temp;
// clear the temp target and set blend to replace
- fGpu->clear(&maskSpaceElementIBounds,
+ fClipTarget->clear(&maskSpaceElementIBounds,
invert ? 0xffffffff : 0x00000000,
true,
dst->asRenderTarget());
@@ -664,7 +665,7 @@ GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID,
0x0000,
0xffff);
drawState->setStencil(kDrawOutsideElement);
- fGpu->drawSimpleRect(clipSpaceIBounds);
+ fClipTarget->drawSimpleRect(clipSpaceIBounds);
drawState->disableStencil();
}
} else {
@@ -690,7 +691,7 @@ bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID,
SkASSERT(kNone_ClipMaskType == fCurrClipMaskType);
- GrDrawState* drawState = fGpu->drawState();
+ GrDrawState* drawState = fClipTarget->drawState();
SkASSERT(drawState->isClipState());
GrRenderTarget* rt = drawState->getRenderTarget();
@@ -712,15 +713,16 @@ bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID,
};
SkMatrix matrix;
matrix.setTranslate(translate);
- GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRInit, &matrix);
- drawState = fGpu->drawState();
+ GrDrawTarget::AutoGeometryAndStatePush agasp(fClipTarget, GrDrawTarget::kReset_ASRInit,
+ &matrix);
+ drawState = fClipTarget->drawState();
drawState->setRenderTarget(rt);
// We set the current clip to the bounds so that our recursive draws are scissored to them.
SkIRect stencilSpaceIBounds(clipSpaceIBounds);
stencilSpaceIBounds.offset(clipSpaceToStencilOffset);
- GrDrawTarget::AutoClipRestore acr(fGpu, stencilSpaceIBounds);
+ GrDrawTarget::AutoClipRestore acr(fClipTarget, stencilSpaceIBounds);
drawState->enableState(GrDrawState::kClip_StateBit);
#if !VISUALIZE_COMPLEX_CLIP
@@ -731,9 +733,9 @@ bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID,
SkASSERT((clipBit <= 16) && "Ganesh only handles 16b or smaller stencil buffers");
clipBit = (1 << (clipBit-1));
- fGpu->clearStencilClip(stencilSpaceIBounds,
- GrReducedClip::kAllIn_InitialState == initialState,
- rt);
+ fClipTarget->clearStencilClip(stencilSpaceIBounds,
+ GrReducedClip::kAllIn_InitialState == initialState,
+ rt);
// walk through each clip element and perform its set op
// with the existing clip.
@@ -741,7 +743,7 @@ bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID,
const Element* element = iter.get();
bool fillInverted = false;
// enabled at bottom of loop
- drawState->disableState(GrGpu::kModifyStencilClip_StateBit);
+ drawState->disableState(kModifyStencilClip_StateBit);
// if the target is MSAA then we want MSAA enabled when the clip is soft
if (rt->isMultisampled()) {
drawState->setState(GrDrawState::kHWAntialias_StateBit, element->isAA());
@@ -768,7 +770,7 @@ bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID,
}
pr = this->getContext()->getPathRenderer(clipPath,
stroke,
- fGpu,
+ fClipTarget,
false,
GrPathRendererChain::kStencilOnly_DrawType,
&stencilSupport);
@@ -805,14 +807,14 @@ bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID,
SET_RANDOM_COLOR
if (Element::kRect_Type == element->getType()) {
*drawState->stencil() = gDrawToStencil;
- fGpu->drawSimpleRect(element->getRect());
+ fClipTarget->drawSimpleRect(element->getRect());
} else {
if (!clipPath.isEmpty()) {
if (canRenderDirectToStencil) {
*drawState->stencil() = gDrawToStencil;
- pr->drawPath(clipPath, stroke, fGpu, false);
+ pr->drawPath(clipPath, stroke, fClipTarget, false);
} else {
- pr->stencilPath(clipPath, stroke, fGpu);
+ pr->stencilPath(clipPath, stroke, fClipTarget);
}
}
}
@@ -820,22 +822,22 @@ bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID,
// now we modify the clip bit by rendering either the clip
// element directly or a bounding rect of the entire clip.
- drawState->enableState(GrGpu::kModifyStencilClip_StateBit);
+ drawState->enableState(kModifyStencilClip_StateBit);
for (int p = 0; p < passes; ++p) {
*drawState->stencil() = stencilSettings[p];
if (canDrawDirectToClip) {
if (Element::kRect_Type == element->getType()) {
SET_RANDOM_COLOR
- fGpu->drawSimpleRect(element->getRect());
+ fClipTarget->drawSimpleRect(element->getRect());
} else {
SET_RANDOM_COLOR
- pr->drawPath(clipPath, stroke, fGpu, false);
+ pr->drawPath(clipPath, stroke, fClipTarget, false);
}
} else {
SET_RANDOM_COLOR
// The view matrix is setup to do clip space -> stencil space translation, so
// draw rect in clip space.
- fGpu->drawSimpleRect(SkRect::Make(clipSpaceIBounds));
+ fClipTarget->drawSimpleRect(SkRect::Make(clipSpaceIBounds));
}
}
}
@@ -905,7 +907,7 @@ void GrClipMaskManager::setDrawStateStencil(GrDrawState::AutoRestoreStencil* ars
// from the stack var to the gpu. We could make this class hold a ptr to
// GrGpu's fStencilSettings and eliminate the stack copy here.
- const GrDrawState& drawState = fGpu->getDrawState();
+ const GrDrawState& drawState = fClipTarget->getDrawState();
// use stencil for clipping if clipping is enabled and the clip
// has been written into the stencil.
@@ -913,10 +915,8 @@ void GrClipMaskManager::setDrawStateStencil(GrDrawState::AutoRestoreStencil* ars
if (this->isClipInStencil() && drawState.isClipState()) {
clipMode = GrClipMaskManager::kRespectClip_StencilClipMode;
// We can't be modifying the clip and respecting it at the same time.
- SkASSERT(!drawState.isStateFlagEnabled(
- GrGpu::kModifyStencilClip_StateBit));
- } else if (drawState.isStateFlagEnabled(
- GrGpu::kModifyStencilClip_StateBit)) {
+ SkASSERT(!drawState.isStateFlagEnabled(kModifyStencilClip_StateBit));
+ } else if (drawState.isStateFlagEnabled(kModifyStencilClip_StateBit)) {
clipMode = GrClipMaskManager::kModifyClip_StencilClipMode;
} else {
clipMode = GrClipMaskManager::kIgnoreClip_StencilClipMode;
@@ -942,11 +942,11 @@ void GrClipMaskManager::setDrawStateStencil(GrDrawState::AutoRestoreStencil* ars
stencilBits = stencilBuffer->bits();
}
- SkASSERT(fGpu->caps()->stencilWrapOpsSupport() || !settings.usesWrapOp());
- SkASSERT(fGpu->caps()->twoSidedStencilSupport() || !settings.isTwoSided());
+ SkASSERT(fClipTarget->caps()->stencilWrapOpsSupport() || !settings.usesWrapOp());
+ SkASSERT(fClipTarget->caps()->twoSidedStencilSupport() || !settings.isTwoSided());
this->adjustStencilParams(&settings, clipMode, stencilBits);
- ars->set(fGpu->drawState());
- fGpu->drawState()->setStencil(settings);
+ ars->set(fClipTarget->drawState());
+ fClipTarget->drawState()->setStencil(settings);
}
void GrClipMaskManager::adjustStencilParams(GrStencilSettings* settings,
@@ -964,7 +964,7 @@ void GrClipMaskManager::adjustStencilParams(GrStencilSettings* settings,
unsigned int userBits = clipBit - 1;
GrStencilSettings::Face face = GrStencilSettings::kFront_Face;
- bool twoSided = fGpu->caps()->twoSidedStencilSupport();
+ bool twoSided = fClipTarget->caps()->twoSidedStencilSupport();
bool finished = false;
while (!finished) {
@@ -1109,21 +1109,19 @@ void GrClipMaskManager::purgeResources() {
fAACache.purgeResources();
}
-void GrClipMaskManager::setGpu(GrGpu* gpu) {
- fGpu = gpu;
- fAACache.setContext(gpu->getContext());
+void GrClipMaskManager::setClipTarget(GrClipTarget* clipTarget) {
+ fClipTarget = clipTarget;
+ fAACache.setContext(clipTarget->getContext());
}
void GrClipMaskManager::adjustPathStencilParams(GrStencilSettings* settings) {
- const GrDrawState& drawState = fGpu->getDrawState();
+ const GrDrawState& drawState = fClipTarget->getDrawState();
GrClipMaskManager::StencilClipMode clipMode;
if (this->isClipInStencil() && drawState.isClipState()) {
clipMode = GrClipMaskManager::kRespectClip_StencilClipMode;
// We can't be modifying the clip and respecting it at the same time.
- SkASSERT(!drawState.isStateFlagEnabled(
- GrGpu::kModifyStencilClip_StateBit));
- } else if (drawState.isStateFlagEnabled(
- GrGpu::kModifyStencilClip_StateBit)) {
+ SkASSERT(!drawState.isStateFlagEnabled(kModifyStencilClip_StateBit));
+ } else if (drawState.isStateFlagEnabled(kModifyStencilClip_StateBit)) {
clipMode = GrClipMaskManager::kModifyClip_StencilClipMode;
} else {
clipMode = GrClipMaskManager::kIgnoreClip_StencilClipMode;
@@ -1131,8 +1129,7 @@ void GrClipMaskManager::adjustPathStencilParams(GrStencilSettings* settings) {
// TODO: dynamically attach a stencil buffer
int stencilBits = 0;
- GrStencilBuffer* stencilBuffer =
- drawState.getRenderTarget()->getStencilBuffer();
+ GrStencilBuffer* stencilBuffer = drawState.getRenderTarget()->getStencilBuffer();
if (stencilBuffer) {
stencilBits = stencilBuffer->bits();
this->adjustStencilParams(settings, clipMode, stencilBits);
diff --git a/src/gpu/GrClipMaskManager.h b/src/gpu/GrClipMaskManager.h
index fe1ff0efde..e4d7223c7e 100644
--- a/src/gpu/GrClipMaskManager.h
+++ b/src/gpu/GrClipMaskManager.h
@@ -22,7 +22,7 @@
#include "SkTLList.h"
#include "SkTypes.h"
-class GrGpu;
+class GrClipTarget;
class GrPathRenderer;
class GrPathRendererChain;
class GrTexture;
@@ -39,8 +39,8 @@ class SkPath;
class GrClipMaskManager : SkNoncopyable {
public:
GrClipMaskManager()
- : fGpu(NULL)
- , fCurrClipMaskType(kNone_ClipMaskType) {
+ : fCurrClipMaskType(kNone_ClipMaskType)
+ , fClipTarget(NULL) {
}
// The state of the scissor is controlled by the clip manager, no one else should set
@@ -64,7 +64,7 @@ public:
const SkRect* devBounds,
GrDrawState::AutoRestoreEffects*,
GrDrawState::AutoRestoreStencil*,
- ScissorState* scissorState);
+ ScissorState*);
/**
* Purge resources to free up memory. TODO: This class shouldn't hold any long lived refs
@@ -89,10 +89,19 @@ public:
return fAACache.getContext();
}
- void setGpu(GrGpu* gpu);
+ void setClipTarget(GrClipTarget*);
+
+ void adjustPathStencilParams(GrStencilSettings*);
- void adjustPathStencilParams(GrStencilSettings* settings);
private:
+ enum PrivateDrawStateStateBits {
+ kFirstBit = (GrDrawState::kLastPublicStateBit << 1),
+
+ kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify
+ // stencil bits used for
+ // clipping.
+ };
+
/**
* Informs the helper function adjustStencilParams() about how the stencil
* buffer clip is being used.
@@ -107,21 +116,6 @@ private:
kIgnoreClip_StencilClipMode,
};
- GrGpu* fGpu;
-
- /**
- * We may represent the clip as a mask in the stencil buffer or as an alpha
- * texture. It may be neither because the scissor rect suffices or we
- * haven't yet examined the clip.
- */
- enum ClipMaskType {
- kNone_ClipMaskType,
- kStencil_ClipMaskType,
- kAlpha_ClipMaskType,
- } fCurrClipMaskType;
-
- GrClipMaskCache fAACache; // cache for the AA path
-
// Attempts to install a series of coverage effects to implement the clip. Return indicates
// whether the element list was successfully converted to effects.
bool installClipEffects(const GrReducedClip::ElementList&,
@@ -196,6 +190,20 @@ private:
StencilClipMode mode,
int stencilBitCnt);
+ /**
+ * We may represent the clip as a mask in the stencil buffer or as an alpha
+ * texture. It may be neither because the scissor rect suffices or we
+ * haven't yet examined the clip.
+ */
+ enum ClipMaskType {
+ kNone_ClipMaskType,
+ kStencil_ClipMaskType,
+ kAlpha_ClipMaskType,
+ } fCurrClipMaskType;
+
+ GrClipMaskCache fAACache; // cache for the AA path
+ GrClipTarget* fClipTarget;
+
typedef SkNoncopyable INHERITED;
};
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 0d3a2390d5..a87e712d33 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -93,7 +93,6 @@ GrDrawTarget::GrDrawTarget(GrContext* context)
, fContext(context)
, fGpuTraceMarkerCount(0) {
SkASSERT(context);
-
fDrawState = &fDefaultDrawState;
// We assume that fDrawState always owns a ref to the object it points at.
fDefaultDrawState.ref();
@@ -725,6 +724,43 @@ void GrDrawTarget::onDrawRect(const SkRect& rect,
void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) {
}
+static const GrStencilSettings& winding_path_stencil_settings() {
+ GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
+ kIncClamp_StencilOp,
+ kIncClamp_StencilOp,
+ kAlwaysIfInClip_StencilFunc,
+ 0xFFFF, 0xFFFF, 0xFFFF);
+ return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
+}
+
+static const GrStencilSettings& even_odd_path_stencil_settings() {
+ GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
+ kInvert_StencilOp,
+ kInvert_StencilOp,
+ kAlwaysIfInClip_StencilFunc,
+ 0xFFFF, 0xFFFF, 0xFFFF);
+ return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
+}
+
+void GrDrawTarget::getPathStencilSettingsForFillType(SkPath::FillType fill,
+ GrStencilSettings* outStencilSettings) {
+
+ switch (fill) {
+ default:
+ SkFAIL("Unexpected path fill.");
+ /* fallthrough */;
+ case SkPath::kWinding_FillType:
+ case SkPath::kInverseWinding_FillType:
+ *outStencilSettings = winding_path_stencil_settings();
+ break;
+ case SkPath::kEvenOdd_FillType:
+ case SkPath::kInverseEvenOdd_FillType:
+ *outStencilSettings = even_odd_path_stencil_settings();
+ break;
+ }
+ this->getClipMaskManager()->adjustPathStencilParams(outStencilSettings);
+}
+
////////////////////////////////////////////////////////////////////////////////
GrDrawTarget::AutoStateRestore::AutoStateRestore() {
diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h
index 3efa6bf357..1f26166f6e 100644
--- a/src/gpu/GrDrawTarget.h
+++ b/src/gpu/GrDrawTarget.h
@@ -505,6 +505,9 @@ public:
const GrDeviceCoordTexture* dstCopy) {
this->onDrawPaths(pathRange, indices, count, transforms, transformsType, fill, dstCopy);
}
+
+ void getPathStencilSettingsForFillType(SkPath::FillType, GrStencilSettings*);
+
////////////////////////////////////////////////////////////////////////////
/**
@@ -923,6 +926,7 @@ private:
// Check to see if this set of draw commands has been sent out
virtual bool isIssued(uint32_t drawID) { return true; }
+ virtual GrClipMaskManager* getClipMaskManager() = 0;
enum {
kPreallocGeoSrcStateStackCnt = 4,
@@ -941,9 +945,21 @@ private:
typedef SkRefCnt INHERITED;
};
+/*
+ * This class is JUST for clip mask manager. Everyone else should just use draw target above.
+ */
class GrClipTarget : public GrDrawTarget {
public:
- GrClipTarget(GrContext* context) : INHERITED(context) {}
+ GrClipTarget(GrContext* context) : INHERITED(context) {
+ fClipMaskManager.setClipTarget(this);
+ }
+
+ /* Clip mask manager needs access to the context.
+ * TODO we only need a very small subset of context in the CMM.
+ */
+ GrContext* getContext() { return INHERITED::getContext(); }
+ const GrContext* getContext() const { return INHERITED::getContext(); }
+
/**
* Clip Mask Manager(and no one else) needs to clear private stencil bits.
* ClipTarget subclass sets clip bit in the stencil buffer. The subclass
@@ -952,7 +968,12 @@ public:
*/
virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0;
+protected:
+ GrClipMaskManager fClipMaskManager;
+
private:
+ GrClipMaskManager* getClipMaskManager() { return &fClipMaskManager; }
+
typedef GrDrawTarget INHERITED;
};
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index e767d07a82..4b1c35ad4e 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -36,9 +36,6 @@ GrGpu::GrGpu(GrContext* context)
, fVertexPoolUseCnt(0)
, fIndexPoolUseCnt(0)
, fQuadIndexBuffer(NULL) {
-
- fClipMaskManager.setGpu(this);
-
fGeomPoolStateStack.push_back();
#ifdef SK_DEBUG
GeometryPoolState& poolState = fGeomPoolStateStack.back();
@@ -250,43 +247,6 @@ void GrGpu::resolveRenderTarget(GrRenderTarget* target) {
this->onResolveRenderTarget(target);
}
-static const GrStencilSettings& winding_path_stencil_settings() {
- GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
- kIncClamp_StencilOp,
- kIncClamp_StencilOp,
- kAlwaysIfInClip_StencilFunc,
- 0xFFFF, 0xFFFF, 0xFFFF);
- return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
-}
-
-static const GrStencilSettings& even_odd_path_stencil_settings() {
- GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
- kInvert_StencilOp,
- kInvert_StencilOp,
- kAlwaysIfInClip_StencilFunc,
- 0xFFFF, 0xFFFF, 0xFFFF);
- return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
-}
-
-void GrGpu::getPathStencilSettingsForFillType(SkPath::FillType fill, GrStencilSettings* outStencilSettings) {
-
- switch (fill) {
- default:
- SkFAIL("Unexpected path fill.");
- /* fallthrough */;
- case SkPath::kWinding_FillType:
- case SkPath::kInverseWinding_FillType:
- *outStencilSettings = winding_path_stencil_settings();
- break;
- case SkPath::kEvenOdd_FillType:
- case SkPath::kInverseEvenOdd_FillType:
- *outStencilSettings = even_odd_path_stencil_settings();
- break;
- }
- fClipMaskManager.adjustPathStencilParams(outStencilSettings);
-}
-
-
////////////////////////////////////////////////////////////////////////////////
static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1;
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 8fa81d62cb..62abd825d3 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -9,7 +9,6 @@
#define GrGpu_DEFINED
#include "GrDrawTarget.h"
-#include "GrClipMaskManager.h"
#include "GrPathRendering.h"
#include "GrProgramDesc.h"
#include "SkPath.h"
@@ -299,16 +298,6 @@ public:
return fResetTimestamp;
}
- enum PrivateDrawStateStateBits {
- kFirstBit = (GrDrawState::kLastPublicStateBit << 1),
-
- kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify
- // stencil bits used for
- // clipping.
- };
-
- void getPathStencilSettingsForFillType(SkPath::FillType fill, GrStencilSettings* outStencilSettings);
-
enum DrawType {
kDrawPoints_DrawType,
kDrawLines_DrawType,
@@ -365,8 +354,6 @@ protected:
unsigned int* ref,
unsigned int* mask);
- GrClipMaskManager fClipMaskManager;
-
GrContext::GPUStats fGPUStats;
struct GeometryPoolState {