aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2016-11-08 13:49:39 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-08 13:49:49 +0000
commiteaa862569dc91d55fc79d057df6e69b139e46888 (patch)
tree49c648f32f78e3f625b9338d675bd8fbcf340c1e
parent283eb302330e9b9a2f144f341ec12cac54590ebf (diff)
Revert "Revert "Add GrRenderTargetContext instantiate & asTextureProxy""
This reverts commit 7d7d7d19462b75f5470492dc4820a02c1eba4af2. Reason for revert: Reverting this to see if it really was crashing on SVGs or if that was cross talk. Original change's description: > Revert "Add GrRenderTargetContext instantiate & asTextureProxy" > > This reverts commit 9113edfff89e657dabc0ba095c54f7720550196c. > > Reason for revert: Looks to be causing EXCEPTION_ACCESS_VIOLATION: > > https://uberchromegw.corp.google.com/i/client.skia/builders/Test-Win-MSVC-NUC-GPU-IntelIris6100-x86_64-Debug/builds/121/steps/test_skia%20on%20Windows/logs/stdio > https://uberchromegw.corp.google.com/i/client.skia/builders/Test-Win-MSVC-GCE-CPU-AVX2-x86-Debug/builds/2384/steps/test_skia%20on%20Windows-2008ServerR2-SP1/logs/stdio > https://uberchromegw.corp.google.com/i/client.skia/builders/Test-Win-MSVC-ShuttleC-GPU-iHD530-x86_64-Debug/builds/785/steps/test_skia%20on%20Windows/logs/stdio > > Original change's description: > > Add GrRenderTargetContext instantiate & asTextureProxy > > > > This CL also centralizes the instantiation code in GrSurfaceProxy and adds a test. > > > > GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4494 > > > > Change-Id: I0081d9a216dc0af293179f23bcb88acf6a822324 > > Reviewed-on: https://skia-review.googlesource.com/4494 > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Robert Phillips <robertphillips@google.com> > > > > TBR=bsalomon@google.com,robertphillips@google.com,reviews@skia.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Change-Id: I225ce7867ebd445067e5ea55ebbfd587f7fe782a > Reviewed-on: https://skia-review.googlesource.com/4528 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Leon Scroggins <scroggo@google.com> > TBR=bsalomon@google.com,robertphillips@google.com,scroggo@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: Ifc3b9ac343009a3808f5f47500eef50df438e3d9 Reviewed-on: https://skia-review.googlesource.com/4537 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
-rw-r--r--gn/tests.gni1
-rw-r--r--include/gpu/GrRenderTargetContext.h10
-rw-r--r--include/private/GrRenderTargetProxy.h1
-rw-r--r--include/private/GrSurfaceProxy.h5
-rw-r--r--include/private/GrTextureProxy.h1
-rw-r--r--src/gpu/GrRenderTargetContext.cpp8
-rw-r--r--src/gpu/GrRenderTargetProxy.cpp26
-rw-r--r--src/gpu/GrSurfaceProxy.cpp24
-rw-r--r--src/gpu/GrTextureProxy.cpp17
-rw-r--r--tests/RenderTargetContextTest.cpp100
-rw-r--r--tools/gpu/GrTest.cpp8
11 files changed, 162 insertions, 39 deletions
diff --git a/gn/tests.gni b/gn/tests.gni
index 135c3ce412..4fa653a037 100644
--- a/gn/tests.gni
+++ b/gn/tests.gni
@@ -173,6 +173,7 @@ tests_sources = [
"$_tests/RefCntTest.cpp",
"$_tests/RefDictTest.cpp",
"$_tests/RegionTest.cpp",
+ "$_tests/RenderTargetContextTest.cpp",
"$_tests/ResourceCacheTest.cpp",
"$_tests/RoundRectTest.cpp",
"$_tests/RRectInPathTest.cpp",
diff --git a/include/gpu/GrRenderTargetContext.h b/include/gpu/GrRenderTargetContext.h
index f728ef15b2..95d8c9d463 100644
--- a/include/gpu/GrRenderTargetContext.h
+++ b/include/gpu/GrRenderTargetContext.h
@@ -33,6 +33,7 @@ class GrRenderTarget;
class GrRenderTargetOpList;
class GrStyle;
class GrSurface;
+class GrTextureProxy;
struct GrUserStencilSettings;
class SkDrawFilter;
struct SkIPoint;
@@ -342,17 +343,20 @@ public:
bool wasAbandoned() const;
+ GrRenderTarget* instantiate();
+
GrRenderTarget* accessRenderTarget() {
// TODO: usage of this entry point needs to be reduced and potentially eliminated
// since it ends the deferral of the GrRenderTarget's allocation
return fRenderTargetProxy->instantiate(fContext->textureProvider());
}
+ GrTextureProxy* asDeferredTexture();
+
sk_sp<GrTexture> asTexture() {
// TODO: usage of this entry point needs to be reduced and potentially eliminated
// since it ends the deferral of the GrRenderTarget's allocation
- // It's usage should migrate to the soon-to-be-added asDeferredTexture which
- // returns a GrTextureProxy
+ // It's usage should migrate to asDeferredTexture
return sk_ref_sp(this->accessRenderTarget()->asTexture());
}
@@ -362,6 +366,8 @@ public:
GrAuditTrail* auditTrail() { return fAuditTrail; }
+ bool isWrapped_ForTesting() const;
+
protected:
GrRenderTargetContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTargetProxy>,
sk_sp<SkColorSpace>, const SkSurfaceProps* surfaceProps, GrAuditTrail*,
diff --git a/include/private/GrRenderTargetProxy.h b/include/private/GrRenderTargetProxy.h
index 3bad9df9e4..267d7549e3 100644
--- a/include/private/GrRenderTargetProxy.h
+++ b/include/private/GrRenderTargetProxy.h
@@ -27,7 +27,6 @@ public:
SkBackingFit, SkBudgeted);
static sk_sp<GrRenderTargetProxy> Make(sk_sp<GrRenderTarget>);
- // TODO: add asTextureProxy variants
GrRenderTargetProxy* asRenderTargetProxy() override { return this; }
const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; }
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h
index e748853cfd..539aaf65aa 100644
--- a/include/private/GrSurfaceProxy.h
+++ b/include/private/GrSurfaceProxy.h
@@ -13,6 +13,7 @@
#include "SkRect.h"
class GrOpList;
+class GrTextureProvider;
class GrTextureProxy;
class GrRenderTargetProxy;
@@ -127,6 +128,8 @@ public:
return fGpuMemorySize;
}
+ bool isWrapped_ForTesting() const;
+
protected:
// Deferred version
GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted)
@@ -143,6 +146,8 @@ protected:
virtual ~GrSurfaceProxy();
+ GrSurface* instantiate(GrTextureProvider* texProvider);
+
// For wrapped resources, 'fDesc' will always be filled in from the wrapped resource.
const GrSurfaceDesc fDesc;
const SkBackingFit fFit; // always exact for wrapped resources
diff --git a/include/private/GrTextureProxy.h b/include/private/GrTextureProxy.h
index e68ef8896a..75f09de800 100644
--- a/include/private/GrTextureProxy.h
+++ b/include/private/GrTextureProxy.h
@@ -24,7 +24,6 @@ public:
const void* srcData = nullptr, size_t rowBytes = 0);
static sk_sp<GrTextureProxy> Make(sk_sp<GrTexture>);
- // TODO: add asRenderTargetProxy variants
GrTextureProxy* asTextureProxy() override { return this; }
const GrTextureProxy* asTextureProxy() const override { return this; }
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index f1f17b03ea..4c86cbc464 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -117,6 +117,14 @@ GrRenderTargetContext::~GrRenderTargetContext() {
SkSafeUnref(fOpList);
}
+GrRenderTarget* GrRenderTargetContext::instantiate() {
+ return fRenderTargetProxy->instantiate(fContext->textureProvider());
+}
+
+GrTextureProxy* GrRenderTargetContext::asDeferredTexture() {
+ return fRenderTargetProxy->asTextureProxy();
+}
+
GrRenderTargetOpList* GrRenderTargetContext::getOpList() {
ASSERT_SINGLE_OWNER
SkDEBUGCODE(this->validate();)
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
index f428a0fb73..fcc5275002 100644
--- a/src/gpu/GrRenderTargetProxy.cpp
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -37,33 +37,17 @@ GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrRenderTarget> rt)
}
GrRenderTarget* GrRenderTargetProxy::instantiate(GrTextureProvider* texProvider) {
- if (fTarget) {
- return fTarget->asRenderTarget();
- }
+ SkASSERT(fDesc.fFlags & GrSurfaceFlags::kRenderTarget_GrSurfaceFlag);
- // TODO: it would be nice to not have to copy the desc here
- GrSurfaceDesc desc = fDesc;
- desc.fFlags |= GrSurfaceFlags::kRenderTarget_GrSurfaceFlag;
-
- if (SkBackingFit::kApprox == fFit) {
- fTarget = texProvider->createApproxTexture(desc);
- } else {
- fTarget = texProvider->createTexture(desc, fBudgeted);
- }
- if (!fTarget) {
+ GrSurface* surf = INHERITED::instantiate(texProvider);
+ if (!surf || !surf->asRenderTarget()) {
return nullptr;
}
-#ifdef SK_DEBUG
- if (kInvalidGpuMemorySize != this->getRawGpuMemorySize_debugOnly()) {
- SkASSERT(fTarget->gpuMemorySize() <= this->getRawGpuMemorySize_debugOnly());
- }
-#endif
-
// Check that our a priori computation matched the ultimate reality
- SkASSERT(fFlags == fTarget->asRenderTarget()->renderTargetPriv().flags());
+ SkASSERT(fFlags == surf->asRenderTarget()->renderTargetPriv().flags());
- return fTarget->asRenderTarget();
+ return surf->asRenderTarget();
}
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index c5afd0f262..b6d0e11cbb 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -9,6 +9,7 @@
#include "GrGpuResourcePriv.h"
#include "GrOpList.h"
+#include "GrTextureProvider.h"
GrSurfaceProxy::GrSurfaceProxy(sk_sp<GrSurface> surface, SkBackingFit fit)
: INHERITED(std::move(surface))
@@ -27,6 +28,29 @@ GrSurfaceProxy::~GrSurfaceProxy() {
SkSafeUnref(fLastOpList);
}
+GrSurface* GrSurfaceProxy::instantiate(GrTextureProvider* texProvider) {
+ if (fTarget) {
+ return fTarget;
+ }
+
+ if (SkBackingFit::kApprox == fFit) {
+ fTarget = texProvider->createApproxTexture(fDesc);
+ } else {
+ fTarget = texProvider->createTexture(fDesc, fBudgeted);
+ }
+ if (!fTarget) {
+ return nullptr;
+ }
+
+#ifdef SK_DEBUG
+ if (kInvalidGpuMemorySize != this->getRawGpuMemorySize_debugOnly()) {
+ SkASSERT(fTarget->gpuMemorySize() <= this->getRawGpuMemorySize_debugOnly());
+ }
+#endif
+
+ return fTarget;
+}
+
void GrSurfaceProxy::setLastOpList(GrOpList* opList) {
if (fLastOpList) {
// The non-MDB world never closes so we can't check this condition
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp
index ca773b3eaf..5fe43f7125 100644
--- a/src/gpu/GrTextureProxy.cpp
+++ b/src/gpu/GrTextureProxy.cpp
@@ -21,21 +21,10 @@ GrTextureProxy::GrTextureProxy(sk_sp<GrTexture> tex)
}
GrTexture* GrTextureProxy::instantiate(GrTextureProvider* texProvider) {
- if (fTarget) {
- return fTarget->asTexture();
- }
-
- if (SkBackingFit::kApprox == fFit) {
- fTarget = texProvider->createApproxTexture(fDesc);
- } else {
- fTarget = texProvider->createTexture(fDesc, fBudgeted);
- }
-
-#ifdef SK_DEBUG
- if (kInvalidGpuMemorySize != this->getRawGpuMemorySize_debugOnly()) {
- SkASSERT(fTarget->gpuMemorySize() <= this->getRawGpuMemorySize_debugOnly());
+ GrSurface* surf = this->INHERITED::instantiate(texProvider);
+ if (!surf) {
+ return nullptr;
}
-#endif
return fTarget->asTexture();
}
diff --git a/tests/RenderTargetContextTest.cpp b/tests/RenderTargetContextTest.cpp
new file mode 100644
index 0000000000..9a4b8747da
--- /dev/null
+++ b/tests/RenderTargetContextTest.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// This is a GPU-backend specific test.
+
+#include "Test.h"
+
+#if SK_SUPPORT_GPU
+#include "GrTextureProxy.h"
+#include "GrRenderTargetContext.h"
+
+static const int kSize = 64;
+
+static sk_sp<GrRenderTargetContext> get_rtc(GrContext* ctx, bool wrapped) {
+
+ if (wrapped) {
+ return ctx->makeRenderTargetContext(SkBackingFit::kExact,
+ kSize, kSize,
+ kRGBA_8888_GrPixelConfig, nullptr);
+ } else {
+ return ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact,
+ kSize, kSize,
+ kRGBA_8888_GrPixelConfig, nullptr);
+ }
+}
+
+static void check_is_wrapped_status(skiatest::Reporter* reporter,
+ GrRenderTargetContext* rtCtx,
+ bool wrappedExpectation) {
+ REPORTER_ASSERT(reporter, rtCtx->isWrapped_ForTesting() == wrappedExpectation);
+
+ GrTextureProxy* tProxy = rtCtx->asDeferredTexture();
+ REPORTER_ASSERT(reporter, tProxy);
+
+ REPORTER_ASSERT(reporter, tProxy->isWrapped_ForTesting() == wrappedExpectation);
+}
+
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) {
+ GrContext* ctx = ctxInfo.grContext();
+
+ // A wrapped rtCtx's textureProxy is also wrapped
+ {
+ sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx, true));
+ check_is_wrapped_status(reporter, rtCtx.get(), true);
+ }
+
+ // A deferred rtCtx's textureProxy is also deferred and GrRenderTargetContext::instantiate()
+ // swaps both from deferred to wrapped
+ {
+ sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx, false));
+
+ check_is_wrapped_status(reporter, rtCtx.get(), false);
+
+ GrRenderTarget* rt = rtCtx->instantiate();
+ REPORTER_ASSERT(reporter, rt);
+
+ check_is_wrapped_status(reporter, rtCtx.get(), true);
+ }
+
+ // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the
+ // GrRenderTargetContext
+ {
+ sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx, false));
+
+ check_is_wrapped_status(reporter, rtCtx.get(), false);
+
+ GrTextureProxy* tProxy = rtCtx->asDeferredTexture();
+ REPORTER_ASSERT(reporter, tProxy);
+
+ GrTexture* tex = tProxy->instantiate(ctx->textureProvider());
+ REPORTER_ASSERT(reporter, tex);
+
+ check_is_wrapped_status(reporter, rtCtx.get(), true);
+ }
+
+ // readPixels switches a deferred rtCtx to wrapped
+ {
+ sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx, false));
+
+ check_is_wrapped_status(reporter, rtCtx.get(), false);
+
+ SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize);
+ SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize);
+ static const size_t kRowBytes = sizeof(uint32_t) * kSize;
+
+ bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, 0, 0);
+ REPORTER_ASSERT(reporter, result);
+
+ check_is_wrapped_status(reporter, rtCtx.get(), true);
+ }
+
+ // TODO: in a future world we should be able to add a test that the majority of
+ // GrRenderTargetContext calls do not force the instantiation of a deferred
+ // GrRenderTargetContext
+}
+#endif
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index ba870ea25e..8574399d74 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -62,6 +62,14 @@ void GrTestTarget::init(GrContext* ctx, sk_sp<GrRenderTargetContext> renderTarge
fRenderTargetContext = renderTargetContext;
}
+bool GrSurfaceProxy::isWrapped_ForTesting() const {
+ return SkToBool(fTarget);
+}
+
+bool GrRenderTargetContext::isWrapped_ForTesting() const {
+ return fRenderTargetProxy->isWrapped_ForTesting();
+}
+
void GrContext::getTestTarget(GrTestTarget* tar, sk_sp<GrRenderTargetContext> renderTargetContext) {
this->flush();
SkASSERT(renderTargetContext);