| Index: gpu/command_buffer/common/discardable_handle.h
|
| diff --git a/gpu/command_buffer/common/discardable_handle.h b/gpu/command_buffer/common/discardable_handle.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8a490aed851c124a1aacc0153ab6d89e45ade391
|
| --- /dev/null
|
| +++ b/gpu/command_buffer/common/discardable_handle.h
|
| @@ -0,0 +1,58 @@
|
| +// 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_DISCARDABLE_HANDLE_H_
|
| +#define GPU_COMMAND_BUFFER_COMMON_DISCARDABLE_HANDLE_H_
|
| +
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/shared_memory.h"
|
| +#include "gpu/command_buffer/common/buffer.h"
|
| +
|
| +namespace gpu {
|
| +
|
| +// DiscardableHandle provides a threadsafe object which can be transitioned
|
| +// between one of three states:
|
| +// ╔════════════╗ ╔════════════╗ ╔═══════════╗
|
| +// ║ Locked ║ ──────> ║ Unlocked ║ ──────> ║ Deleted ║
|
| +// ╚════════════╝ ╚════════════╝ ╚═══════════╝
|
| +// └───────────<──────────┘
|
| +// Note that a DiscardableHAndle can be locked multiple times, and stores
|
| +// a lock-count.
|
| +//
|
| +// In order to facilitate transfering DiscardableHandles across the command
|
| +// buffer, a DiscardableHandle is backed by a gpu::Buffer and an offset
|
| +// into that buffer. The handle uses a single uint32_t of data at the given
|
| +// offset.
|
| +class GPU_EXPORT DiscardableHandle {
|
| + public:
|
| + void InitializeWithNewData(scoped_refptr<Buffer> buffer,
|
| + uint32_t byte_offset,
|
| + int32_t shm_id);
|
| + void InitializeWithExistingData(scoped_refptr<Buffer> buffer,
|
| + uint32_t byte_offset,
|
| + int32_t shm_id);
|
| +
|
| + bool Lock();
|
| + void Unlock();
|
| + bool Delete();
|
| +
|
| + bool IsInitialized() const { return !!shm_id_; }
|
| + int32_t shm_id() const { return shm_id_; }
|
| + uint32_t byte_offset() const { return byte_offset_; }
|
| + bool IsDeleted() const;
|
| +
|
| + // Test only functions.
|
| + bool IsLockedForTesting();
|
| +
|
| + private:
|
| + volatile base::subtle::Atomic32* AsAtomic() const;
|
| +
|
| + scoped_refptr<Buffer> buffer_;
|
| + uint32_t byte_offset_ = 0;
|
| + uint32_t shm_id_ = 0;
|
| +};
|
| +
|
| +} // namespace gpu
|
| +
|
| +#endif // GPU_COMMAND_BUFFER_COMMON_DISCARDABLE_HANDLE_H_
|
|
|