summaryrefslogtreecommitdiffstats
path: root/gfx/angle/checkout/src/libANGLE/renderer/d3d/d3d9/Buffer9.cpp
blob: dbf875134bd536f417646475feb22a708e147e34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// Copyright 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

// Buffer9.cpp Defines the Buffer9 class.

#include "libANGLE/renderer/d3d/d3d9/Buffer9.h"

#include "libANGLE/Context.h"
#include "libANGLE/renderer/d3d/d3d9/Renderer9.h"

namespace rx
{

Buffer9::Buffer9(const gl::BufferState &state, Renderer9 *renderer)
    : BufferD3D(state, renderer), mSize(0)
{}

Buffer9::~Buffer9()
{
    mSize = 0;
}

size_t Buffer9::getSize() const
{
    return mSize;
}

bool Buffer9::supportsDirectBinding() const
{
    return false;
}

angle::Result Buffer9::setData(const gl::Context *context,
                               gl::BufferBinding target,
                               const void *data,
                               size_t size,
                               gl::BufferUsage usage)
{
    if (size > mMemory.size())
    {
        ANGLE_CHECK_GL_ALLOC(GetImplAs<Context9>(context), mMemory.resize(size));
    }

    mSize = size;
    if (data && size > 0)
    {
        memcpy(mMemory.data(), data, size);
    }

    updateD3DBufferUsage(context, usage);

    invalidateStaticData(context);

    return angle::Result::Continue;
}

angle::Result Buffer9::getData(const gl::Context *context, const uint8_t **outData)
{
    if (mMemory.empty())
    {
        *outData = nullptr;
    }
    else
    {
        *outData = mMemory.data();
    }
    return angle::Result::Continue;
}

angle::Result Buffer9::setSubData(const gl::Context *context,
                                  gl::BufferBinding target,
                                  const void *data,
                                  size_t size,
                                  size_t offset)
{
    if (offset + size > mMemory.size())
    {
        ANGLE_CHECK_GL_ALLOC(GetImplAs<Context9>(context), mMemory.resize(size + offset));
    }

    mSize = std::max(mSize, offset + size);
    if (data && size > 0)
    {
        memcpy(mMemory.data() + offset, data, size);
    }

    invalidateStaticData(context);

    return angle::Result::Continue;
}

angle::Result Buffer9::copySubData(const gl::Context *context,
                                   BufferImpl *source,
                                   GLintptr sourceOffset,
                                   GLintptr destOffset,
                                   GLsizeiptr size)
{
    // Note: this method is currently unreachable
    Buffer9 *sourceBuffer = GetAs<Buffer9>(source);
    ASSERT(sourceBuffer);

    memcpy(mMemory.data() + destOffset, sourceBuffer->mMemory.data() + sourceOffset, size);

    invalidateStaticData(context);

    return angle::Result::Continue;
}

// We do not support buffer mapping in D3D9
angle::Result Buffer9::map(const gl::Context *context, GLenum access, void **mapPtr)
{
    ANGLE_HR_UNREACHABLE(GetImplAs<Context9>(context));
    return angle::Result::Stop;
}

angle::Result Buffer9::mapRange(const gl::Context *context,
                                size_t offset,
                                size_t length,
                                GLbitfield access,
                                void **mapPtr)
{
    ANGLE_HR_UNREACHABLE(GetImplAs<Context9>(context));
    return angle::Result::Stop;
}

angle::Result Buffer9::unmap(const gl::Context *context, GLboolean *result)
{
    ANGLE_HR_UNREACHABLE(GetImplAs<Context9>(context));
    return angle::Result::Stop;
}

angle::Result Buffer9::markTransformFeedbackUsage(const gl::Context *context)
{
    ANGLE_HR_UNREACHABLE(GetImplAs<Context9>(context));
    return angle::Result::Stop;
}

}  // namespace rx