Merge GrClipMaskManager into GrClipStackClip

TBR=bsalomon@google.com
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2196393007

Review-Url: https://codereview.chromium.org/2196393007
This commit is contained in:
csmartdalton 2016-08-05 22:32:12 -07:00 committed by Commit bot
parent 4c1abdcd21
commit c6f411e72b
14 changed files with 119 additions and 175 deletions

View File

@ -84,8 +84,8 @@
'<(skia_src_path)/gpu/GrBufferAllocPool.h',
'<(skia_src_path)/gpu/GrCaps.cpp',
'<(skia_src_path)/gpu/GrClip.cpp',
'<(skia_src_path)/gpu/GrClipMaskManager.h',
'<(skia_src_path)/gpu/GrClipMaskManager.cpp',
'<(skia_src_path)/gpu/GrClipStackClip.h',
'<(skia_src_path)/gpu/GrClipStackClip.cpp',
'<(skia_src_path)/gpu/GrColorSpaceXform.cpp',
'<(skia_src_path)/gpu/GrContext.cpp',
'<(skia_src_path)/gpu/GrContextPriv.h',

View File

@ -10,7 +10,6 @@
#include "GrFragmentProcessor.h"
#include "GrTypesPriv.h"
#include "SkClipStack.h"
class GrDrawContext;
@ -270,37 +269,4 @@ private:
bool fHasStencilClip;
};
/**
* GrClipStackClip can apply a generic SkClipStack to the draw state. It may generate clip masks or
* write to the stencil buffer during apply().
*/
class GrClipStackClip final : public GrClip {
public:
GrClipStackClip(const SkClipStack* stack = nullptr, const SkIPoint* origin = nullptr) {
this->reset(stack, origin);
}
void reset(const SkClipStack* stack = nullptr, const SkIPoint* origin = nullptr) {
fOrigin = origin ? *origin : SkIPoint::Make(0, 0);
fStack.reset(SkSafeRef(stack));
}
const SkIPoint& origin() const { return fOrigin; }
const SkClipStack* clipStack() const { return fStack; }
bool quickContains(const SkRect&) const final;
void getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects) const final;
bool apply(GrContext*,
GrDrawContext*,
const SkRect* devBounds,
bool useHWAA,
bool hasUserStencilSettings,
GrAppliedClip* out) const final;
private:
SkIPoint fOrigin;
SkAutoTUnref<const SkClipStack> fStack;
};
#endif

View File

@ -423,10 +423,11 @@ private:
GrAuditTrail fAuditTrail;
// TODO: have the CMM use drawContexts and rm this friending
friend class GrClipMaskManager; // the CMM is friended just so it can call 'drawingManager'
friend class GrDrawingManager; // for access to drawingManager for ProgramUnitTest
// TODO: have the GrClipStackClip use drawContexts and rm this friending
friend class GrClipStackClip; // for access to drawingManager
friend class GrDrawingManager; // for access to drawingManager for ProgramUnitTest
friend class GrContextPriv;
GrDrawingManager* drawingManager() { return fDrawingManager; }
GrContext(); // init must be called after the constructor.

View File

@ -314,7 +314,6 @@ private:
friend class GrDrawContextPriv;
friend class GrTestTarget; // for access to getDrawTarget
friend class GrSWMaskHelper; // for access to drawBatch
friend class GrClipMaskManager; // for access to drawBatch
// All the path renderers currently make their own batches
friend class GrSoftwarePathRenderer; // for access to drawBatch

View File

@ -17,6 +17,7 @@
#include "SkGrPriv.h"
#include "SkMaskFilter.h"
#include "SkPaint.h"
#include "SkTLazy.h"
static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& rect) {
return clipBounds.isEmpty() || rect.isEmpty() || !SkIRect::Intersects(clipBounds, rect);

View File

@ -7,7 +7,6 @@
#include "GrClip.h"
#include "GrClipMaskManager.h"
#include "GrDrawContext.h"
void GrNoClip::getConservativeBounds(int width, int height, SkIRect* devResult,
@ -70,36 +69,3 @@ bool GrFixedClip::apply(GrContext*,
out->makeStencil(fHasStencilClip, fDeviceBounds);
return true;
}
bool GrClipStackClip::quickContains(const SkRect& rect) const {
if (!fStack) {
return true;
}
return fStack->quickContains(rect.makeOffset(SkIntToScalar(fOrigin.x()),
SkIntToScalar(fOrigin.y())));
}
void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects) const {
if (!fStack) {
devResult->setXYWH(0, 0, width, height);
if (isIntersectionOfRects) {
*isIntersectionOfRects = true;
}
return;
}
SkRect devBounds;
fStack->getConservativeBounds(-fOrigin.x(), -fOrigin.y(), width, height, &devBounds,
isIntersectionOfRects);
devBounds.roundOut(devResult);
}
bool GrClipStackClip::apply(GrContext* context,
GrDrawContext* drawContext,
const SkRect* devBounds,
bool useHWAA,
bool hasUserStencilSettings,
GrAppliedClip* out) const {
return GrClipMaskManager::SetupClipping(context, drawContext, *this, devBounds,
useHWAA, hasUserStencilSettings, out);
}

View File

@ -1,27 +1,18 @@
/*
* Copyright 2012 Google Inc.
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrClipMaskManager.h"
#include "GrCaps.h"
#include "GrClipStackClip.h"
#include "GrDrawingManager.h"
#include "GrDrawContextPriv.h"
#include "GrGpuResourcePriv.h"
#include "GrPaint.h"
#include "GrPathRenderer.h"
#include "GrRenderTarget.h"
#include "GrRenderTargetPriv.h"
#include "GrResourceProvider.h"
#include "GrStencilAttachment.h"
#include "GrSWMaskHelper.h"
#include "SkRasterClip.h"
#include "SkTLazy.h"
#include "batches/GrRectBatchFactory.h"
#include "effects/GrConvexPolyEffect.h"
#include "effects/GrPorterDuffXferProcessor.h"
#include "effects/GrRRectEffect.h"
#include "effects/GrTextureDomain.h"
@ -30,6 +21,29 @@ typedef GrReducedClip::InitialState InitialState;
static const int kMaxAnalyticElements = 4;
bool GrClipStackClip::quickContains(const SkRect& rect) const {
if (!fStack) {
return true;
}
return fStack->quickContains(rect.makeOffset(SkIntToScalar(fOrigin.x()),
SkIntToScalar(fOrigin.y())));
}
void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects) const {
if (!fStack) {
devResult->setXYWH(0, 0, width, height);
if (isIntersectionOfRects) {
*isIntersectionOfRects = true;
}
return;
}
SkRect devBounds;
fStack->getConservativeBounds(-fOrigin.x(), -fOrigin.y(), width, height, &devBounds,
isIntersectionOfRects);
devBounds.roundOut(devResult);
}
////////////////////////////////////////////////////////////////////////////////
// set up the draw state to enable the aa clipping mask. Besides setting up the
// stage matrix this also alters the vertex layout
@ -56,13 +70,13 @@ static sk_sp<GrFragmentProcessor> create_fp_for_mask(GrTexture* result,
// Does the path in 'element' require SW rendering? If so, return true (and,
// optionally, set 'prOut' to NULL. If not, return false (and, optionally, set
// 'prOut' to the non-SW path renderer that will do the job).
bool GrClipMaskManager::PathNeedsSWRenderer(GrContext* context,
bool hasUserStencilSettings,
const GrDrawContext* drawContext,
const SkMatrix& viewMatrix,
const Element* element,
GrPathRenderer** prOut,
bool needsStencil) {
bool GrClipStackClip::PathNeedsSWRenderer(GrContext* context,
bool hasUserStencilSettings,
const GrDrawContext* drawContext,
const SkMatrix& viewMatrix,
const Element* element,
GrPathRenderer** prOut,
bool needsStencil) {
if (Element::kRect_Type == element->getType()) {
// rects can always be drawn directly w/o using the software path
// TODO: skip rrects once we're drawing them directly.
@ -116,11 +130,11 @@ bool GrClipMaskManager::PathNeedsSWRenderer(GrContext* context,
* will be used on any element. If so, it returns true to indicate that the
* entire clip should be rendered in SW and then uploaded en masse to the gpu.
*/
bool GrClipMaskManager::UseSWOnlyPath(GrContext* context,
bool hasUserStencilSettings,
const GrDrawContext* drawContext,
const SkVector& clipToMaskOffset,
const GrReducedClip::ElementList& elements) {
bool GrClipStackClip::UseSWOnlyPath(GrContext* context,
bool hasUserStencilSettings,
const GrDrawContext* drawContext,
const SkVector& clipToMaskOffset,
const GrReducedClip::ElementList& elements) {
// TODO: generalize this function so that when
// a clip gets complex enough it can just be done in SW regardless
// of whether it would invoke the GrSoftwarePathRenderer.
@ -227,14 +241,13 @@ static bool get_analytic_clip_processor(const GrReducedClip::ElementList& elemen
////////////////////////////////////////////////////////////////////////////////
// sort out what kind of clip mask needs to be created: alpha, stencil,
// scissor, or entirely software
bool GrClipMaskManager::SetupClipping(GrContext* context,
GrDrawContext* drawContext,
const GrClipStackClip& clip,
const SkRect* origDevBounds,
bool useHWAA,
bool hasUserStencilSettings,
GrAppliedClip* out) {
if (!clip.clipStack() || clip.clipStack()->isWideOpen()) {
bool GrClipStackClip::apply(GrContext* context,
GrDrawContext* drawContext,
const SkRect* origDevBounds,
bool useHWAA,
bool hasUserStencilSettings,
GrAppliedClip* out) const {
if (!fStack || fStack->isWideOpen()) {
return true;
}
@ -243,15 +256,15 @@ bool GrClipMaskManager::SetupClipping(GrContext* context,
return false;
}
const SkScalar clipX = SkIntToScalar(clip.origin().x()),
clipY = SkIntToScalar(clip.origin().y());
const SkScalar clipX = SkIntToScalar(fOrigin.x()),
clipY = SkIntToScalar(fOrigin.y());
GrReducedClip::ElementList elements;
int32_t genID = 0;
SkIRect clipSpaceIBounds;
bool requiresAA = false;
InitialState initialState = GrReducedClip::ReduceClipStack(*clip.clipStack(),
InitialState initialState = GrReducedClip::ReduceClipStack(*fStack,
devBounds.makeOffset(clipX, clipY),
&elements,
&genID,
@ -262,7 +275,7 @@ bool GrClipMaskManager::SetupClipping(GrContext* context,
return false;
} else {
SkIRect scissorSpaceIBounds(clipSpaceIBounds);
scissorSpaceIBounds.offset(-clip.origin());
scissorSpaceIBounds.offset(-fOrigin);
if (!GrClip::IsInsideClip(scissorSpaceIBounds, devBounds)) {
out->makeScissored(scissorSpaceIBounds);
}
@ -293,7 +306,7 @@ bool GrClipMaskManager::SetupClipping(GrContext* context,
get_analytic_clip_processor(elements, disallowAnalyticAA, {-clipX, -clipY}, devBounds,
&clipFP)) {
SkIRect scissorSpaceIBounds(clipSpaceIBounds);
scissorSpaceIBounds.offset(-clip.origin());
scissorSpaceIBounds.offset(-fOrigin);
if (GrClip::IsInsideClip(scissorSpaceIBounds, devBounds)) {
out->makeFPBased(std::move(clipFP), SkRect::Make(scissorSpaceIBounds));
} else {
@ -338,7 +351,7 @@ bool GrClipMaskManager::SetupClipping(GrContext* context,
// The mask's top left coord should be pinned to the rounded-out top left corner of
// clipSpace bounds. We determine the mask's position WRT to the render target here.
SkIRect rtSpaceMaskBounds = clipSpaceIBounds;
rtSpaceMaskBounds.offset(-clip.origin());
rtSpaceMaskBounds.offset(-fOrigin);
out->makeFPBased(create_fp_for_mask(result.get(), rtSpaceMaskBounds),
SkRect::Make(rtSpaceMaskBounds));
return true;
@ -347,7 +360,7 @@ bool GrClipMaskManager::SetupClipping(GrContext* context,
}
// use the stencil clip if we can't represent the clip as a rectangle.
SkIPoint clipSpaceToStencilSpaceOffset = -clip.origin();
SkIPoint clipSpaceToStencilSpaceOffset = -fOrigin;
CreateStencilClipMask(context,
drawContext,
genID,
@ -443,12 +456,12 @@ static void GetClipMaskKey(int32_t clipGenID, const SkIRect& bounds, GrUniqueKey
builder[2] = SkToU16(bounds.fTop) | (SkToU16(bounds.fBottom) << 16);
}
sk_sp<GrTexture> GrClipMaskManager::CreateAlphaClipMask(GrContext* context,
int32_t elementsGenID,
GrReducedClip::InitialState initialState,
const GrReducedClip::ElementList& elements,
const SkVector& clipToMaskOffset,
const SkIRect& clipSpaceIBounds) {
sk_sp<GrTexture> GrClipStackClip::CreateAlphaClipMask(GrContext* context,
int32_t elementsGenID,
GrReducedClip::InitialState initialState,
const GrReducedClip::ElementList& elements,
const SkVector& clipToMaskOffset,
const SkIRect& clipSpaceIBounds) {
GrResourceProvider* resourceProvider = context->resourceProvider();
GrUniqueKey key;
GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key);
@ -548,13 +561,13 @@ sk_sp<GrTexture> GrClipMaskManager::CreateAlphaClipMask(GrContext* context,
////////////////////////////////////////////////////////////////////////////////
// Create a 1-bit clip mask in the stencil buffer. 'devClipBounds' are in device
// (as opposed to canvas) coordinates
bool GrClipMaskManager::CreateStencilClipMask(GrContext* context,
GrDrawContext* drawContext,
int32_t elementsGenID,
GrReducedClip::InitialState initialState,
const GrReducedClip::ElementList& elements,
const SkIRect& clipSpaceIBounds,
const SkIPoint& clipSpaceToStencilOffset) {
bool GrClipStackClip::CreateStencilClipMask(GrContext* context,
GrDrawContext* drawContext,
int32_t elementsGenID,
GrReducedClip::InitialState initialState,
const GrReducedClip::ElementList& elements,
const SkIRect& clipSpaceIBounds,
const SkIPoint& clipSpaceToStencilOffset) {
SkASSERT(drawContext);
GrStencilAttachment* stencilAttachment = context->resourceProvider()->attachStencilAttachment(
@ -620,9 +633,10 @@ bool GrClipMaskManager::CreateStencilClipMask(GrContext* context,
canDrawArgs.fHasUserStencilSettings = false;
canDrawArgs.fIsStencilBufferMSAA = drawContext->isStencilBufferMultisampled();
pr = context->drawingManager()->getPathRenderer(canDrawArgs, false,
GrPathRendererChain::kStencilOnly_DrawType,
&stencilSupport);
GrDrawingManager* dm = context->drawingManager();
pr = dm->getPathRenderer(canDrawArgs, false,
GrPathRendererChain::kStencilOnly_DrawType,
&stencilSupport);
if (!pr) {
return false;
}
@ -731,13 +745,12 @@ bool GrClipMaskManager::CreateStencilClipMask(GrContext* context,
}
////////////////////////////////////////////////////////////////////////////////
sk_sp<GrTexture> GrClipMaskManager::CreateSoftwareClipMask(
GrTextureProvider* texProvider,
int32_t elementsGenID,
GrReducedClip::InitialState initialState,
const GrReducedClip::ElementList& elements,
const SkVector& clipToMaskOffset,
const SkIRect& clipSpaceIBounds) {
sk_sp<GrTexture> GrClipStackClip::CreateSoftwareClipMask(GrTextureProvider* texProvider,
int32_t elementsGenID,
GrReducedClip::InitialState initialState,
const GrReducedClip::ElementList& elements,
const SkVector& clipToMaskOffset,
const SkIRect& clipSpaceIBounds) {
GrUniqueKey key;
GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key);
if (GrTexture* texture = texProvider->findAndRefTextureByUniqueKey(key)) {

View File

@ -1,50 +1,44 @@
/*
* Copyright 2012 Google Inc.
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrClipMaskManager_DEFINED
#define GrClipMaskManager_DEFINED
#ifndef GrClipStackClip_DEFINED
#define GrClipStackClip_DEFINED
#include "GrClip.h"
#include "GrReducedClip.h"
#include "SkClipStack.h"
#include "SkTypes.h"
class GrAppliedClip;
class GrClipStackClip;
class GrContext;
class GrDrawContext;
class GrPathRenderer;
class GrTexture;
class GrTextureProvider;
class GrUniqueKey;
class GrPathRenderer;
/**
* The clip mask creator handles the generation of the clip mask. If anti
* aliasing is requested it will (in the future) generate a single channel
* (8bit) mask. If no anti aliasing is requested it will generate a 1-bit
* mask in the stencil buffer. In the non anti-aliasing case, if the clip
* mask can be represented as a rectangle then scissoring is used. In all
* cases scissoring is used to bound the range of the clip mask.
* GrClipStackClip can apply a generic SkClipStack to the draw state. It may need to generate an
* 8-bit alpha clip mask and/or modify the stencil buffer during apply().
*/
// This has to remain a class, for now, so it can be friended (by GrDrawContext & GrContext)
class GrClipMaskManager {
class GrClipStackClip final : public GrClip {
public:
/**
* Creates a clip mask if necessary as a stencil buffer or alpha texture
* and sets the GrGpu's scissor and stencil state. If the return is false
* then the draw can be skipped. devBounds is optional but can help optimize
* clipping.
*/
static bool SetupClipping(GrContext*,
GrDrawContext*,
const GrClipStackClip&,
const SkRect* devBounds,
bool useHWAA,
bool hasUserStencilSettings,
GrAppliedClip* out);
GrClipStackClip(const SkClipStack* stack = nullptr, const SkIPoint* origin = nullptr) {
this->reset(stack, origin);
}
void reset(const SkClipStack* stack = nullptr, const SkIPoint* origin = nullptr) {
fOrigin = origin ? *origin : SkIPoint::Make(0, 0);
fStack.reset(SkSafeRef(stack));
}
bool quickContains(const SkRect&) const final;
void getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects) const final;
bool apply(GrContext*,
GrDrawContext*,
const SkRect* devBounds,
bool useHWAA,
bool hasUserStencilSettings,
GrAppliedClip* out) const final;
private:
static bool PathNeedsSWRenderer(GrContext* context,
@ -89,6 +83,9 @@ private:
static GrTexture* CreateCachedMask(int width, int height, const GrUniqueKey& key,
bool renderTarget);
SkIPoint fOrigin;
SkAutoTUnref<const SkClipStack> fStack;
};
#endif // GrClipMaskManager_DEFINED
#endif // GrClipStackClip_DEFINED

View File

@ -49,7 +49,7 @@ GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
, fAuditTrail(auditTrail)
, fFlags(0)
, fRenderTarget(rt) {
// TODO: Stop extracting the context (currently needed by GrClipMaskManager)
// TODO: Stop extracting the context (currently needed by GrClip)
fContext = fGpu->getContext();
fClipBatchToBounds = options.fClipBatchToBounds;

View File

@ -214,7 +214,7 @@ private:
SkRect fClippedBounds;
};
SkSTArray<256, RecordedBatch, true> fRecordedBatches;
// The context is only in service of the clip mask manager, remove once CMM doesn't need this.
// The context is only in service of the GrClip, remove once it doesn't need this.
GrContext* fContext;
GrGpu* fGpu;
GrResourceProvider* fResourceProvider;

View File

@ -75,7 +75,7 @@ public:
const SkMatrix* matrix);
// This utility routine is used to add a shape's mask to some other draw.
// The ClipMaskManager uses it to accumulate clip masks while the
// The GrClipStackClip uses it to accumulate clip masks while the
// GrSoftwarePathRenderer uses it to fulfill a drawPath call.
// It draws with "texture" as a path mask into "target" using "rect" as
// geometry and the current drawState. The current drawState is altered to

View File

@ -9,8 +9,8 @@
#ifndef GrStencilAttachment_DEFINED
#define GrStencilAttachment_DEFINED
#include "GrClip.h"
#include "GrGpuResource.h"
#include "SkClipStack.h"
class GrRenderTarget;
class GrResourceKey;

View File

@ -15,6 +15,7 @@
#include "SkPicture.h"
#include "SkRegion.h"
#include "SkSurface.h"
#include "GrClipStackClip.h"
#include "GrDrawContext.h"
#include "GrContext.h"
#include "GrSurfacePriv.h"

View File

@ -8,7 +8,7 @@
#include "Test.h"
// This is a GR test
#if SK_SUPPORT_GPU
#include "GrClipMaskManager.h"
#include "GrClipStackClip.h"
#include "GrContext.h"
// Ensure that the 'getConservativeBounds' calls are returning bounds clamped