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

Unified Diff: gpu/command_buffer/client/gles2_implementation.cc

Issue 2252163003: Update Context Client Visibility to use Scoped Pattern (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 4 years, 4 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: gpu/command_buffer/client/gles2_implementation.cc
diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc
index d2f959c11b23f2ce34f6cd3c01ac053595704877..db71bcd1109d7ab7323463eeee05c82d7c3c2eb1 100644
--- a/gpu/command_buffer/client/gles2_implementation.cc
+++ b/gpu/command_buffer/client/gles2_implementation.cc
@@ -19,6 +19,7 @@
#include <string>
#include "base/atomic_sequence_num.h"
#include "base/compiler_specific.h"
+#include "base/memory/ptr_util.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
@@ -51,6 +52,22 @@ namespace gles2 {
namespace {
+class ScopedVisibilityImpl : public ContextSupport::ScopedVisibility {
+ public:
+ explicit ScopedVisibilityImpl(ContextSupport* context_support)
+ : initial_context_support_(context_support) {}
+ ~ScopedVisibilityImpl() { DCHECK(!initial_context_support_); }
+
+ void Release(ContextSupport* context_support) {
+ DCHECK_EQ(initial_context_support_, context_support);
+ initial_context_support_ = nullptr;
+ }
+
+ private:
+ // |initial_context_support_| is just stored/used for sanity-checking Release.
danakj 2016/08/19 18:29:55 Update comment
ericrk 2016/08/19 18:49:58 Done.
+ const ContextSupport* initial_context_support_;
+};
+
void CopyRectToBuffer(const void* pixels,
uint32_t height,
uint32_t unpadded_row_size,
@@ -164,7 +181,6 @@ GLES2Implementation::GLES2Implementation(
current_trace_stack_(0),
gpu_control_(gpu_control),
capabilities_(gpu_control->GetCapabilities()),
- aggressively_free_resources_(false),
cached_extension_string_(nullptr),
weak_ptr_factory_(this) {
DCHECK(helper);
@@ -5861,18 +5877,21 @@ void GLES2Implementation::SetErrorMessageCallback(
error_message_callback_ = callback;
}
-void GLES2Implementation::SetClientVisible(int client_id, bool is_visible) {
- if (is_visible) {
- visible_clients_.insert(client_id);
- } else {
- auto found = visible_clients_.find(client_id);
- if (found != visible_clients_.end())
- visible_clients_.erase(found);
- }
+std::unique_ptr<ContextSupport::ScopedVisibility>
+GLES2Implementation::ClientBecameVisible() {
+ ++num_visible_clients_;
+ return base::MakeUnique<ScopedVisibilityImpl>(this);
+}
+
+void GLES2Implementation::ClientBecameNotVisible(
+ std::unique_ptr<ScopedVisibility> visibility) {
+ DCHECK_GT(num_visible_clients_, 0u);
danakj 2016/08/19 18:29:55 can you DCHECK(visibility) too? (same for the Test
ericrk 2016/08/19 18:49:58 Done.
+ --num_visible_clients_;
+ static_cast<ScopedVisibilityImpl*>(visibility.get())->Release(this);
}
bool GLES2Implementation::AnyClientsVisible() const {
- return !visible_clients_.empty();
+ return num_visible_clients_ > 0;
}
void GLES2Implementation::SetLostContextCallback(

Powered by Google App Engine
This is Rietveld 408576698