Chromium Code Reviews| Index: gpu/command_buffer/common/activity_flags.h |
| diff --git a/gpu/command_buffer/common/activity_flags.h b/gpu/command_buffer/common/activity_flags.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7059abd15929c3cd3242c7af8997684d82252b65 |
| --- /dev/null |
| +++ b/gpu/command_buffer/common/activity_flags.h |
| @@ -0,0 +1,75 @@ |
| +// 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. |
| + |
| +#ifndef GPU_COMMAND_BUFFER_COMMON_ACTIVITY_FLAGS_H_ |
| +#define GPU_COMMAND_BUFFER_COMMON_ACTIVITY_FLAGS_H_ |
| + |
| +#include "base/atomicops.h" |
| +#include "gpu/gpu_export.h" |
| +#include "mojo/public/cpp/system/buffer.h" |
| + |
| +namespace base { |
| +template <typename T> |
| +struct DefaultSingletonTraits; |
| + |
| +} // namespace base |
| + |
| +namespace gpu { |
| + |
| +// Base class for GpuProcessActivityFlags and GpuProcessHostActivityFlags, |
| +// can not be used directly. |
| +class GPU_EXPORT ActivityFlagsBase { |
| + public: |
| + enum Flag : uint32_t { FLAG_LOADING_PROGRAM_BINARY = 0x1 }; |
| + |
| + protected: |
| + ActivityFlagsBase(); |
| + ~ActivityFlagsBase(); |
| + |
| + void Initialize(mojo::ScopedSharedBufferHandle handle); |
| + const mojo::SharedBufferHandle& handle() const { return handle_.get(); } |
| + bool is_initialized() const { return handle().is_valid(); } |
| + |
| + protected: |
| + volatile base::subtle::Atomic32* AsAtomic(); |
| + |
| + private: |
| + mojo::ScopedSharedBufferHandle handle_; |
| + mojo::ScopedSharedBufferMapping mapping_; |
| +}; |
| + |
| +// Provides write-only access to activity flags for the gpu process. Each gpu |
| +// process has a singleton GpuProcessActivityFlags retreived via GetInstance(). |
| +// |
| +// Note that we currently assume that the GPU process never sets/unsets flags |
| +// from multiple threads at the same time. This is true with our current |
| +// single-flag approach, but may need adjustment if additional flags are added. |
| +class GPU_EXPORT GpuProcessActivityFlags : public ActivityFlagsBase { |
| + public: |
| + static GpuProcessActivityFlags* GetInstance(); |
|
sadrul
2017/03/16 04:40:32
Please consider not making it a singleton.
Looks
ericrk
2017/03/16 21:25:23
Sure, made this not a singleton.
|
| + static void InitializeInstance(mojo::ScopedSharedBufferHandle handle); |
| + |
| + void SetFlag(Flag flag); |
| + void UnsetFlag(Flag flag); |
| + |
| + private: |
| + friend base::DefaultSingletonTraits<GpuProcessActivityFlags>; |
| + GpuProcessActivityFlags() = default; |
| +}; |
| + |
| +// Provides read-only access to activity flags. Creating a new |
| +// GpuProcessHostActivityFlags will initialize a new mojo shared buffer. The |
| +// handle to this buffer should be passed to the GPU process via CloneHandle. |
| +// The GPU process will then populate flags, which can be read via this class. |
| +class GPU_EXPORT GpuProcessHostActivityFlags : public ActivityFlagsBase { |
| + public: |
| + GpuProcessHostActivityFlags(); |
| + |
| + bool IsFlagSet(Flag flag); |
| + mojo::ScopedSharedBufferHandle CloneHandle() { return handle().Clone(); } |
| +}; |
| + |
| +} // namespace gpu |
| + |
| +#endif // GPU_COMMAND_BUFFER_COMMON_ACTIVITY_FLAGS_H_ |