blob: b288c23acd5269935573dde891e84a23a1c1b49a [file] [log] [blame]
Geoff Langd08f3b32016-09-23 15:56:30 -04001//
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// ContextNULL.cpp:
7// Implements the class methods for ContextNULL.
8//
9
10#include "libANGLE/renderer/null/ContextNULL.h"
11
12#include "common/debug.h"
13
Geoff Lang76cdbd52016-09-23 16:51:04 -040014#include "libANGLE/renderer/null/BufferNULL.h"
15#include "libANGLE/renderer/null/CompilerNULL.h"
16#include "libANGLE/renderer/null/DisplayNULL.h"
17#include "libANGLE/renderer/null/FenceNVNULL.h"
Geoff Lang76cdbd52016-09-23 16:51:04 -040018#include "libANGLE/renderer/null/FramebufferNULL.h"
19#include "libANGLE/renderer/null/ImageNULL.h"
20#include "libANGLE/renderer/null/PathNULL.h"
21#include "libANGLE/renderer/null/ProgramNULL.h"
Yunchao Hea336b902017-08-02 16:05:21 +080022#include "libANGLE/renderer/null/ProgramPipelineNULL.h"
Geoff Lang76cdbd52016-09-23 16:51:04 -040023#include "libANGLE/renderer/null/QueryNULL.h"
24#include "libANGLE/renderer/null/RenderbufferNULL.h"
25#include "libANGLE/renderer/null/SamplerNULL.h"
26#include "libANGLE/renderer/null/ShaderNULL.h"
Jamie Madill70b5bb02017-08-28 13:32:37 -040027#include "libANGLE/renderer/null/SyncNULL.h"
Geoff Lang76cdbd52016-09-23 16:51:04 -040028#include "libANGLE/renderer/null/TextureNULL.h"
29#include "libANGLE/renderer/null/TransformFeedbackNULL.h"
30#include "libANGLE/renderer/null/VertexArrayNULL.h"
31
Geoff Langd08f3b32016-09-23 15:56:30 -040032namespace rx
33{
34
Geoff Lang1b60d8d2017-02-10 14:56:55 -050035AllocationTrackerNULL::AllocationTrackerNULL(size_t maxTotalAllocationSize)
36 : mAllocatedBytes(0), mMaxBytes(maxTotalAllocationSize)
Geoff Langd08f3b32016-09-23 15:56:30 -040037{
Geoff Lang1b60d8d2017-02-10 14:56:55 -050038}
39
40AllocationTrackerNULL::~AllocationTrackerNULL()
41{
42 // ASSERT that all objects with the NULL renderer clean up after themselves
43 ASSERT(mAllocatedBytes == 0);
44}
45
46bool AllocationTrackerNULL::updateMemoryAllocation(size_t oldSize, size_t newSize)
47{
48 ASSERT(mAllocatedBytes >= oldSize);
49
50 size_t sizeAfterRelease = mAllocatedBytes - oldSize;
51 size_t sizeAfterReallocate = sizeAfterRelease + newSize;
52 if (sizeAfterReallocate < sizeAfterRelease || sizeAfterReallocate > mMaxBytes)
53 {
54 // Overflow or allocation would be too large
55 return false;
56 }
57
58 mAllocatedBytes = sizeAfterReallocate;
59 return true;
60}
61
62ContextNULL::ContextNULL(const gl::ContextState &state, AllocationTrackerNULL *allocationTracker)
63 : ContextImpl(state), mAllocationTracker(allocationTracker)
64{
65 ASSERT(mAllocationTracker != nullptr);
66
Jamie Madill493f9572018-05-24 19:52:15 -040067 mExtensions = gl::Extensions();
68 mExtensions.fence = true;
69 mExtensions.instancedArrays = true;
70 mExtensions.pixelBufferObject = true;
71 mExtensions.mapBuffer = true;
72 mExtensions.mapBufferRange = true;
73 mExtensions.copyTexture = true;
74 mExtensions.copyCompressedTexture = true;
75 mExtensions.textureRectangle = true;
Geoff Lang73dcc602017-11-08 16:41:52 -050076 mExtensions.textureUsage = true;
77 mExtensions.vertexArrayObject = true;
78 mExtensions.debugMarker = true;
79 mExtensions.translatedShaderSource = true;
Geoff Lang1e031b22017-02-10 15:01:28 -050080
Geoff Langd54d3042017-11-07 14:56:07 -050081 mExtensions.textureStorage = true;
Jamie Madill493f9572018-05-24 19:52:15 -040082 mExtensions.rgb8rgba8 = true;
Geoff Lang86f81162017-10-30 15:10:45 -040083 mExtensions.textureCompressionDXT1 = true;
84 mExtensions.textureCompressionDXT3 = true;
85 mExtensions.textureCompressionDXT5 = true;
86 mExtensions.textureCompressionS3TCsRGB = true;
87 mExtensions.textureCompressionASTCHDR = true;
88 mExtensions.textureCompressionASTCLDR = true;
89 mExtensions.compressedETC1RGB8Texture = true;
90 mExtensions.lossyETCDecode = true;
Jiawei Shao361df072017-11-22 09:33:59 +080091 mExtensions.geometryShader = true;
Geoff Langd84a00b2017-10-27 17:27:26 -040092
Geoff Lang025aafd2017-10-30 15:16:37 -040093 mExtensions.eglImage = true;
94 mExtensions.eglImageExternal = true;
95 mExtensions.eglImageExternalEssl3 = true;
96 mExtensions.eglStreamConsumerExternal = true;
97
Geoff Lang4751aab2017-10-30 15:14:52 -040098 const gl::Version maxClientVersion(3, 1);
99 mCaps = GenerateMinimumCaps(maxClientVersion, mExtensions);
100
Jamie Madill7b62cf92017-11-02 15:20:49 -0400101 InitMinimumTextureCapsMap(maxClientVersion, mExtensions, &mTextureCaps);
Geoff Langd08f3b32016-09-23 15:56:30 -0400102}
103
104ContextNULL::~ContextNULL()
105{
106}
107
108gl::Error ContextNULL::initialize()
109{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400110 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400111}
112
Jamie Madillafa02a22017-11-23 12:57:38 -0500113gl::Error ContextNULL::flush(const gl::Context *context)
Geoff Langd08f3b32016-09-23 15:56:30 -0400114{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400115 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400116}
117
Jamie Madillafa02a22017-11-23 12:57:38 -0500118gl::Error ContextNULL::finish(const gl::Context *context)
Geoff Langd08f3b32016-09-23 15:56:30 -0400119{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400120 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400121}
122
Jamie Madillc564c072017-06-01 12:45:42 -0400123gl::Error ContextNULL::drawArrays(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400124 gl::PrimitiveMode mode,
Jamie Madillc564c072017-06-01 12:45:42 -0400125 GLint first,
126 GLsizei count)
Geoff Langd08f3b32016-09-23 15:56:30 -0400127{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400128 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400129}
130
Jamie Madillc564c072017-06-01 12:45:42 -0400131gl::Error ContextNULL::drawArraysInstanced(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400132 gl::PrimitiveMode mode,
Geoff Langd08f3b32016-09-23 15:56:30 -0400133 GLint first,
134 GLsizei count,
135 GLsizei instanceCount)
136{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400137 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400138}
139
Jamie Madillc564c072017-06-01 12:45:42 -0400140gl::Error ContextNULL::drawElements(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400141 gl::PrimitiveMode mode,
Geoff Langd08f3b32016-09-23 15:56:30 -0400142 GLsizei count,
143 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800144 const void *indices)
Geoff Langd08f3b32016-09-23 15:56:30 -0400145{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400146 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400147}
148
Jamie Madillc564c072017-06-01 12:45:42 -0400149gl::Error ContextNULL::drawElementsInstanced(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400150 gl::PrimitiveMode mode,
Geoff Langd08f3b32016-09-23 15:56:30 -0400151 GLsizei count,
152 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -0400153 const void *indices,
Qin Jiajia1da00652017-06-20 17:16:25 +0800154 GLsizei instances)
Geoff Langd08f3b32016-09-23 15:56:30 -0400155{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400156 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400157}
158
Jamie Madillc564c072017-06-01 12:45:42 -0400159gl::Error ContextNULL::drawRangeElements(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400160 gl::PrimitiveMode mode,
Geoff Langd08f3b32016-09-23 15:56:30 -0400161 GLuint start,
162 GLuint end,
163 GLsizei count,
164 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800165 const void *indices)
Geoff Langd08f3b32016-09-23 15:56:30 -0400166{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400167 return gl::NoError();
168}
169
Jamie Madillc564c072017-06-01 12:45:42 -0400170gl::Error ContextNULL::drawArraysIndirect(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400171 gl::PrimitiveMode mode,
Jamie Madillc564c072017-06-01 12:45:42 -0400172 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800173{
174 return gl::NoError();
175}
176
Jamie Madillc564c072017-06-01 12:45:42 -0400177gl::Error ContextNULL::drawElementsIndirect(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400178 gl::PrimitiveMode mode,
Jamie Madillc564c072017-06-01 12:45:42 -0400179 GLenum type,
180 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800181{
182 return gl::NoError();
183}
184
Geoff Lang76cdbd52016-09-23 16:51:04 -0400185void ContextNULL::stencilFillPath(const gl::Path *path, GLenum fillMode, GLuint mask)
186{
187}
188
189void ContextNULL::stencilStrokePath(const gl::Path *path, GLint reference, GLuint mask)
190{
191}
192
193void ContextNULL::coverFillPath(const gl::Path *path, GLenum coverMode)
194{
195}
196
197void ContextNULL::coverStrokePath(const gl::Path *path, GLenum coverMode)
198{
199}
200
201void ContextNULL::stencilThenCoverFillPath(const gl::Path *path,
202 GLenum fillMode,
203 GLuint mask,
204 GLenum coverMode)
205{
206}
207
208void ContextNULL::stencilThenCoverStrokePath(const gl::Path *path,
209 GLint reference,
210 GLuint mask,
211 GLenum coverMode)
212{
213}
214
215void ContextNULL::coverFillPathInstanced(const std::vector<gl::Path *> &paths,
216 GLenum coverMode,
217 GLenum transformType,
218 const GLfloat *transformValues)
219{
220}
221
222void ContextNULL::coverStrokePathInstanced(const std::vector<gl::Path *> &paths,
223 GLenum coverMode,
224 GLenum transformType,
225 const GLfloat *transformValues)
226{
227}
228
229void ContextNULL::stencilFillPathInstanced(const std::vector<gl::Path *> &paths,
230 GLenum fillMode,
231 GLuint mask,
232 GLenum transformType,
233 const GLfloat *transformValues)
234{
235}
236
237void ContextNULL::stencilStrokePathInstanced(const std::vector<gl::Path *> &paths,
238 GLint reference,
239 GLuint mask,
240 GLenum transformType,
241 const GLfloat *transformValues)
242{
243}
244
245void ContextNULL::stencilThenCoverFillPathInstanced(const std::vector<gl::Path *> &paths,
246 GLenum coverMode,
247 GLenum fillMode,
248 GLuint mask,
249 GLenum transformType,
250 const GLfloat *transformValues)
251{
252}
253
254void ContextNULL::stencilThenCoverStrokePathInstanced(const std::vector<gl::Path *> &paths,
255 GLenum coverMode,
256 GLint reference,
257 GLuint mask,
258 GLenum transformType,
259 const GLfloat *transformValues)
260{
261}
262
263GLenum ContextNULL::getResetStatus()
264{
265 return GL_NO_ERROR;
266}
267
268std::string ContextNULL::getVendorString() const
269{
270 return "NULL";
271}
272
273std::string ContextNULL::getRendererDescription() const
274{
275 return "NULL";
276}
277
278void ContextNULL::insertEventMarker(GLsizei length, const char *marker)
279{
280}
281
282void ContextNULL::pushGroupMarker(GLsizei length, const char *marker)
283{
284}
285
286void ContextNULL::popGroupMarker()
287{
288}
289
Geoff Lang5d5253a2017-11-22 14:51:12 -0500290void ContextNULL::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message)
291{
292}
293
294void ContextNULL::popDebugGroup()
295{
296}
297
Jamie Madill189ad872018-07-09 13:32:37 -0400298gl::Error ContextNULL::syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits)
Geoff Lang76cdbd52016-09-23 16:51:04 -0400299{
Jamie Madill189ad872018-07-09 13:32:37 -0400300 return gl::NoError();
Geoff Lang76cdbd52016-09-23 16:51:04 -0400301}
302
303GLint ContextNULL::getGPUDisjoint()
304{
305 return 0;
306}
307
308GLint64 ContextNULL::getTimestamp()
309{
310 return 0;
311}
312
Jamie Madill4928b7c2017-06-20 12:57:39 -0400313void ContextNULL::onMakeCurrent(const gl::Context *context)
Geoff Lang76cdbd52016-09-23 16:51:04 -0400314{
315}
316
Jiawei Shaod0a7d102018-05-07 12:40:20 +0800317gl::Caps ContextNULL::getNativeCaps() const
Geoff Lang76cdbd52016-09-23 16:51:04 -0400318{
319 return mCaps;
320}
321
322const gl::TextureCapsMap &ContextNULL::getNativeTextureCaps() const
323{
324 return mTextureCaps;
325}
326
327const gl::Extensions &ContextNULL::getNativeExtensions() const
328{
329 return mExtensions;
330}
331
332const gl::Limitations &ContextNULL::getNativeLimitations() const
333{
334 return mLimitations;
Geoff Langd08f3b32016-09-23 15:56:30 -0400335}
336
337CompilerImpl *ContextNULL::createCompiler()
338{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400339 return new CompilerNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400340}
341
342ShaderImpl *ContextNULL::createShader(const gl::ShaderState &data)
343{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400344 return new ShaderNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400345}
346
347ProgramImpl *ContextNULL::createProgram(const gl::ProgramState &data)
348{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400349 return new ProgramNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400350}
351
352FramebufferImpl *ContextNULL::createFramebuffer(const gl::FramebufferState &data)
353{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400354 return new FramebufferNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400355}
356
357TextureImpl *ContextNULL::createTexture(const gl::TextureState &state)
358{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400359 return new TextureNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400360}
361
Jamie Madille703c602018-02-20 10:21:48 -0500362RenderbufferImpl *ContextNULL::createRenderbuffer(const gl::RenderbufferState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400363{
Jamie Madille703c602018-02-20 10:21:48 -0500364 return new RenderbufferNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400365}
366
Jamie Madill8f775602016-11-03 16:45:34 -0400367BufferImpl *ContextNULL::createBuffer(const gl::BufferState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400368{
Geoff Lang1b60d8d2017-02-10 14:56:55 -0500369 return new BufferNULL(state, mAllocationTracker);
Geoff Langd08f3b32016-09-23 15:56:30 -0400370}
371
372VertexArrayImpl *ContextNULL::createVertexArray(const gl::VertexArrayState &data)
373{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400374 return new VertexArrayNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400375}
376
Corentin Wallezad3ae902018-03-09 13:40:42 -0500377QueryImpl *ContextNULL::createQuery(gl::QueryType type)
Geoff Langd08f3b32016-09-23 15:56:30 -0400378{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400379 return new QueryNULL(type);
Geoff Langd08f3b32016-09-23 15:56:30 -0400380}
381
382FenceNVImpl *ContextNULL::createFenceNV()
383{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400384 return new FenceNVNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400385}
386
Jamie Madill70b5bb02017-08-28 13:32:37 -0400387SyncImpl *ContextNULL::createSync()
Geoff Langd08f3b32016-09-23 15:56:30 -0400388{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400389 return new SyncNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400390}
391
392TransformFeedbackImpl *ContextNULL::createTransformFeedback(const gl::TransformFeedbackState &state)
393{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400394 return new TransformFeedbackNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400395}
396
Jamie Madill06ef36b2017-09-09 23:32:46 -0400397SamplerImpl *ContextNULL::createSampler(const gl::SamplerState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400398{
Jamie Madill06ef36b2017-09-09 23:32:46 -0400399 return new SamplerNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400400}
401
Yunchao Hea336b902017-08-02 16:05:21 +0800402ProgramPipelineImpl *ContextNULL::createProgramPipeline(const gl::ProgramPipelineState &state)
403{
404 return new ProgramPipelineNULL(state);
405}
406
Geoff Langd08f3b32016-09-23 15:56:30 -0400407std::vector<PathImpl *> ContextNULL::createPaths(GLsizei range)
408{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400409 std::vector<PathImpl *> result(range);
410 for (GLsizei idx = 0; idx < range; idx++)
411 {
412 result[idx] = new PathNULL();
413 }
414 return result;
Geoff Langd08f3b32016-09-23 15:56:30 -0400415}
416
Jamie Madillfe548342017-06-19 11:13:24 -0400417gl::Error ContextNULL::dispatchCompute(const gl::Context *context,
418 GLuint numGroupsX,
419 GLuint numGroupsY,
420 GLuint numGroupsZ)
Xinghua Cao2b396592017-03-29 15:36:04 +0800421{
422 return gl::NoError();
423}
424
Qin Jiajia62fcf622017-11-30 16:16:12 +0800425gl::Error ContextNULL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
426{
427 return gl::NoError();
428}
429
Xinghua Cao89c422a2017-11-29 18:24:20 +0800430gl::Error ContextNULL::memoryBarrier(const gl::Context *context, GLbitfield barriers)
431{
432 return gl::NoError();
433}
434
435gl::Error ContextNULL::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
436{
437 return gl::NoError();
438}
439
Geoff Langd08f3b32016-09-23 15:56:30 -0400440} // namespace rx