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
setData(const gl::Context * context,gl::BufferBinding target,const void * data,size_t size,gl::BufferUsage usage)33 angle::Result BufferNULL::setData(const gl::Context *context,
34 gl::BufferBinding target,
35 const void *data,
36 size_t size,
37 gl::BufferUsage usage)
38 {
39 ANGLE_CHECK_GL_ALLOC(GetImplAs<ContextNULL>(context),
40 mAllocationTracker->updateMemoryAllocation(mData.size(), size));
41
42 mData.resize(size, 0);
43 if (size > 0 && data != nullptr)
44 {
45 memcpy(mData.data(), data, size);
46 }
47 return angle::Result::Continue;
48 }
49
setSubData(const gl::Context * context,gl::BufferBinding target,const void * data,size_t size,size_t offset)50 angle::Result BufferNULL::setSubData(const gl::Context *context,
51 gl::BufferBinding target,
52 const void *data,
53 size_t size,
54 size_t offset)
55 {
56 if (size > 0)
57 {
58 memcpy(mData.data() + offset, data, size);
59 }
60 return angle::Result::Continue;
61 }
62
copySubData(const gl::Context * context,BufferImpl * source,GLintptr sourceOffset,GLintptr destOffset,GLsizeiptr size)63 angle::Result BufferNULL::copySubData(const gl::Context *context,
64 BufferImpl *source,
65 GLintptr sourceOffset,
66 GLintptr destOffset,
67 GLsizeiptr size)
68 {
69 BufferNULL *sourceNULL = GetAs<BufferNULL>(source);
70 if (size > 0)
71 {
72 memcpy(mData.data() + destOffset, sourceNULL->mData.data() + sourceOffset, size);
73 }
74 return angle::Result::Continue;
75 }
76
map(const gl::Context * context,GLenum access,void ** mapPtr)77 angle::Result BufferNULL::map(const gl::Context *context, GLenum access, void **mapPtr)
78 {
79 *mapPtr = mData.data();
80 return angle::Result::Continue;
81 }
82
mapRange(const gl::Context * context,size_t offset,size_t length,GLbitfield access,void ** mapPtr)83 angle::Result BufferNULL::mapRange(const gl::Context *context,
84 size_t offset,
85 size_t length,
86 GLbitfield access,
87 void **mapPtr)
88 {
89 *mapPtr = mData.data() + offset;
90 return angle::Result::Continue;
91 }
92
unmap(const gl::Context * context,GLboolean * result)93 angle::Result BufferNULL::unmap(const gl::Context *context, GLboolean *result)
94 {
95 *result = GL_TRUE;
96 return angle::Result::Continue;
97 }
98
getIndexRange(const gl::Context * context,gl::DrawElementsType type,size_t offset,size_t count,bool primitiveRestartEnabled,gl::IndexRange * outRange)99 angle::Result BufferNULL::getIndexRange(const gl::Context *context,
100 gl::DrawElementsType type,
101 size_t offset,
102 size_t count,
103 bool primitiveRestartEnabled,
104 gl::IndexRange *outRange)
105 {
106 *outRange = gl::ComputeIndexRange(type, mData.data() + offset, count, primitiveRestartEnabled);
107 return angle::Result::Continue;
108 }
109
getDataPtr()110 uint8_t *BufferNULL::getDataPtr()
111 {
112 return mData.data();
113 }
114
getDataPtr() const115 const uint8_t *BufferNULL::getDataPtr() const
116 {
117 return mData.data();
118 }
119
120 } // namespace rx
121