GrSWMaskHelper and GrSoftwarePathRenderer only need the textureProvider (not GrContext)
This is split out of: https://codereview.chromium.org/1988923002/ (Declassify GrClipMaskManager and Remove GrRenderTarget and GrDrawTarget from GrPipelineBuilder) BUG=skia: Review-Url: https://codereview.chromium.org/1993403002
This commit is contained in:
parent
24a9bd711a
commit
0152d731e0
@ -384,7 +384,7 @@ 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 = CreateSoftwareClipMask(this->getContext(),
|
result = CreateSoftwareClipMask(this->getContext()->textureProvider(),
|
||||||
genID,
|
genID,
|
||||||
initialState,
|
initialState,
|
||||||
elements,
|
elements,
|
||||||
@ -791,7 +791,7 @@ bool GrClipMaskManager::createStencilClipMask(GrRenderTarget* rt,
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
sk_sp<GrTexture> GrClipMaskManager::CreateSoftwareClipMask(
|
sk_sp<GrTexture> GrClipMaskManager::CreateSoftwareClipMask(
|
||||||
GrContext* context,
|
GrTextureProvider* texProvider,
|
||||||
int32_t elementsGenID,
|
int32_t elementsGenID,
|
||||||
GrReducedClip::InitialState initialState,
|
GrReducedClip::InitialState initialState,
|
||||||
const GrReducedClip::ElementList& elements,
|
const GrReducedClip::ElementList& elements,
|
||||||
@ -799,8 +799,7 @@ sk_sp<GrTexture> GrClipMaskManager::CreateSoftwareClipMask(
|
|||||||
const SkIRect& clipSpaceIBounds) {
|
const SkIRect& clipSpaceIBounds) {
|
||||||
GrUniqueKey key;
|
GrUniqueKey key;
|
||||||
GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key);
|
GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key);
|
||||||
GrResourceProvider* resourceProvider = context->resourceProvider();
|
if (GrTexture* texture = texProvider->findAndRefTextureByUniqueKey(key)) {
|
||||||
if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)) {
|
|
||||||
return sk_sp<GrTexture>(texture);
|
return sk_sp<GrTexture>(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -808,7 +807,7 @@ sk_sp<GrTexture> GrClipMaskManager::CreateSoftwareClipMask(
|
|||||||
// the top left corner of the resulting rect to the top left of the texture.
|
// the top left corner of the resulting rect to the top left of the texture.
|
||||||
SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpaceIBounds.height());
|
SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpaceIBounds.height());
|
||||||
|
|
||||||
GrSWMaskHelper helper(context);
|
GrSWMaskHelper helper(texProvider);
|
||||||
|
|
||||||
// Set the matrix so that rendered clip elements are transformed to mask space from clip
|
// Set the matrix so that rendered clip elements are transformed to mask space from clip
|
||||||
// space.
|
// space.
|
||||||
@ -857,7 +856,7 @@ sk_sp<GrTexture> GrClipMaskManager::CreateSoftwareClipMask(
|
|||||||
desc.fHeight = clipSpaceIBounds.height();
|
desc.fHeight = clipSpaceIBounds.height();
|
||||||
desc.fConfig = kAlpha_8_GrPixelConfig;
|
desc.fConfig = kAlpha_8_GrPixelConfig;
|
||||||
|
|
||||||
sk_sp<GrTexture> result(context->resourceProvider()->createApproxTexture(desc, 0));
|
sk_sp<GrTexture> result(texProvider->createApproxTexture(desc));
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,7 @@
|
|||||||
|
|
||||||
#include "GrPipelineBuilder.h"
|
#include "GrPipelineBuilder.h"
|
||||||
#include "GrReducedClip.h"
|
#include "GrReducedClip.h"
|
||||||
#include "GrTexture.h"
|
|
||||||
#include "SkClipStack.h"
|
#include "SkClipStack.h"
|
||||||
#include "SkDeque.h"
|
|
||||||
#include "SkPath.h"
|
|
||||||
#include "SkRefCnt.h"
|
|
||||||
#include "SkTLList.h"
|
|
||||||
#include "SkTypes.h"
|
#include "SkTypes.h"
|
||||||
|
|
||||||
class GrAppliedClip;
|
class GrAppliedClip;
|
||||||
@ -24,7 +19,7 @@ class GrPathRenderer;
|
|||||||
class GrPathRendererChain;
|
class GrPathRendererChain;
|
||||||
class GrResourceProvider;
|
class GrResourceProvider;
|
||||||
class GrTexture;
|
class GrTexture;
|
||||||
class SkPath;
|
class GrTextureProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The clip mask creator handles the generation of the clip mask. If anti
|
* The clip mask creator handles the generation of the clip mask. If anti
|
||||||
@ -93,7 +88,7 @@ private:
|
|||||||
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 sk_sp<GrTexture> CreateSoftwareClipMask(GrContext*,
|
static sk_sp<GrTexture> CreateSoftwareClipMask(GrTextureProvider*,
|
||||||
int32_t elementsGenID,
|
int32_t elementsGenID,
|
||||||
GrReducedClip::InitialState initialState,
|
GrReducedClip::InitialState initialState,
|
||||||
const GrReducedClip::ElementList& elements,
|
const GrReducedClip::ElementList& elements,
|
||||||
|
@ -151,7 +151,7 @@ GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawP
|
|||||||
GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport);
|
GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport);
|
||||||
if (!pr && allowSW) {
|
if (!pr && allowSW) {
|
||||||
if (!fSoftwarePathRenderer) {
|
if (!fSoftwarePathRenderer) {
|
||||||
fSoftwarePathRenderer = new GrSoftwarePathRenderer(fContext);
|
fSoftwarePathRenderer = new GrSoftwarePathRenderer(fContext->textureProvider());
|
||||||
}
|
}
|
||||||
pr = fSoftwarePathRenderer;
|
pr = fSoftwarePathRenderer;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ GrTexture* GrSWMaskHelper::createTexture() {
|
|||||||
desc.fHeight = fPixels.height();
|
desc.fHeight = fPixels.height();
|
||||||
desc.fConfig = kAlpha_8_GrPixelConfig;
|
desc.fConfig = kAlpha_8_GrPixelConfig;
|
||||||
|
|
||||||
return fContext->textureProvider()->createApproxTexture(desc);
|
return fTexProvider->createApproxTexture(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,13 +134,13 @@ void GrSWMaskHelper::toSDF(unsigned char* sdf) {
|
|||||||
* and uploads the result to a scratch texture. Returns the resulting
|
* and uploads the result to a scratch texture. Returns the resulting
|
||||||
* texture on success; nullptr on failure.
|
* texture on success; nullptr on failure.
|
||||||
*/
|
*/
|
||||||
GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context,
|
GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrTextureProvider* texProvider,
|
||||||
const SkPath& path,
|
const SkPath& path,
|
||||||
const GrStyle& style,
|
const GrStyle& style,
|
||||||
const SkIRect& resultBounds,
|
const SkIRect& resultBounds,
|
||||||
bool antiAlias,
|
bool antiAlias,
|
||||||
const SkMatrix* matrix) {
|
const SkMatrix* matrix) {
|
||||||
GrSWMaskHelper helper(context);
|
GrSWMaskHelper helper(texProvider);
|
||||||
|
|
||||||
if (!helper.init(resultBounds, matrix)) {
|
if (!helper.init(resultBounds, matrix)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#include "SkTypes.h"
|
#include "SkTypes.h"
|
||||||
|
|
||||||
class GrClip;
|
class GrClip;
|
||||||
class GrContext;
|
class GrTextureProvider;
|
||||||
class GrTexture;
|
class GrTexture;
|
||||||
class SkPath;
|
class SkPath;
|
||||||
class SkStrokeRec;
|
class SkStrokeRec;
|
||||||
@ -41,7 +41,7 @@ class GrDrawTarget;
|
|||||||
*/
|
*/
|
||||||
class GrSWMaskHelper : SkNoncopyable {
|
class GrSWMaskHelper : SkNoncopyable {
|
||||||
public:
|
public:
|
||||||
GrSWMaskHelper(GrContext* context) : fContext(context) { }
|
GrSWMaskHelper(GrTextureProvider* texProvider) : fTexProvider(texProvider) { }
|
||||||
|
|
||||||
// set up the internal state in preparation for draws. Since many masks
|
// set up the internal state in preparation for draws. Since many masks
|
||||||
// may be accumulated in the helper during creation, "resultBounds"
|
// may be accumulated in the helper during creation, "resultBounds"
|
||||||
@ -69,7 +69,7 @@ public:
|
|||||||
|
|
||||||
// Canonical usage utility that draws a single path and uploads it
|
// Canonical usage utility that draws a single path and uploads it
|
||||||
// to the GPU. The result is returned.
|
// to the GPU. The result is returned.
|
||||||
static GrTexture* DrawPathMaskToTexture(GrContext* context,
|
static GrTexture* DrawPathMaskToTexture(GrTextureProvider*,
|
||||||
const SkPath& path,
|
const SkPath& path,
|
||||||
const GrStyle& style,
|
const GrStyle& style,
|
||||||
const SkIRect& resultBounds,
|
const SkIRect& resultBounds,
|
||||||
@ -99,11 +99,11 @@ private:
|
|||||||
// result (i.e., right size & format)
|
// result (i.e., right size & format)
|
||||||
GrTexture* createTexture();
|
GrTexture* createTexture();
|
||||||
|
|
||||||
GrContext* fContext;
|
GrTextureProvider* fTexProvider;
|
||||||
SkMatrix fMatrix;
|
SkMatrix fMatrix;
|
||||||
SkAutoPixmapStorage fPixels;
|
SkAutoPixmapStorage fPixels;
|
||||||
SkDraw fDraw;
|
SkDraw fDraw;
|
||||||
SkRasterClip fRasterClip;
|
SkRasterClip fRasterClip;
|
||||||
|
|
||||||
typedef SkNoncopyable INHERITED;
|
typedef SkNoncopyable INHERITED;
|
||||||
};
|
};
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "GrSoftwarePathRenderer.h"
|
#include "GrSoftwarePathRenderer.h"
|
||||||
#include "GrContext.h"
|
|
||||||
#include "GrSWMaskHelper.h"
|
#include "GrSWMaskHelper.h"
|
||||||
|
#include "GrTextureProvider.h"
|
||||||
#include "batches/GrRectBatchFactory.h"
|
#include "batches/GrRectBatchFactory.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool GrSoftwarePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
|
bool GrSoftwarePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
|
||||||
return SkToBool(fContext);
|
return SkToBool(fTexProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -21,22 +21,17 @@ namespace {
|
|||||||
// gets device coord bounds of path (not considering the fill) and clip. The
|
// gets device coord bounds of path (not considering the fill) and clip. The
|
||||||
// path bounds will be a subset of the clip bounds. returns false if
|
// path bounds will be a subset of the clip bounds. returns false if
|
||||||
// path bounds would be empty.
|
// path bounds would be empty.
|
||||||
bool get_path_and_clip_bounds(const GrPipelineBuilder* pipelineBuilder,
|
bool get_path_and_clip_bounds(int width, int height,
|
||||||
const GrClip& clip,
|
const GrClip& clip,
|
||||||
const SkPath& path,
|
const SkPath& path,
|
||||||
const SkMatrix& matrix,
|
const SkMatrix& matrix,
|
||||||
SkIRect* devPathBounds,
|
SkIRect* devPathBounds,
|
||||||
SkIRect* devClipBounds) {
|
SkIRect* devClipBounds) {
|
||||||
// compute bounds as intersection of rt size, clip, and path
|
// compute bounds as intersection of rt size, clip, and path
|
||||||
const GrRenderTarget* rt = pipelineBuilder->getRenderTarget();
|
clip.getConservativeBounds(width, height, devClipBounds);
|
||||||
if (nullptr == rt) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
clip.getConservativeBounds(rt->width(), rt->height(), devClipBounds);
|
|
||||||
|
|
||||||
if (devClipBounds->isEmpty()) {
|
if (devClipBounds->isEmpty()) {
|
||||||
*devPathBounds = SkIRect::MakeWH(rt->width(), rt->height());
|
*devPathBounds = SkIRect::MakeWH(width, height);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,12 +107,15 @@ void draw_around_inv_path(GrDrawTarget* target,
|
|||||||
// return true on success; false on failure
|
// return true on success; false on failure
|
||||||
bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
|
bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
|
||||||
GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), "GrSoftwarePathRenderer::onDrawPath");
|
GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), "GrSoftwarePathRenderer::onDrawPath");
|
||||||
if (nullptr == fContext) {
|
if (!fTexProvider || !args.fPipelineBuilder->getRenderTarget()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int width = args.fPipelineBuilder->getRenderTarget()->width();
|
||||||
|
const int height = args.fPipelineBuilder->getRenderTarget()->height();
|
||||||
|
|
||||||
SkIRect devPathBounds, devClipBounds;
|
SkIRect devPathBounds, devClipBounds;
|
||||||
if (!get_path_and_clip_bounds(args.fPipelineBuilder, *args.fClip, *args.fPath,
|
if (!get_path_and_clip_bounds(width, height, *args.fClip, *args.fPath,
|
||||||
*args.fViewMatrix, &devPathBounds, &devClipBounds)) {
|
*args.fViewMatrix, &devPathBounds, &devClipBounds)) {
|
||||||
if (args.fPath->isInverseFillType()) {
|
if (args.fPath->isInverseFillType()) {
|
||||||
draw_around_inv_path(args.fTarget, args.fPipelineBuilder, *args.fClip, args.fColor,
|
draw_around_inv_path(args.fTarget, args.fPipelineBuilder, *args.fClip, args.fColor,
|
||||||
@ -127,7 +125,7 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkAutoTUnref<GrTexture> texture(
|
SkAutoTUnref<GrTexture> texture(
|
||||||
GrSWMaskHelper::DrawPathMaskToTexture(fContext, *args.fPath, *args.fStyle,
|
GrSWMaskHelper::DrawPathMaskToTexture(fTexProvider, *args.fPath, *args.fStyle,
|
||||||
devPathBounds,
|
devPathBounds,
|
||||||
args.fAntiAlias, args.fViewMatrix));
|
args.fAntiAlias, args.fViewMatrix));
|
||||||
if (nullptr == texture) {
|
if (nullptr == texture) {
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include "GrPathRenderer.h"
|
#include "GrPathRenderer.h"
|
||||||
|
|
||||||
class GrContext;
|
class GrTextureProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class uses the software side to render a path to an SkBitmap and
|
* This class uses the software side to render a path to an SkBitmap and
|
||||||
@ -18,9 +18,8 @@ class GrContext;
|
|||||||
*/
|
*/
|
||||||
class GrSoftwarePathRenderer : public GrPathRenderer {
|
class GrSoftwarePathRenderer : public GrPathRenderer {
|
||||||
public:
|
public:
|
||||||
GrSoftwarePathRenderer(GrContext* context)
|
GrSoftwarePathRenderer(GrTextureProvider* texProvider) : fTexProvider(texProvider) { }
|
||||||
: fContext(context) {
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
StencilSupport onGetStencilSupport(const SkPath&) const override {
|
StencilSupport onGetStencilSupport(const SkPath&) const override {
|
||||||
return GrPathRenderer::kNoSupport_StencilSupport;
|
return GrPathRenderer::kNoSupport_StencilSupport;
|
||||||
@ -31,7 +30,7 @@ private:
|
|||||||
bool onDrawPath(const DrawPathArgs&) override;
|
bool onDrawPath(const DrawPathArgs&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GrContext* fContext;
|
GrTextureProvider* fTexProvider;
|
||||||
|
|
||||||
typedef GrPathRenderer INHERITED;
|
typedef GrPathRenderer INHERITED;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user