| 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 #ifndef GPU_IPC_COMMON_ACTIVITY_FLAGS_H_ |
| 6 #define GPU_IPC_COMMON_ACTIVITY_FLAGS_H_ |
| 7 |
| 8 #include "base/atomicops.h" |
| 9 #include "gpu/gpu_export.h" |
| 10 #include "mojo/public/cpp/system/buffer.h" |
| 11 |
| 12 namespace base { |
| 13 template <typename T> |
| 14 struct DefaultSingletonTraits; |
| 15 |
| 16 } // namespace base |
| 17 |
| 18 namespace gpu { |
| 19 |
| 20 // Base class for GpuProcessActivityFlags and GpuProcessHostActivityFlags, |
| 21 // can not be used directly. |
| 22 class GPU_EXPORT ActivityFlagsBase { |
| 23 public: |
| 24 enum Flag : uint32_t { FLAG_LOADING_PROGRAM_BINARY = 0x1 }; |
| 25 |
| 26 protected: |
| 27 ActivityFlagsBase(); |
| 28 ~ActivityFlagsBase(); |
| 29 |
| 30 void Initialize(mojo::ScopedSharedBufferHandle handle); |
| 31 const mojo::SharedBufferHandle& handle() const { return handle_.get(); } |
| 32 bool is_initialized() const { return handle().is_valid(); } |
| 33 |
| 34 protected: |
| 35 volatile base::subtle::Atomic32* AsAtomic(); |
| 36 |
| 37 private: |
| 38 mojo::ScopedSharedBufferHandle handle_; |
| 39 mojo::ScopedSharedBufferMapping mapping_; |
| 40 }; |
| 41 |
| 42 // Provides write-only access to activity flags for the gpu process. Each gpu |
| 43 // process has a singleton GpuProcessActivityFlags retreived via GetInstance(). |
| 44 // |
| 45 // Note that we currently assume that the GPU process never sets/unsets flags |
| 46 // from multiple threads at the same time. This is true with our current |
| 47 // single-flag approach, but may need adjustment if additional flags are added. |
| 48 class GPU_EXPORT GpuProcessActivityFlags : public ActivityFlagsBase { |
| 49 public: |
| 50 static GpuProcessActivityFlags* GetInstance(); |
| 51 static void InitializeInstance(mojo::ScopedSharedBufferHandle handle); |
| 52 |
| 53 void SetFlag(Flag flag); |
| 54 void UnsetFlag(Flag flag); |
| 55 |
| 56 private: |
| 57 friend base::DefaultSingletonTraits<GpuProcessActivityFlags>; |
| 58 GpuProcessActivityFlags() = default; |
| 59 }; |
| 60 |
| 61 // Provides read-only access to activity flags. Creating a new |
| 62 // GpuProcessHostActivityFlags will initialize a new mojo shared buffer. The |
| 63 // handle to this buffer should be passed to the GPU process via CloneHandle. |
| 64 // The GPU process will then populate flags, which can be read via this class. |
| 65 class GPU_EXPORT GpuProcessHostActivityFlags : public ActivityFlagsBase { |
| 66 public: |
| 67 GpuProcessHostActivityFlags(); |
| 68 |
| 69 bool IsFlagSet(Flag flag); |
| 70 mojo::ScopedSharedBufferHandle CloneHandle() { return handle().Clone(); } |
| 71 }; |
| 72 |
| 73 } // namespace gpu |
| 74 |
| 75 #endif // GPU_IPC_COMMON_ACTIVITY_FLAGS_H_ |
| OLD | NEW |