| Index: ppapi/shared_impl/circular_buffer.h
|
| diff --git a/ppapi/shared_impl/circular_buffer.h b/ppapi/shared_impl/circular_buffer.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2c306313bac23cf282623e93b1798051bd83693c
|
| --- /dev/null
|
| +++ b/ppapi/shared_impl/circular_buffer.h
|
| @@ -0,0 +1,92 @@
|
| +// Copyright (c) 2014 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 PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_
|
| +#define PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "ppapi/shared_impl/ppapi_shared_export.h"
|
| +
|
| +namespace ppapi {
|
| +
|
| +class PPAPI_SHARED_EXPORT CircularBuffer {
|
| + public:
|
| + // Construct a CircularBuffer by given underlying buffer and size.
|
| + CircularBuffer(void* buffer, uint32_t size);
|
| +
|
| + ~CircularBuffer();
|
| +
|
| + // Remaining buffer size for reading or writing.
|
| + uint32_t remaining() const {
|
| + return remaining_;
|
| + }
|
| +
|
| + // Moves position forward by given offset.
|
| + void MovePosition(uint32_t offset);
|
| +
|
| + // Moves limit forward by given offset.
|
| + void MoveLimit(uint32_t offset);
|
| +
|
| + // Reads data and move position forward. The actual read size will be
|
| + // returned.
|
| + int32_t Read(void* buffer, uint32_t size);
|
| +
|
| + // Similar to |Read()|, but it will fail, if the circular buffer does not have
|
| + // enough data.
|
| + int32_t ReadAll(void* buffer, uint32_t size);
|
| +
|
| + // Writes data and move position forward. The actual write size will be
|
| + // returned.
|
| + int32_t Write(const void* buffer, uint32_t size);
|
| +
|
| + // Similar to |Write()|, but it will fail, if the circular buffer does not
|
| + // have enough space for the given size of data.
|
| + int32_t WriteAll(const void* buffer, uint32_t size);
|
| +
|
| + // Locks the given size of underlying buffer for direct accessing.
|
| + int32_t Lock(void** buffer, uint32_t size);
|
| +
|
| + // Relocks underlying buffer. It is used for adjusting locked block size;
|
| + int32_t Relock(void* buffer, uint32_t size);
|
| +
|
| + // Unlocks buffer which is locked by previous |Lock()| call. The locked block
|
| + // size will be returned.
|
| + int32_t Unlock(const void* buffer);
|
| +
|
| + // Returns true if the circular buffer is locked.
|
| + bool IsLocked() const { return locked_buffer_; }
|
| +
|
| + private:
|
| + int32_t ReadInternal(void* buffer, uint32_t size);
|
| +
|
| + int32_t WriteInternal(const void* buffer, uint32_t size);
|
| +
|
| + // Underlying buffer pointer.
|
| + uint8_t* buffer_;
|
| +
|
| + // Underlying buffer size.
|
| + uint32_t buffer_size_;
|
| +
|
| + // Current position for reading or writing.
|
| + uint32_t position_;
|
| +
|
| + // The limit position for reading or writing.
|
| + uint32_t limit_;
|
| +
|
| + // Remaining buffer size for reading or writing.
|
| + uint32_t remaining_;
|
| +
|
| + // Locked buffer pointer returned by |Lock()|. It will be reset to NULL,
|
| + // When |Unlock()| is called.
|
| + uint8_t* locked_buffer_;
|
| +
|
| + // Locked buffer size.
|
| + uint32_t locked_buffer_size_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CircularBuffer);
|
| +};
|
| +
|
| +} // namespace ppapi
|
| +
|
| +#endif // PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_
|
|
|