aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/effects/SkShadowMaskFilter.cpp2
-rw-r--r--src/gpu/GrClipStackClip.cpp24
-rw-r--r--src/gpu/GrClipStackClip.h2
-rw-r--r--src/gpu/GrContext.cpp19
-rw-r--r--src/gpu/GrContextPriv.h4
-rw-r--r--src/gpu/GrSWMaskHelper.cpp58
-rw-r--r--src/gpu/GrSWMaskHelper.h22
-rw-r--r--src/gpu/GrSoftwarePathRenderer.cpp8
-rw-r--r--src/gpu/GrSurfaceContextPriv.h45
9 files changed, 120 insertions, 64 deletions
diff --git a/src/effects/SkShadowMaskFilter.cpp b/src/effects/SkShadowMaskFilter.cpp
index 85770ca175..38f2591cb2 100755
--- a/src/effects/SkShadowMaskFilter.cpp
+++ b/src/effects/SkShadowMaskFilter.cpp
@@ -349,7 +349,7 @@ sk_sp<GrTextureProxy> SkShadowMaskFilterImpl::filterMaskGPU(GrContext*,
sk_sp<GrTextureProxy> srcProxy,
const SkMatrix& ctm,
const SkIRect& maskRect) const {
- // This filter it generative and doesn't operate on pre-existing masks
+ // This filter is generative and doesn't operate on pre-existing masks
return nullptr;
}
diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp
index fae01ce63c..a7bcce492d 100644
--- a/src/gpu/GrClipStackClip.cpp
+++ b/src/gpu/GrClipStackClip.cpp
@@ -16,6 +16,7 @@
#include "GrRenderTargetPriv.h"
#include "GrStencilAttachment.h"
#include "GrSWMaskHelper.h"
+#include "GrTextureProxy.h"
#include "effects/GrConvexPolyEffect.h"
#include "effects/GrRRectEffect.h"
#include "effects/GrTextureDomain.h"
@@ -340,7 +341,7 @@ bool GrClipStackClip::apply(GrContext* context, GrRenderTargetContext* renderTar
if (UseSWOnlyPath(context, hasUserStencilSettings, renderTargetContext, reducedClip)) {
// The clip geometry is complex enough that it will be more efficient to create it
// entirely in software
- result = CreateSoftwareClipMask(context->textureProvider(), reducedClip);
+ result = CreateSoftwareClipMask(context, reducedClip);
} else {
result = CreateAlphaClipMask(context, reducedClip);
}
@@ -425,11 +426,11 @@ sk_sp<GrTexture> GrClipStackClip::CreateAlphaClipMask(GrContext* context,
return texture;
}
-sk_sp<GrTexture> GrClipStackClip::CreateSoftwareClipMask(GrTextureProvider* texProvider,
+sk_sp<GrTexture> GrClipStackClip::CreateSoftwareClipMask(GrContext* context,
const GrReducedClip& reducedClip) {
GrUniqueKey key;
GetClipMaskKey(reducedClip.elementsGenID(), reducedClip.ibounds(), &key);
- if (GrTexture* texture = texProvider->findAndRefTextureByUniqueKey(key)) {
+ if (GrTexture* texture = context->textureProvider()->findAndRefTextureByUniqueKey(key)) {
return sk_sp<GrTexture>(texture);
}
@@ -437,7 +438,7 @@ sk_sp<GrTexture> GrClipStackClip::CreateSoftwareClipMask(GrTextureProvider* texP
// the top left corner of the resulting rect to the top left of the texture.
SkIRect maskSpaceIBounds = SkIRect::MakeWH(reducedClip.width(), reducedClip.height());
- GrSWMaskHelper helper(texProvider);
+ GrSWMaskHelper helper;
// Set the matrix so that rendered clip elements are transformed to mask space from clip
// space.
@@ -484,19 +485,14 @@ sk_sp<GrTexture> GrClipStackClip::CreateSoftwareClipMask(GrTextureProvider* texP
}
}
- // Allocate clip mask texture
- GrSurfaceDesc desc;
- desc.fWidth = reducedClip.width();
- desc.fHeight = reducedClip.height();
- desc.fConfig = kAlpha_8_GrPixelConfig;
+ sk_sp<GrTextureProxy> result(helper.toTexture(context, SkBackingFit::kApprox));
- sk_sp<GrTexture> result(texProvider->createApproxTexture(desc));
- if (!result) {
+ GrTexture* tex = result->instantiate(context->textureProvider());
+ if (!tex) {
return nullptr;
}
- result->resourcePriv().setUniqueKey(key);
- helper.toTexture(result.get());
+ tex->resourcePriv().setUniqueKey(key);
- return result;
+ return sk_ref_sp(tex);
}
diff --git a/src/gpu/GrClipStackClip.h b/src/gpu/GrClipStackClip.h
index 42bd373b09..f5b8411169 100644
--- a/src/gpu/GrClipStackClip.h
+++ b/src/gpu/GrClipStackClip.h
@@ -54,7 +54,7 @@ private:
static sk_sp<GrTexture> CreateAlphaClipMask(GrContext*, const GrReducedClip&);
// Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture.
- static sk_sp<GrTexture> CreateSoftwareClipMask(GrTextureProvider*, const GrReducedClip&);
+ static sk_sp<GrTexture> CreateSoftwareClipMask(GrContext*, const GrReducedClip&);
static bool UseSWOnlyPath(GrContext*,
bool hasUserStencilSettings,
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 7dd01defe9..65503420c9 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -593,6 +593,23 @@ void GrContext::flushSurfaceIO(GrSurface* surface) {
}
}
+sk_sp<GrSurfaceContext> GrContextPriv::makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc,
+ SkBackingFit fit,
+ SkBudgeted isDstBudgeted) {
+
+ sk_sp<GrSurfaceProxy> proxy = GrSurfaceProxy::MakeDeferred(*fContext->caps(), dstDesc,
+ fit, isDstBudgeted);
+
+ if (proxy->asRenderTargetProxy()) {
+ return this->drawingManager()->makeRenderTargetContext(std::move(proxy), nullptr, nullptr);
+ } else {
+ SkASSERT(proxy->asTextureProxy());
+ return this->drawingManager()->makeTextureContext(std::move(proxy));
+ }
+
+ return nullptr;
+}
+
////////////////////////////////////////////////////////////////////////////////
int GrContext::getRecommendedSampleCount(GrPixelConfig config,
SkScalar dpi) const {
@@ -639,7 +656,7 @@ sk_sp<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext(sk_sp<GrSurface
}
sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContext(
- const GrBackendTextureDesc& desc,
+ const GrBackendTextureDesc& desc,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props,
GrWrapOwnership ownership) {
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index dcf0807507..7d7cbb0e52 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -26,6 +26,10 @@ public:
// Create a surfaceContext that wraps an existing texture or renderTarget
sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurface> tex);
+ sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc,
+ SkBackingFit dstFit,
+ SkBudgeted isDstBudgeted);
+
sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
const GrBackendTextureDesc& desc,
sk_sp<SkColorSpace> colorSpace,
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index f90678a3c2..00653908fc 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -9,10 +9,13 @@
#include "GrCaps.h"
#include "GrContext.h"
+#include "GrContextPriv.h"
#include "batches/GrDrawOp.h"
#include "GrRenderTargetContext.h"
#include "GrPipelineBuilder.h"
#include "GrShape.h"
+#include "GrSurfaceContext.h"
+#include "GrTextureProxy.h"
#include "SkDistanceFieldGen.h"
@@ -94,33 +97,30 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds, const SkMatrix* matrix) {
return true;
}
-/**
- * Get a texture (from the texture cache) of the correct size & format.
- */
-GrTexture* GrSWMaskHelper::createTexture(SkBackingFit fit) {
+sk_sp<GrTextureProxy> GrSWMaskHelper::toTexture(GrContext* context, SkBackingFit fit) {
GrSurfaceDesc desc;
desc.fWidth = fPixels.width();
desc.fHeight = fPixels.height();
desc.fConfig = kAlpha_8_GrPixelConfig;
- if (SkBackingFit::kApprox == fit) {
- return fTexProvider->createApproxTexture(desc);
- } else {
- return fTexProvider->createTexture(desc, SkBudgeted::kYes);
+ sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeDeferredSurfaceContext(
+ desc,
+ fit,
+ SkBudgeted::kYes);
+ if (!sContext || !sContext->asDeferredTexture()) {
+ return nullptr;
}
-}
-/**
- * Move the result of the software mask generation back to the gpu
- */
-void GrSWMaskHelper::toTexture(GrTexture *texture) {
- // Since we're uploading to it, and it's compressed, 'texture' shouldn't
- // have a render target.
- SkASSERT(!texture->asRenderTarget());
+ // TODO: can skip this step when writePixels is moved
+ GrTexture* tex = sContext->asDeferredTexture()->instantiate(context->textureProvider());
+ if (!tex) {
+ return nullptr;
+ }
- texture->writePixels(0, 0, fPixels.width(), fPixels.height(), texture->config(),
- fPixels.addr(), fPixels.rowBytes());
+ tex->writePixels(0, 0, fPixels.width(), fPixels.height(), kAlpha_8_GrPixelConfig,
+ fPixels.addr(), fPixels.rowBytes());
+ return sk_ref_sp(sContext->asDeferredTexture());
}
/**
@@ -136,13 +136,13 @@ void GrSWMaskHelper::toSDF(unsigned char* sdf) {
* Software rasterizes shape to A8 mask and uploads the result to a scratch texture. Returns the
* resulting texture on success; nullptr on failure.
*/
-GrTexture* GrSWMaskHelper::DrawShapeMaskToTexture(GrTextureProvider* texProvider,
- const GrShape& shape,
- const SkIRect& resultBounds,
- GrAA aa,
- SkBackingFit fit,
- const SkMatrix* matrix) {
- GrSWMaskHelper helper(texProvider);
+sk_sp<GrTexture> GrSWMaskHelper::DrawShapeMaskToTexture(GrContext* context,
+ const GrShape& shape,
+ const SkIRect& resultBounds,
+ GrAA aa,
+ SkBackingFit fit,
+ const SkMatrix* matrix) {
+ GrSWMaskHelper helper;
if (!helper.init(resultBounds, matrix)) {
return nullptr;
@@ -150,14 +150,12 @@ GrTexture* GrSWMaskHelper::DrawShapeMaskToTexture(GrTextureProvider* texProvider
helper.drawShape(shape, SkRegion::kReplace_Op, aa, 0xFF);
- GrTexture* texture(helper.createTexture(fit));
- if (!texture) {
+ sk_sp<GrTextureProxy> tProxy = helper.toTexture(context, fit);
+ if (!tProxy) {
return nullptr;
}
- helper.toTexture(texture);
-
- return texture;
+ return sk_ref_sp(tProxy->instantiate(context->textureProvider()));
}
void GrSWMaskHelper::DrawToTargetWithShapeMask(GrTexture* texture,
diff --git a/src/gpu/GrSWMaskHelper.h b/src/gpu/GrSWMaskHelper.h
index 55ed3ff2e5..6ec1c821fd 100644
--- a/src/gpu/GrSWMaskHelper.h
+++ b/src/gpu/GrSWMaskHelper.h
@@ -43,7 +43,7 @@ struct GrUserStencilSettings;
*/
class GrSWMaskHelper : SkNoncopyable {
public:
- GrSWMaskHelper(GrTextureProvider* texProvider) : fTexProvider(texProvider) { }
+ GrSWMaskHelper() { }
// set up the internal state in preparation for draws. Since many masks
// may be accumulated in the helper during creation, "resultBounds"
@@ -57,8 +57,7 @@ public:
// Draw a single path into the accumuation bitmap using the specified op
void drawShape(const GrShape&, SkRegion::Op op, GrAA, uint8_t alpha);
- // Move the mask generation results from the internal bitmap to the gpu.
- void toTexture(GrTexture* texture);
+ sk_sp<GrTextureProxy> toTexture(GrContext*, SkBackingFit fit);
// Convert mask generation results to a signed distance field
void toSDF(unsigned char* sdf);
@@ -70,12 +69,12 @@ public:
// Canonical usage utility that draws a single path and uploads it
// to the GPU. The result is returned.
- static GrTexture* DrawShapeMaskToTexture(GrTextureProvider*,
- const GrShape&,
- const SkIRect& resultBounds,
- GrAA,
- SkBackingFit,
- const SkMatrix* matrix);
+ static sk_sp<GrTexture> DrawShapeMaskToTexture(GrContext*,
+ const GrShape&,
+ const SkIRect& resultBounds,
+ GrAA,
+ SkBackingFit,
+ const SkMatrix* matrix);
// This utility draws a path mask generated by DrawShapeMaskToTexture using a provided paint.
// The rectangle is drawn in device space. The 'viewMatrix' will be used to ensure the correct
@@ -90,11 +89,6 @@ public:
const SkIRect& deviceSpaceRectToDraw);
private:
- // Helper function to get a scratch texture suitable for capturing the
- // result (i.e., right size & format)
- GrTexture* createTexture(SkBackingFit);
-
- GrTextureProvider* fTexProvider;
SkMatrix fMatrix;
SkAutoPixmapStorage fPixels;
SkDraw fDraw;
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
index d6db0dfdd2..12a753df73 100644
--- a/src/gpu/GrSoftwarePathRenderer.cpp
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -11,6 +11,7 @@
#include "GrPipelineBuilder.h"
#include "GrGpuResourcePriv.h"
#include "GrSWMaskHelper.h"
+#include "GrSurfaceContextPriv.h"
#include "GrTextureProvider.h"
#include "batches/GrRectBatchFactory.h"
@@ -203,9 +204,10 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
if (!texture) {
SkBackingFit fit = useCache ? SkBackingFit::kExact : SkBackingFit::kApprox;
GrAA aa = GrAAType::kCoverage == args.fAAType ? GrAA::kYes : GrAA::kNo;
- texture.reset(GrSWMaskHelper::DrawShapeMaskToTexture(fTexProvider, *args.fShape,
- *boundsForMask, aa,
- fit, args.fViewMatrix));
+ GrContext* context = args.fRenderTargetContext->surfPriv().getContext();
+ texture = GrSWMaskHelper::DrawShapeMaskToTexture(context, *args.fShape,
+ *boundsForMask, aa,
+ fit, args.fViewMatrix);
if (!texture) {
return false;
}
diff --git a/src/gpu/GrSurfaceContextPriv.h b/src/gpu/GrSurfaceContextPriv.h
new file mode 100644
index 0000000000..bd3d2de217
--- /dev/null
+++ b/src/gpu/GrSurfaceContextPriv.h
@@ -0,0 +1,45 @@
+/*
+ * 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 GrSurfaceContextPriv_DEFINED
+#define GrSurfaceContextPriv_DEFINED
+
+#include "GrSurfaceContext.h"
+
+/** Class that adds methods to GrSurfaceContext that are only intended for use internal to
+ Skia. This class is purely a privileged window into GrSurfaceContext. It should never have
+ additional data members or virtual methods. */
+class GrSurfaceContextPriv {
+public:
+ GrContext* getContext() { return fSurfaceContext->fContext; }
+
+private:
+ explicit GrSurfaceContextPriv(GrSurfaceContext* surfaceContext)
+ : fSurfaceContext(surfaceContext) {
+ }
+
+ GrSurfaceContextPriv(const GrSurfaceContextPriv&) {} // unimpl
+ GrSurfaceContextPriv& operator=(const GrSurfaceContextPriv&); // unimpl
+
+ // No taking addresses of this type.
+ const GrSurfaceContextPriv* operator&() const;
+ GrSurfaceContextPriv* operator&();
+
+ GrSurfaceContext* fSurfaceContext;
+
+ friend class GrSurfaceContext; // to construct/copy this type.
+};
+
+inline GrSurfaceContextPriv GrSurfaceContext::surfPriv() {
+ return GrSurfaceContextPriv(this);
+}
+
+inline const GrSurfaceContextPriv GrSurfaceContext::surfPriv() const {
+ return GrSurfaceContextPriv(const_cast<GrSurfaceContext*>(this));
+}
+
+#endif