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

Unified Diff: gpu/ipc/common/activity_flags.cc

Issue 2744363002: Clear shader disk cache after glProgramBinary failure. (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « gpu/ipc/common/activity_flags.h ('k') | gpu/ipc/common/activity_flags_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/ipc/common/activity_flags.cc
diff --git a/gpu/ipc/common/activity_flags.cc b/gpu/ipc/common/activity_flags.cc
new file mode 100644
index 0000000000000000000000000000000000000000..42dbfef95c555abb8a802149b422acc0ba2c5932
--- /dev/null
+++ b/gpu/ipc/common/activity_flags.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gpu/ipc/common/activity_flags.h"
+
+#include "base/memory/singleton.h"
+
+namespace gpu {
+
+ActivityFlagsBase::ActivityFlagsBase() = default;
+
+ActivityFlagsBase::~ActivityFlagsBase() = default;
+
+void ActivityFlagsBase::Initialize(mojo::ScopedSharedBufferHandle handle) {
+ handle_ = std::move(handle);
+ mapping_ = handle_->Map(sizeof(Flag));
+}
+
+volatile base::subtle::Atomic32* ActivityFlagsBase::AsAtomic() {
+ return reinterpret_cast<volatile base::subtle::Atomic32*>(mapping_.get());
+}
+
+GpuProcessActivityFlags* GpuProcessActivityFlags::GetInstance() {
+ return base::Singleton<GpuProcessActivityFlags>::get();
+}
+
+void GpuProcessActivityFlags::InitializeInstance(
+ mojo::ScopedSharedBufferHandle handle) {
+ // In cases where we are running without a GpuProcessHost, we may not
+ // have a valid handle. In this case, just return.
+ if (!handle.is_valid())
+ return;
+
+ GetInstance()->Initialize(std::move(handle));
+}
+
+void GpuProcessActivityFlags::SetFlag(Flag flag) {
+ // In cases where we are running without a GpuProcessHost, we may not
+ // initialize the GpuProcessActivityFlags. In this case, just return.
+ if (!is_initialized())
+ return;
+
+ base::subtle::Atomic32 old_value = base::subtle::NoBarrier_Load(AsAtomic());
+ base::subtle::Atomic32 new_value = old_value | flag;
+
+ // These flags are *only* written by a single process, and should only be
+ // written from the main GPU thread. We should never double-set them.
+ DCHECK_NE(old_value, new_value);
+ base::subtle::Acquire_Store(AsAtomic(), new_value);
+}
+
+void GpuProcessActivityFlags::UnsetFlag(Flag flag) {
+ // In cases where we are running without a GpuProcessHost, we may not
+ // initialize the GpuProcessActivityFlags. In this case, just return.
+ if (!is_initialized())
+ return;
+
+ // These flags are *only* written by a single process, and should only be
+ // written from the main GPU thread. No need to check for failure.
+ base::subtle::Atomic32 old_value = base::subtle::NoBarrier_Load(AsAtomic());
+ base::subtle::Atomic32 new_value = old_value ^ flag;
+
+ // These flags are *only* written by a single process, and should only be
+ // written from the main GPU thread. We should never double-unset them.
+ DCHECK_NE(old_value, new_value);
vmiura 2017/03/13 20:18:36 This doesn't really check anything since x ^ flag
ericrk 2017/03/13 20:30:45 Yup, good point.
+ base::subtle::Release_Store(AsAtomic(), new_value);
+}
+
+GpuProcessHostActivityFlags::GpuProcessHostActivityFlags() {
+ Initialize(mojo::SharedBufferHandle::Create(sizeof(Flag)));
+}
+
+bool GpuProcessHostActivityFlags::IsFlagSet(Flag flag) {
+ DCHECK(is_initialized());
+ return !!(base::subtle::Acquire_Load(AsAtomic()) & flag);
+}
+
+} // namespace gpu
« no previous file with comments | « gpu/ipc/common/activity_flags.h ('k') | gpu/ipc/common/activity_flags_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698