robertphillips 2016-05-15 07:53:35 -07:00 committed by Commit bot
parent 9342bd8219
commit c99b8f0351
2 changed files with 54 additions and 72 deletions

View File

@ -370,7 +370,7 @@ bool GrClipMaskManager::setupClipping(const GrPipelineBuilder& pipelineBuilder,
// If the stencil buffer is multisampled we can use it to do everything. // If the stencil buffer is multisampled we can use it to do everything.
if (!rt->isStencilBufferMultisampled() && requiresAA) { if (!rt->isStencilBufferMultisampled() && requiresAA) {
SkAutoTUnref<GrTexture> result; sk_sp<GrTexture> result;
// The top-left of the mask corresponds to the top-left corner of the bounds. // The top-left of the mask corresponds to the top-left corner of the bounds.
SkVector clipToMaskOffset = { SkVector clipToMaskOffset = {
@ -381,19 +381,19 @@ bool GrClipMaskManager::setupClipping(const GrPipelineBuilder& pipelineBuilder,
if (UseSWOnlyPath(this->getContext(), pipelineBuilder, rt, clipToMaskOffset, elements)) { if (UseSWOnlyPath(this->getContext(), pipelineBuilder, rt, clipToMaskOffset, elements)) {
// The clip geometry is complex enough that it will be more efficient to create it // The clip geometry is complex enough that it will be more efficient to create it
// entirely in software // entirely in software
result.reset(CreateSoftwareClipMask(this->getContext(), result = CreateSoftwareClipMask(this->getContext(),
genID, genID,
initialState, initialState,
elements, elements,
clipToMaskOffset, clipToMaskOffset,
clipSpaceIBounds)); clipSpaceIBounds);
} else { } else {
result.reset(CreateAlphaClipMask(this->getContext(), result = CreateAlphaClipMask(this->getContext(),
genID, genID,
initialState, initialState,
elements, elements,
clipToMaskOffset, clipToMaskOffset,
clipSpaceIBounds)); clipSpaceIBounds);
// If createAlphaClipMask fails it means UseSWOnlyPath has a bug // If createAlphaClipMask fails it means UseSWOnlyPath has a bug
SkASSERT(result); SkASSERT(result);
} }
@ -403,7 +403,7 @@ bool GrClipMaskManager::setupClipping(const GrPipelineBuilder& pipelineBuilder,
// clipSpace bounds. We determine the mask's position WRT to the render target here. // clipSpace bounds. We determine the mask's position WRT to the render target here.
SkIRect rtSpaceMaskBounds = clipSpaceIBounds; SkIRect rtSpaceMaskBounds = clipSpaceIBounds;
rtSpaceMaskBounds.offset(-clip.origin()); rtSpaceMaskBounds.offset(-clip.origin());
out->fClipCoverageFP.reset(create_fp_for_mask(result, rtSpaceMaskBounds)); out->fClipCoverageFP.reset(create_fp_for_mask(result.get(), rtSpaceMaskBounds));
return true; return true;
} }
// if alpha clip mask creation fails fall through to the non-AA code paths // if alpha clip mask creation fails fall through to the non-AA code paths
@ -502,38 +502,29 @@ static void GetClipMaskKey(int32_t clipGenID, const SkIRect& bounds, GrUniqueKey
builder[2] = SkToU16(bounds.fTop) | (SkToU16(bounds.fBottom) << 16); builder[2] = SkToU16(bounds.fTop) | (SkToU16(bounds.fBottom) << 16);
} }
GrTexture* GrClipMaskManager::CreateAlphaClipMask(GrContext* context, sk_sp<GrTexture> GrClipMaskManager::CreateAlphaClipMask(GrContext* context,
int32_t elementsGenID, int32_t elementsGenID,
GrReducedClip::InitialState initialState, GrReducedClip::InitialState initialState,
const GrReducedClip::ElementList& elements, const GrReducedClip::ElementList& elements,
const SkVector& clipToMaskOffset, const SkVector& clipToMaskOffset,
const SkIRect& clipSpaceIBounds) { const SkIRect& clipSpaceIBounds) {
GrResourceProvider* resourceProvider = context->resourceProvider(); GrResourceProvider* resourceProvider = context->resourceProvider();
GrUniqueKey key; GrUniqueKey key;
GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key); GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key);
if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)) { if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)) {
return texture; return sk_sp<GrTexture>(texture);
} }
// There's no texture in the cache. Let's try to allocate it then. // There's no texture in the cache. Let's try to allocate it then.
GrSurfaceDesc desc; GrPixelConfig config = kRGBA_8888_GrPixelConfig;
desc.fWidth = clipSpaceIBounds.width();
desc.fHeight = clipSpaceIBounds.height();
desc.fFlags = kRenderTarget_GrSurfaceFlag;
if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
desc.fConfig = kAlpha_8_GrPixelConfig; config = kAlpha_8_GrPixelConfig;
} else {
desc.fConfig = kRGBA_8888_GrPixelConfig;
} }
SkAutoTUnref<GrTexture> texture(resourceProvider->createApproxTexture(desc, 0)); sk_sp<GrDrawContext> dc(context->newDrawContext(SkBackingFit::kApprox,
if (!texture) { clipSpaceIBounds.width(),
return nullptr; clipSpaceIBounds.height(),
} config));
texture->resourcePriv().setUniqueKey(key);
sk_sp<GrDrawContext> dc(context->drawContext(sk_ref_sp(texture->asRenderTarget())));
if (!dc) { if (!dc) {
return nullptr; return nullptr;
} }
@ -563,17 +554,6 @@ GrTexture* GrClipMaskManager::CreateAlphaClipMask(GrContext* context,
SkRegion::Op op = element->getOp(); SkRegion::Op op = element->getOp();
bool invert = element->isInverseFilled(); bool invert = element->isInverseFilled();
if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) { if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) {
#ifdef SK_DEBUG
GrPathRenderer* pr = GetPathRenderer(context,
texture, translate, element);
if (Element::kRect_Type != element->getType() && !pr) {
// UseSWOnlyPath should now filter out all cases where gpu-side mask merging would
// be performed (i.e., pr would be NULL for a non-rect path).
// See https://bug.skia.org/4519 for rationale and details.
SkASSERT(0);
}
#endif
GrFixedClip clip(maskSpaceIBounds); GrFixedClip clip(maskSpaceIBounds);
// draw directly into the result with the stencil set to make the pixels affected // draw directly into the result with the stencil set to make the pixels affected
@ -589,7 +569,6 @@ GrTexture* GrClipMaskManager::CreateAlphaClipMask(GrContext* context,
); );
if (!stencil_element(dc.get(), clip, &kStencilInElement, if (!stencil_element(dc.get(), clip, &kStencilInElement,
translate, element)) { translate, element)) {
texture->resourcePriv().removeUniqueKey();
return nullptr; return nullptr;
} }
@ -607,7 +586,6 @@ GrTexture* GrClipMaskManager::CreateAlphaClipMask(GrContext* context,
op, !invert, false, op, !invert, false,
translate, translate,
SkRect::Make(clipSpaceIBounds))) { SkRect::Make(clipSpaceIBounds))) {
texture->resourcePriv().removeUniqueKey();
return nullptr; return nullptr;
} }
} else { } else {
@ -620,7 +598,10 @@ GrTexture* GrClipMaskManager::CreateAlphaClipMask(GrContext* context,
} }
} }
return texture.release(); sk_sp<GrTexture> texture(dc->asTexture());
SkASSERT(texture);
texture->resourcePriv().setUniqueKey(key);
return texture;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -807,17 +788,18 @@ bool GrClipMaskManager::createStencilClipMask(GrRenderTarget* rt,
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
GrTexture* GrClipMaskManager::CreateSoftwareClipMask(GrContext* context, sk_sp<GrTexture> GrClipMaskManager::CreateSoftwareClipMask(
int32_t elementsGenID, GrContext* context,
GrReducedClip::InitialState initialState, int32_t elementsGenID,
const GrReducedClip::ElementList& elements, GrReducedClip::InitialState initialState,
const SkVector& clipToMaskOffset, const GrReducedClip::ElementList& elements,
const SkIRect& clipSpaceIBounds) { const SkVector& clipToMaskOffset,
const SkIRect& clipSpaceIBounds) {
GrUniqueKey key; GrUniqueKey key;
GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key); GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key);
GrResourceProvider* resourceProvider = context->resourceProvider(); GrResourceProvider* resourceProvider = context->resourceProvider();
if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)) { if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)) {
return texture; return sk_sp<GrTexture>(texture);
} }
// The mask texture may be larger than necessary. We round out the clip space bounds and pin // The mask texture may be larger than necessary. We round out the clip space bounds and pin
@ -873,13 +855,13 @@ GrTexture* GrClipMaskManager::CreateSoftwareClipMask(GrContext* context,
desc.fHeight = clipSpaceIBounds.height(); desc.fHeight = clipSpaceIBounds.height();
desc.fConfig = kAlpha_8_GrPixelConfig; desc.fConfig = kAlpha_8_GrPixelConfig;
GrTexture* result = context->resourceProvider()->createApproxTexture(desc, 0); sk_sp<GrTexture> result(context->resourceProvider()->createApproxTexture(desc, 0));
if (!result) { if (!result) {
return nullptr; return nullptr;
} }
result->resourcePriv().setUniqueKey(key); result->resourcePriv().setUniqueKey(key);
helper.toTexture(result); helper.toTexture(result.get());
return result; return result;
} }

View File

@ -85,20 +85,20 @@ private:
// Creates an alpha mask of the clip. The mask is a rasterization of elements through the // Creates an alpha mask of the clip. The mask is a rasterization of elements through the
// rect specified by clipSpaceIBounds. // rect specified by clipSpaceIBounds.
static GrTexture* CreateAlphaClipMask(GrContext*, static sk_sp<GrTexture> CreateAlphaClipMask(GrContext*,
int32_t elementsGenID, int32_t elementsGenID,
GrReducedClip::InitialState initialState, GrReducedClip::InitialState initialState,
const GrReducedClip::ElementList& elements, const GrReducedClip::ElementList& elements,
const SkVector& clipToMaskOffset, const SkVector& clipToMaskOffset,
const SkIRect& clipSpaceIBounds); const SkIRect& clipSpaceIBounds);
// Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture. // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture.
static GrTexture* CreateSoftwareClipMask(GrContext*, static sk_sp<GrTexture> CreateSoftwareClipMask(GrContext*,
int32_t elementsGenID, int32_t elementsGenID,
GrReducedClip::InitialState initialState, GrReducedClip::InitialState initialState,
const GrReducedClip::ElementList& elements, const GrReducedClip::ElementList& elements,
const SkVector& clipToMaskOffset, const SkVector& clipToMaskOffset,
const SkIRect& clipSpaceIBounds); const SkIRect& clipSpaceIBounds);
static bool UseSWOnlyPath(GrContext*, static bool UseSWOnlyPath(GrContext*,
const GrPipelineBuilder&, const GrPipelineBuilder&,