| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "gpu/command_buffer/common/activity_flags.h" |
| 6 |
| 7 #include "base/memory/singleton.h" |
| 8 |
| 9 namespace gpu { |
| 10 |
| 11 ActivityFlagsBase::ActivityFlagsBase() = default; |
| 12 |
| 13 ActivityFlagsBase::~ActivityFlagsBase() = default; |
| 14 |
| 15 void ActivityFlagsBase::Initialize(mojo::ScopedSharedBufferHandle handle) { |
| 16 handle_ = std::move(handle); |
| 17 mapping_ = handle_->Map(sizeof(Flag)); |
| 18 } |
| 19 |
| 20 volatile base::subtle::Atomic32* ActivityFlagsBase::AsAtomic() { |
| 21 return reinterpret_cast<volatile base::subtle::Atomic32*>(mapping_.get()); |
| 22 } |
| 23 |
| 24 GpuProcessActivityFlags* GpuProcessActivityFlags::GetInstance() { |
| 25 return base::Singleton<GpuProcessActivityFlags>::get(); |
| 26 } |
| 27 |
| 28 void GpuProcessActivityFlags::InitializeInstance( |
| 29 mojo::ScopedSharedBufferHandle handle) { |
| 30 // In cases where we are running without a GpuProcessHost, we may not |
| 31 // have a valid handle. In this case, just return. |
| 32 if (!handle.is_valid()) |
| 33 return; |
| 34 |
| 35 GetInstance()->Initialize(std::move(handle)); |
| 36 } |
| 37 |
| 38 void GpuProcessActivityFlags::SetFlag(Flag flag) { |
| 39 // In cases where we are running without a GpuProcessHost, we may not |
| 40 // initialize the GpuProcessActivityFlags. In this case, just return. |
| 41 if (!is_initialized()) |
| 42 return; |
| 43 |
| 44 base::subtle::Atomic32 old_value = base::subtle::NoBarrier_Load(AsAtomic()); |
| 45 base::subtle::Atomic32 new_value = old_value | flag; |
| 46 |
| 47 // These flags are only written by a single process / single thread. |
| 48 // We should never double-set them. |
| 49 DCHECK(!(old_value & flag)); |
| 50 base::subtle::Acquire_Store(AsAtomic(), new_value); |
| 51 } |
| 52 |
| 53 void GpuProcessActivityFlags::UnsetFlag(Flag flag) { |
| 54 // In cases where we are running without a GpuProcessHost, we may not |
| 55 // initialize the GpuProcessActivityFlags. In this case, just return. |
| 56 if (!is_initialized()) |
| 57 return; |
| 58 |
| 59 base::subtle::Atomic32 old_value = base::subtle::NoBarrier_Load(AsAtomic()); |
| 60 base::subtle::Atomic32 new_value = old_value ^ flag; |
| 61 |
| 62 // These flags are only written by a single process / single thread. |
| 63 // We should never double-unset them. |
| 64 DCHECK(!!(old_value & flag)); |
| 65 base::subtle::Release_Store(AsAtomic(), new_value); |
| 66 } |
| 67 |
| 68 GpuProcessHostActivityFlags::GpuProcessHostActivityFlags() { |
| 69 Initialize(mojo::SharedBufferHandle::Create(sizeof(Flag))); |
| 70 } |
| 71 |
| 72 bool GpuProcessHostActivityFlags::IsFlagSet(Flag flag) { |
| 73 DCHECK(is_initialized()); |
| 74 return !!(base::subtle::Acquire_Load(AsAtomic()) & flag); |
| 75 } |
| 76 |
| 77 } // namespace gpu |
| OLD | NEW |