aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrSurfaceProxyRef.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2018-02-01 09:10:04 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-01 15:00:53 +0000
commit620003692923dc6c6df5a1b66288988b6783a69f (patch)
tree5010067f4d26fb23f28964e74b5e37c38e3dddc3 /src/gpu/GrSurfaceProxyRef.cpp
parent5f9ee7cc53d28c8ff2d000436bfee195c493ccdf (diff)
Implement GPU/OpList DDLs
This relies on https://skia-review.googlesource.com/c/skia/+/102101 (Add SkSurface_Gpu::MakeWrappedRenderTarget method) landing first TBR=bsalomon@google.com Change-Id: I4d2d66af5800407f638ef32d7b19ce49084bd4e4 Reviewed-on: https://skia-review.googlesource.com/102263 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu/GrSurfaceProxyRef.cpp')
-rw-r--r--src/gpu/GrSurfaceProxyRef.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/gpu/GrSurfaceProxyRef.cpp b/src/gpu/GrSurfaceProxyRef.cpp
new file mode 100644
index 0000000000..ad13e4a450
--- /dev/null
+++ b/src/gpu/GrSurfaceProxyRef.cpp
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrSurfaceProxyRef.h"
+#include "GrTextureProxy.h"
+
+GrSurfaceProxyRef::GrSurfaceProxyRef() {
+ fProxy = nullptr;
+ fOwnRef = false;
+ fPendingIO = false;
+}
+
+GrSurfaceProxyRef::GrSurfaceProxyRef(sk_sp<GrSurfaceProxy> proxy, GrIOType ioType) {
+ fProxy = nullptr;
+ fOwnRef = false;
+ fPendingIO = false;
+ this->setProxy(std::move(proxy), ioType);
+}
+
+GrSurfaceProxyRef::~GrSurfaceProxyRef() {
+ this->reset();
+}
+
+void GrSurfaceProxyRef::reset() {
+ if (fPendingIO) {
+ SkASSERT(fProxy);
+ switch (fIOType) {
+ case kRead_GrIOType:
+ fProxy->completedRead();
+ break;
+ case kWrite_GrIOType:
+ fProxy->completedWrite();
+ break;
+ case kRW_GrIOType:
+ fProxy->completedRead();
+ fProxy->completedWrite();
+ break;
+ }
+ fPendingIO = false;
+ }
+ if (fOwnRef) {
+ SkASSERT(fProxy);
+ fProxy->unref();
+ fOwnRef = false;
+ }
+
+ fProxy = nullptr;
+}
+
+void GrSurfaceProxyRef::setProxy(sk_sp<GrSurfaceProxy> proxy, GrIOType ioType) {
+ SkASSERT(!fPendingIO);
+ SkASSERT(SkToBool(fProxy) == fOwnRef);
+ SkSafeUnref(fProxy);
+ if (!proxy) {
+ fProxy = nullptr;
+ fOwnRef = false;
+ } else {
+ fProxy = proxy.release(); // due to the semantics of this class we unpack from sk_sp
+ fOwnRef = true;
+ fIOType = ioType;
+ }
+}
+
+void GrSurfaceProxyRef::markPendingIO() const {
+ // This should only be called when the owning GrProgramElement gets its first
+ // pendingExecution ref.
+ SkASSERT(!fPendingIO);
+ SkASSERT(fProxy);
+ fPendingIO = true;
+ switch (fIOType) {
+ case kRead_GrIOType:
+ fProxy->addPendingRead();
+ break;
+ case kWrite_GrIOType:
+ fProxy->addPendingWrite();
+ break;
+ case kRW_GrIOType:
+ fProxy->addPendingRead();
+ fProxy->addPendingWrite();
+ break;
+ }
+}
+
+void GrSurfaceProxyRef::pendingIOComplete() const {
+ // This should only be called when the owner's pending executions have ocurred but it is still
+ // reffed.
+ SkASSERT(fOwnRef);
+ SkASSERT(fPendingIO);
+ switch (fIOType) {
+ case kRead_GrIOType:
+ fProxy->completedRead();
+ break;
+ case kWrite_GrIOType:
+ fProxy->completedWrite();
+ break;
+ case kRW_GrIOType:
+ fProxy->completedRead();
+ fProxy->completedWrite();
+ break;
+
+ }
+ fPendingIO = false;
+}
+
+void GrSurfaceProxyRef::removeRef() const {
+ // This should only be called once, when the owners last ref goes away and
+ // there is a pending execution.
+ SkASSERT(fOwnRef);
+ SkASSERT(fPendingIO);
+ SkASSERT(fProxy);
+ fProxy->unref();
+ fOwnRef = false;
+}
+