Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Unified Diff: src/gpu/GrRenderTargetProxy.cpp

Issue 1937553002: Add Gr*Proxy classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More clean up Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrRenderTargetProxy.cpp
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e4071e5d032f013f9e719d2f44bb343f15142cc2
--- /dev/null
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrRenderTargetProxy.h"
+
+#include "GrDrawTarget.h"
+#include "GrGpuResourcePriv.h"
+#include "GrRenderTargetPriv.h"
+
+GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrRenderTarget> rt)
+ : INHERITED(rt->desc(), kExact_BackingFit, rt->resourcePriv().isBudgeted())
+ , fTarget(std::move(rt))
+ , fSampleConfig(fTarget->renderTargetPriv().sampleConfig())
+ , fLastDrawTarget(nullptr) {
+}
+
+GrRenderTargetProxy::~GrRenderTargetProxy() {
+ if (fLastDrawTarget) {
+ fLastDrawTarget->clearRT();
+ }
+ SkSafeUnref(fLastDrawTarget);
+}
+
+GrRenderTarget* GrRenderTargetProxy::instantiate(GrTextureProvider* texProvider) {
+ if (fTarget) {
+ return fTarget.get();
+ }
+
+ // TODO: it would be nice to not have to copy the desc here
+ GrSurfaceDesc desc = fDesc;
+ desc.fFlags |= GrSurfaceFlags::kRenderTarget_GrSurfaceFlag;
+
+ sk_sp<GrTexture> tex;
+ if (kApprox_BackingFit == fFit) {
+ tex.reset(texProvider->createApproxTexture(desc));
+ } else {
+ tex.reset(texProvider->createTexture(desc, fBudgeted));
+ }
+ if (!tex || !tex->asRenderTarget()) {
+ return nullptr;
+ }
+
+ fTarget.reset(tex->asRenderTarget());
+
+ // Check that our a priori computation matched the ultimate reality
+ SkASSERT(fSampleConfig == fTarget->renderTargetPriv().sampleConfig());
+
+ return fTarget.get();
+}
+
+void GrRenderTargetProxy::setLastDrawTarget(GrDrawTarget* dt) {
+ if (fLastDrawTarget) {
+ // The non-MDB world never closes so we can't check this condition
+#ifdef ENABLE_MDB
+ SkASSERT(fLastDrawTarget->isClosed());
+#endif
+ fLastDrawTarget->clearRT();
+ }
+
+ SkRefCnt_SafeAssign(fLastDrawTarget, dt);
+}
+
+sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(const GrCaps& caps,
+ const GrSurfaceDesc& desc,
+ BackingFit fit,
+ SkBudgeted budgeted) {
+ return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(caps, desc, fit, budgeted));
+}
+
+sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(sk_sp<GrRenderTarget> rt) {
+ return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(rt));
+}
+

Powered by Google App Engine
This is Rietveld 408576698