| 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 namespace gpu { |
| 8 |
| 9 ActivityFlagsBase::ActivityFlagsBase() = default; |
| 10 ActivityFlagsBase::ActivityFlagsBase(ActivityFlagsBase&& other) = default; |
| 11 ActivityFlagsBase::~ActivityFlagsBase() = default; |
| 12 |
| 13 void ActivityFlagsBase::Initialize(mojo::ScopedSharedBufferHandle handle) { |
| 14 handle_ = std::move(handle); |
| 15 mapping_ = handle_->Map(sizeof(Flag)); |
| 16 } |
| 17 |
| 18 volatile base::subtle::Atomic32* ActivityFlagsBase::AsAtomic() { |
| 19 return reinterpret_cast<volatile base::subtle::Atomic32*>(mapping_.get()); |
| 20 } |
| 21 |
| 22 GpuProcessActivityFlags::GpuProcessActivityFlags() = default; |
| 23 GpuProcessActivityFlags::GpuProcessActivityFlags( |
| 24 GpuProcessActivityFlags&& other) = default; |
| 25 |
| 26 GpuProcessActivityFlags::GpuProcessActivityFlags( |
| 27 mojo::ScopedSharedBufferHandle handle) { |
| 28 // In cases where we are running without a GpuProcessHost, we may not |
| 29 // have a valid handle. In this case, just return. |
| 30 if (!handle.is_valid()) |
| 31 return; |
| 32 |
| 33 Initialize(std::move(handle)); |
| 34 } |
| 35 |
| 36 void GpuProcessActivityFlags::SetFlag(Flag flag) { |
| 37 // In cases where we are running without a GpuProcessHost, we may not |
| 38 // initialize the GpuProcessActivityFlags. In this case, just return. |
| 39 if (!is_initialized()) |
| 40 return; |
| 41 |
| 42 base::subtle::Atomic32 old_value = base::subtle::NoBarrier_Load(AsAtomic()); |
| 43 base::subtle::Atomic32 new_value = old_value | flag; |
| 44 |
| 45 // These flags are only written by a single process / single thread. |
| 46 // We should never double-set them. |
| 47 DCHECK(!(old_value & flag)); |
| 48 base::subtle::Acquire_Store(AsAtomic(), new_value); |
| 49 } |
| 50 |
| 51 void GpuProcessActivityFlags::UnsetFlag(Flag flag) { |
| 52 // In cases where we are running without a GpuProcessHost, we may not |
| 53 // initialize the GpuProcessActivityFlags. In this case, just return. |
| 54 if (!is_initialized()) |
| 55 return; |
| 56 |
| 57 base::subtle::Atomic32 old_value = base::subtle::NoBarrier_Load(AsAtomic()); |
| 58 base::subtle::Atomic32 new_value = old_value ^ flag; |
| 59 |
| 60 // These flags are only written by a single process / single thread. |
| 61 // We should never double-unset them. |
| 62 DCHECK(!!(old_value & flag)); |
| 63 base::subtle::Release_Store(AsAtomic(), new_value); |
| 64 } |
| 65 |
| 66 GpuProcessHostActivityFlags::GpuProcessHostActivityFlags() { |
| 67 Initialize(mojo::SharedBufferHandle::Create(sizeof(Flag))); |
| 68 } |
| 69 |
| 70 bool GpuProcessHostActivityFlags::IsFlagSet(Flag flag) { |
| 71 DCHECK(is_initialized()); |
| 72 return !!(base::subtle::Acquire_Load(AsAtomic()) & flag); |
| 73 } |
| 74 |
| 75 } // namespace gpu |
| OLD | NEW |