• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2016 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 // BufferNULL.cpp:
7 //    Implements the class methods for BufferNULL.
8 //
9 
10 #include "libANGLE/renderer/null/BufferNULL.h"
11 
12 #include "common/debug.h"
13 #include "common/utilities.h"
14 #include "libANGLE/Context.h"
15 #include "libANGLE/angletypes.h"
16 #include "libANGLE/renderer/null/ContextNULL.h"
17 
18 namespace rx
19 {
20 
BufferNULL(const gl::BufferState & state,AllocationTrackerNULL * allocationTracker)21 BufferNULL::BufferNULL(const gl::BufferState &state, AllocationTrackerNULL *allocationTracker)
22     : BufferImpl(state), mAllocationTracker(allocationTracker)
23 {
24     ASSERT(mAllocationTracker != nullptr);
25 }
26 
~BufferNULL()27 BufferNULL::~BufferNULL()
28 {
29     bool memoryReleaseResult = mAllocationTracker->updateMemoryAllocation(mData.size(), 0);
30     ASSERT(memoryReleaseResult);
31 }
32 
setDataWithUsageFlags(const gl::Context * context,gl::BufferBinding target,GLeglClientBufferEXT clientBuffer,const void * data,size_t size,gl::BufferUsage usage,GLbitfield flags)33 angle::Result BufferNULL::setDataWithUsageFlags(const gl::Context *context,
34                                                 gl::BufferBinding target,
35                                                 GLeglClientBufferEXT clientBuffer,
36                                                 const void *data,
37                                                 size_t size,
38                                                 gl::BufferUsage usage,
39                                                 GLbitfield flags)
40 {
41     ANGLE_CHECK_GL_ALLOC(GetImplAs<ContextNULL>(context),
42                          mAllocationTracker->updateMemoryAllocation(mData.size(), size));
43 
44     mData.resize(size, 0);
45     if (size > 0 && data != nullptr)
46     {
47         memcpy(mData.data(), data, size);
48     }
49     return angle::Result::Continue;
50 }
51 
setData(const gl::Context * context,gl::BufferBinding target,const void * data,size_t size,gl::BufferUsage usage)52 angle::Result BufferNULL::setData(const gl::Context *context,
53                                   gl::BufferBinding target,
54                                   const void *data,
55                                   size_t size,
56                                   gl::BufferUsage usage)
57 {
58     ANGLE_CHECK_GL_ALLOC(GetImplAs<ContextNULL>(context),
59                          mAllocationTracker->updateMemoryAllocation(mData.size(), size));
60 
61     mData.resize(size, 0);
62     if (size > 0 && data != nullptr)
63     {
64         memcpy(mData.data(), data, size);
65     }
66     return angle::Result::Continue;
67 }
68 
setSubData(const gl::Context * context,gl::BufferBinding target,const void * data,size_t size,size_t offset)69 angle::Result BufferNULL::setSubData(const gl::Context *context,
70                                      gl::BufferBinding target,
71                                      const void *data,
72                                      size_t size,
73                                      size_t offset)
74 {
75     if (size > 0)
76     {
77         memcpy(mData.data() + offset, data, size);
78     }
79     return angle::Result::Continue;
80 }
81 
copySubData(const gl::Context * context,BufferImpl * source,GLintptr sourceOffset,GLintptr destOffset,GLsizeiptr size)82 angle::Result BufferNULL::copySubData(const gl::Context *context,
83                                       BufferImpl *source,
84                                       GLintptr sourceOffset,
85                                       GLintptr destOffset,
86                                       GLsizeiptr size)
87 {
88     BufferNULL *sourceNULL = GetAs<BufferNULL>(source);
89     if (size > 0)
90     {
91         memcpy(mData.data() + destOffset, sourceNULL->mData.data() + sourceOffset, size);
92     }
93     return angle::Result::Continue;
94 }
95 
map(const gl::Context * context,GLenum access,void ** mapPtr)96 angle::Result BufferNULL::map(const gl::Context *context, GLenum access, void **mapPtr)
97 {
98     *mapPtr = mData.data();
99     return angle::Result::Continue;
100 }
101 
mapRange(const gl::Context * context,size_t offset,size_t length,GLbitfield access,void ** mapPtr)102 angle::Result BufferNULL::mapRange(const gl::Context *context,
103                                    size_t offset,
104                                    size_t length,
105                                    GLbitfield access,
106                                    void **mapPtr)
107 {
108     *mapPtr = mData.data() + offset;
109     return angle::Result::Continue;
110 }
111 
unmap(const gl::Context * context,GLboolean * result)112 angle::Result BufferNULL::unmap(const gl::Context *context, GLboolean *result)
113 {
114     *result = GL_TRUE;
115     return angle::Result::Continue;
116 }
117 
getIndexRange(const gl::Context * context,gl::DrawElementsType type,size_t offset,size_t count,bool primitiveRestartEnabled,gl::IndexRange * outRange)118 angle::Result BufferNULL::getIndexRange(const gl::Context *context,
119                                         gl::DrawElementsType type,
120                                         size_t offset,
121                                         size_t count,
122                                         bool primitiveRestartEnabled,
123                                         gl::IndexRange *outRange)
124 {
125     *outRange = gl::ComputeIndexRange(type, mData.data() + offset, count, primitiveRestartEnabled);
126     return angle::Result::Continue;
127 }
128 
getDataPtr()129 uint8_t *BufferNULL::getDataPtr()
130 {
131     return mData.data();
132 }
133 
getDataPtr() const134 const uint8_t *BufferNULL::getDataPtr() const
135 {
136     return mData.data();
137 }
138 
139 }  // namespace rx
140