1 //
2 // Copyright 2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // BufferImpl.h: Defines the abstract rx::BufferImpl class.
8
9 #ifndef LIBANGLE_RENDERER_BUFFERIMPL_H_
10 #define LIBANGLE_RENDERER_BUFFERIMPL_H_
11
12 #include "common/PackedEnums.h"
13 #include "common/angleutils.h"
14 #include "common/mathutil.h"
15 #include "libANGLE/Error.h"
16 #include "libANGLE/Observer.h"
17
18 #include <stdint.h>
19
20 namespace gl
21 {
22 class BufferState;
23 class Context;
24 } // namespace gl
25
26 namespace rx
27 {
28 // We use two set of Subject messages. The CONTENTS_CHANGED message is signaled whenever data
29 // changes, to trigger re-translation or other events. Some buffers only need to be updated when the
30 // underlying driver object changes - this is notified via the STORAGE_CHANGED message.
31 class BufferImpl : public angle::Subject
32 {
33 public:
BufferImpl(const gl::BufferState & state)34 BufferImpl(const gl::BufferState &state) : mState(state) {}
~BufferImpl()35 ~BufferImpl() override {}
destroy(const gl::Context * context)36 virtual void destroy(const gl::Context *context) {}
37
38 virtual angle::Result setDataWithUsageFlags(const gl::Context *context,
39 gl::BufferBinding target,
40 GLeglClientBufferEXT clientBuffer,
41 const void *data,
42 size_t size,
43 gl::BufferUsage usage,
44 GLbitfield flags);
45 virtual angle::Result setData(const gl::Context *context,
46 gl::BufferBinding target,
47 const void *data,
48 size_t size,
49 gl::BufferUsage usage) = 0;
50 virtual angle::Result setSubData(const gl::Context *context,
51 gl::BufferBinding target,
52 const void *data,
53 size_t size,
54 size_t offset) = 0;
55 virtual angle::Result copySubData(const gl::Context *context,
56 BufferImpl *source,
57 GLintptr sourceOffset,
58 GLintptr destOffset,
59 GLsizeiptr size) = 0;
60 virtual angle::Result map(const gl::Context *context, GLenum access, void **mapPtr) = 0;
61 virtual angle::Result mapRange(const gl::Context *context,
62 size_t offset,
63 size_t length,
64 GLbitfield access,
65 void **mapPtr) = 0;
66 virtual angle::Result unmap(const gl::Context *context, GLboolean *result) = 0;
67
68 virtual angle::Result getIndexRange(const gl::Context *context,
69 gl::DrawElementsType type,
70 size_t offset,
71 size_t count,
72 bool primitiveRestartEnabled,
73 gl::IndexRange *outRange) = 0;
74
75 virtual angle::Result getSubData(const gl::Context *context,
76 GLintptr offset,
77 GLsizeiptr size,
78 void *outData);
79
80 // Override if accurate native memory size information is available
81 virtual GLint64 getMemorySize() const;
82
onDataChanged()83 virtual void onDataChanged() {}
84
85 protected:
86 const gl::BufferState &mState;
87 };
88
getMemorySize()89 inline GLint64 BufferImpl::getMemorySize() const
90 {
91 return 0;
92 }
93
94 } // namespace rx
95
96 #endif // LIBANGLE_RENDERER_BUFFERIMPL_H_
97