aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-08-03 14:26:53 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-03 14:26:53 -0700
commit4fd74aec9f6c68c66483bcc6735793440b1ba184 (patch)
tree2dc927157414e8393d1e31dff5c3fbcd873a883d /src/gpu
parent4db3b7969f62f5ddbf32bd812b9510af018ece89 (diff)
Move GrContext::makeDrawContext to new GrContextPriv object
We don't want external clients to be able to call the wrapping makeDrawContext. The "creating" makeDrawContext needs to be public for external image filters. The 3 specialized drawContext creators on GrContextPriv (to wrap backend objects) are also to be kept from public use and will be used to remove SkSurface::MakeRenderTargetDirect. Split out of: https://codereview.chromium.org/2176333002/ (Remove SkSurface::MakeRenderTargetDirect) TBR=bsalomon@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2211473002 Review-Url: https://codereview.chromium.org/2211473002
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrContext.cpp71
-rw-r--r--src/gpu/GrContextPriv.h57
-rw-r--r--src/gpu/GrRenderTarget.cpp4
-rw-r--r--src/gpu/SkGpuDevice.cpp7
4 files changed, 128 insertions, 11 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 078cfbdb2c..94ad9644bc 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -6,6 +6,7 @@
*/
#include "GrContext.h"
+#include "GrContextPriv.h"
#include "GrContextOptions.h"
#include "GrDrawingManager.h"
#include "GrDrawContext.h"
@@ -25,6 +26,8 @@
#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
#define ASSERT_SINGLE_OWNER \
SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fSingleOwner);)
+#define ASSERT_SINGLE_OWNER_PRIV \
+ SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fContext->fSingleOwner);)
#define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return; }
#define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; }
#define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; }
@@ -360,7 +363,9 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
// TODO: Need to decide the semantics of this function for color spaces. Do we support
// conversion from a passed-in color space? For now, specifying nullptr means that this
// path will do no conversion, so it will match the behavior of the non-draw path.
- sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(renderTarget), nullptr));
+ sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDrawContext(
+ sk_ref_sp(renderTarget),
+ nullptr));
if (!drawContext) {
return false;
}
@@ -568,7 +573,9 @@ bool GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
src->flushWrites();
return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint);
}
- sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(dst->asRenderTarget()), nullptr));
+ sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDrawContext(
+ sk_ref_sp(dst->asRenderTarget()),
+ nullptr));
if (!drawContext) {
return false;
}
@@ -606,12 +613,59 @@ int GrContext::getRecommendedSampleCount(GrPixelConfig config,
return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCount : 0;
}
+sk_sp<GrDrawContext> GrContextPriv::makeWrappedDrawContext(sk_sp<GrRenderTarget> rt,
+ sk_sp<SkColorSpace> colorSpace,
+ const SkSurfaceProps* surfaceProps) {
+ ASSERT_SINGLE_OWNER_PRIV
+ return fContext->drawingManager()->drawContext(std::move(rt), std::move(colorSpace),
+ surfaceProps);
+}
-sk_sp<GrDrawContext> GrContext::makeDrawContext(sk_sp<GrRenderTarget> rt,
- sk_sp<SkColorSpace> colorSpace,
- const SkSurfaceProps* surfaceProps) {
- ASSERT_SINGLE_OWNER
- return fDrawingManager->drawContext(std::move(rt), std::move(colorSpace), surfaceProps);
+sk_sp<GrDrawContext> GrContextPriv::makeBackendTextureDrawContext(const GrBackendTextureDesc& desc,
+ sk_sp<SkColorSpace> colorSpace,
+ const SkSurfaceProps* props,
+ GrWrapOwnership ownership) {
+ ASSERT_SINGLE_OWNER_PRIV
+ SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag);
+
+ sk_sp<GrSurface> surface(fContext->textureProvider()->wrapBackendTexture(desc, ownership));
+ if (!surface) {
+ return nullptr;
+ }
+
+ return fContext->drawingManager()->drawContext(sk_ref_sp(surface->asRenderTarget()),
+ std::move(colorSpace), props);
+}
+
+sk_sp<GrDrawContext> GrContextPriv::makeBackendRenderTargetDrawContext(
+ const GrBackendRenderTargetDesc& desc,
+ sk_sp<SkColorSpace> colorSpace,
+ const SkSurfaceProps* surfaceProps) {
+ ASSERT_SINGLE_OWNER_PRIV
+
+ sk_sp<GrRenderTarget> rt(fContext->textureProvider()->wrapBackendRenderTarget(desc));
+ if (!rt) {
+ return nullptr;
+ }
+
+ return fContext->drawingManager()->drawContext(std::move(rt), std::move(colorSpace),
+ surfaceProps);
+}
+
+sk_sp<GrDrawContext> GrContextPriv::makeBackendTextureAsRenderTargetDrawContext(
+ const GrBackendTextureDesc& desc,
+ sk_sp<SkColorSpace> colorSpace,
+ const SkSurfaceProps* surfaceProps) {
+ ASSERT_SINGLE_OWNER_PRIV
+ SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag);
+
+ sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTextureAsRenderTarget(desc));
+ if (!surface) {
+ return nullptr;
+ }
+
+ return fContext->drawingManager()->drawContext(sk_ref_sp(surface->asRenderTarget()),
+ std::move(colorSpace), surfaceProps);
}
sk_sp<GrDrawContext> GrContext::makeDrawContext(SkBackingFit fit,
@@ -640,7 +694,8 @@ sk_sp<GrDrawContext> GrContext::makeDrawContext(SkBackingFit fit,
return nullptr;
}
- sk_sp<GrDrawContext> drawContext(this->makeDrawContext(sk_ref_sp(tex->asRenderTarget()),
+ sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDrawContext(
+ sk_ref_sp(tex->asRenderTarget()),
std::move(colorSpace), surfaceProps));
if (!drawContext) {
return nullptr;
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
new file mode 100644
index 0000000000..8646e25d49
--- /dev/null
+++ b/src/gpu/GrContextPriv.h
@@ -0,0 +1,57 @@
+/*
+ * 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 GrContextPriv_DEFINED
+#define GrContextPriv_DEFINED
+
+#include "GrContext.h"
+
+/** Class that adds methods to GrContext that are only intended for use internal to Skia.
+ This class is purely a privileged window into GrContext. It should never have additional
+ data members or virtual methods. */
+class GrContextPriv {
+public:
+ // Create a drawContext that wraps an existing renderTarget
+ sk_sp<GrDrawContext> makeWrappedDrawContext(sk_sp<GrRenderTarget> rt,
+ sk_sp<SkColorSpace> colorSpace,
+ const SkSurfaceProps* = nullptr);
+
+ sk_sp<GrDrawContext> makeBackendTextureDrawContext(const GrBackendTextureDesc& desc,
+ sk_sp<SkColorSpace> colorSpace,
+ const SkSurfaceProps* = nullptr,
+ GrWrapOwnership = kBorrow_GrWrapOwnership);
+
+ sk_sp<GrDrawContext> makeBackendRenderTargetDrawContext(const GrBackendRenderTargetDesc& desc,
+ sk_sp<SkColorSpace> colorSpace,
+ const SkSurfaceProps* = nullptr);
+
+ sk_sp<GrDrawContext> makeBackendTextureAsRenderTargetDrawContext(
+ const GrBackendTextureDesc& desc,
+ sk_sp<SkColorSpace> colorSpace,
+ const SkSurfaceProps* = nullptr);
+
+private:
+ explicit GrContextPriv(GrContext* context) : fContext(context) {}
+ GrContextPriv(const GrContextPriv&) {} // unimpl
+ GrContextPriv& operator=(const GrContextPriv&); // unimpl
+
+ // No taking addresses of this type.
+ const GrContextPriv* operator&() const;
+ GrContextPriv* operator&();
+
+ GrContext* fContext;
+
+ friend class GrContext; // to construct/copy this type.
+};
+
+inline GrContextPriv GrContext::contextPriv() { return GrContextPriv(this); }
+
+inline const GrContextPriv GrContext::contextPriv () const {
+ return GrContextPriv(const_cast<GrContext*>(this));
+}
+
+#endif
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index cccf9534f6..a0700a095f 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -9,6 +9,7 @@
#include "GrRenderTarget.h"
#include "GrContext.h"
+#include "GrContextPriv.h"
#include "GrDrawContext.h"
#include "GrDrawTarget.h"
#include "GrGpu.h"
@@ -29,7 +30,8 @@ void GrRenderTarget::discard() {
return;
}
- sk_sp<GrDrawContext> drawContext(context->makeDrawContext(sk_ref_sp(this), nullptr));
+ sk_sp<GrDrawContext> drawContext(context->contextPriv().makeWrappedDrawContext(sk_ref_sp(this),
+ nullptr));
if (!drawContext) {
return;
}
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 7271819269..82038f6232 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -9,6 +9,7 @@
#include "GrBlurUtils.h"
#include "GrContext.h"
+#include "GrContextPriv.h"
#include "SkDraw.h"
#include "GrGpu.h"
#include "GrGpuResourcePriv.h"
@@ -104,8 +105,10 @@ sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, sk_sp<SkColorSpac
GrContext* context = rt->getContext();
- sk_sp<GrDrawContext> drawContext(context->makeDrawContext(std::move(rt), std::move(colorSpace),
- props));
+ sk_sp<GrDrawContext> drawContext(context->contextPriv().makeWrappedDrawContext(
+ std::move(rt),
+ std::move(colorSpace),
+ props));
return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), width, height, flags));
}