Improve performance of registering font preferences
[chromium-blink-merge.git] / media / base / data_buffer.h
blob96e9af5b44cd3f0a198a114cfe23eb537caf268e
1 // Copyright (c) 2012 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.
5 // A simple implementation of Buffer that takes ownership of the given data
6 // pointer.
7 //
8 // DataBuffer assumes that memory was allocated with new uint8[].
10 #ifndef MEDIA_BASE_DATA_BUFFER_H_
11 #define MEDIA_BASE_DATA_BUFFER_H_
13 #include "base/memory/scoped_ptr.h"
14 #include "media/base/buffers.h"
16 namespace media {
18 class MEDIA_EXPORT DataBuffer : public Buffer {
19 public:
20 // Assumes valid data of size |buffer_size|.
21 DataBuffer(scoped_array<uint8> buffer, int buffer_size);
23 // Allocates buffer of size |buffer_size|. If |buffer_size| is 0, |data_| is
24 // set to a NULL ptr.
25 explicit DataBuffer(int buffer_size);
27 // Allocates buffer of size |data_size|, copies [data,data+data_size) to
28 // the allocated buffer and sets data size to |data_size|.
29 DataBuffer(const uint8* data, int data_size);
31 // Buffer implementation.
32 virtual const uint8* GetData() const OVERRIDE;
33 virtual int GetDataSize() const OVERRIDE;
35 // Returns a read-write pointer to the buffer data.
36 virtual uint8* GetWritableData();
38 // Updates the size of valid data in bytes, which must be less than or equal
39 // to GetBufferSize().
40 virtual void SetDataSize(int data_size);
42 // Returns the size of the underlying buffer.
43 virtual int GetBufferSize() const;
45 protected:
46 virtual ~DataBuffer();
48 private:
49 // Constructor helper method for memory allocations.
50 void Initialize();
52 scoped_array<uint8> data_;
53 int buffer_size_;
54 int data_size_;
56 DISALLOW_COPY_AND_ASSIGN(DataBuffer);
59 } // namespace media
61 #endif // MEDIA_BASE_DATA_BUFFER_H_