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 // 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
14 #include "libANGLE/Context.h"
15 #include "libANGLE/renderer/OverlayImpl.h"
16 #include "libANGLE/renderer/null/BufferNULL.h"
17 #include "libANGLE/renderer/null/CompilerNULL.h"
18 #include "libANGLE/renderer/null/DisplayNULL.h"
19 #include "libANGLE/renderer/null/FenceNVNULL.h"
20 #include "libANGLE/renderer/null/FramebufferNULL.h"
21 #include "libANGLE/renderer/null/ImageNULL.h"
22 #include "libANGLE/renderer/null/ProgramNULL.h"
23 #include "libANGLE/renderer/null/ProgramPipelineNULL.h"
24 #include "libANGLE/renderer/null/QueryNULL.h"
25 #include "libANGLE/renderer/null/RenderbufferNULL.h"
26 #include "libANGLE/renderer/null/SamplerNULL.h"
27 #include "libANGLE/renderer/null/ShaderNULL.h"
28 #include "libANGLE/renderer/null/SyncNULL.h"
29 #include "libANGLE/renderer/null/TextureNULL.h"
30 #include "libANGLE/renderer/null/TransformFeedbackNULL.h"
31 #include "libANGLE/renderer/null/VertexArrayNULL.h"
32
33 namespace rx
34 {
35
AllocationTrackerNULL(size_t maxTotalAllocationSize)36 AllocationTrackerNULL::AllocationTrackerNULL(size_t maxTotalAllocationSize)
37 : mAllocatedBytes(0), mMaxBytes(maxTotalAllocationSize)
38 {}
39
~AllocationTrackerNULL()40 AllocationTrackerNULL::~AllocationTrackerNULL()
41 {
42 // ASSERT that all objects with the NULL renderer clean up after themselves
43 ASSERT(mAllocatedBytes == 0);
44 }
45
updateMemoryAllocation(size_t oldSize,size_t newSize)46 bool 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
ContextNULL(const gl::State & state,gl::ErrorSet * errorSet,AllocationTrackerNULL * allocationTracker)62 ContextNULL::ContextNULL(const gl::State &state,
63 gl::ErrorSet *errorSet,
64 AllocationTrackerNULL *allocationTracker)
65 : ContextImpl(state, errorSet), mAllocationTracker(allocationTracker)
66 {
67 ASSERT(mAllocationTracker != nullptr);
68
69 mExtensions = gl::Extensions();
70 mExtensions.fenceNV = true;
71 mExtensions.framebufferBlitANGLE = true;
72 mExtensions.framebufferBlitNV = true;
73 mExtensions.instancedArraysANGLE = true;
74 mExtensions.instancedArraysEXT = true;
75 mExtensions.pixelBufferObjectNV = true;
76 mExtensions.mapBufferOES = true;
77 mExtensions.mapBufferRange = true;
78 mExtensions.copyTexture = true;
79 mExtensions.copyCompressedTexture = true;
80 mExtensions.textureRectangle = true;
81 mExtensions.textureUsage = true;
82 mExtensions.vertexArrayObjectOES = true;
83 mExtensions.debugMarker = true;
84 mExtensions.translatedShaderSource = true;
85
86 mExtensions.textureStorage = true;
87 mExtensions.rgb8rgba8OES = true;
88 mExtensions.textureCompressionDXT1 = true;
89 mExtensions.textureCompressionDXT3 = true;
90 mExtensions.textureCompressionDXT5 = true;
91 mExtensions.textureCompressionS3TCsRGB = true;
92 mExtensions.textureCompressionASTCHDRKHR = true;
93 mExtensions.textureCompressionASTCLDRKHR = true;
94 mExtensions.textureCompressionASTCOES = true;
95 mExtensions.compressedETC1RGB8TextureOES = true;
96 mExtensions.compressedETC1RGB8SubTexture = true;
97 mExtensions.lossyETCDecode = true;
98 mExtensions.geometryShaderEXT = true;
99 mExtensions.geometryShaderOES = true;
100
101 mExtensions.eglImageOES = true;
102 mExtensions.eglImageExternalOES = true;
103 mExtensions.eglImageExternalEssl3OES = true;
104 mExtensions.eglImageArray = true;
105 mExtensions.eglStreamConsumerExternalNV = true;
106
107 const gl::Version maxClientVersion(3, 1);
108 mCaps = GenerateMinimumCaps(maxClientVersion, mExtensions);
109
110 InitMinimumTextureCapsMap(maxClientVersion, mExtensions, &mTextureCaps);
111 }
112
~ContextNULL()113 ContextNULL::~ContextNULL() {}
114
initialize()115 angle::Result ContextNULL::initialize()
116 {
117 return angle::Result::Continue;
118 }
119
flush(const gl::Context * context)120 angle::Result ContextNULL::flush(const gl::Context *context)
121 {
122 return angle::Result::Continue;
123 }
124
finish(const gl::Context * context)125 angle::Result ContextNULL::finish(const gl::Context *context)
126 {
127 return angle::Result::Continue;
128 }
129
drawArrays(const gl::Context * context,gl::PrimitiveMode mode,GLint first,GLsizei count)130 angle::Result ContextNULL::drawArrays(const gl::Context *context,
131 gl::PrimitiveMode mode,
132 GLint first,
133 GLsizei count)
134 {
135 return angle::Result::Continue;
136 }
137
drawArraysInstanced(const gl::Context * context,gl::PrimitiveMode mode,GLint first,GLsizei count,GLsizei instanceCount)138 angle::Result ContextNULL::drawArraysInstanced(const gl::Context *context,
139 gl::PrimitiveMode mode,
140 GLint first,
141 GLsizei count,
142 GLsizei instanceCount)
143 {
144 return angle::Result::Continue;
145 }
146
drawArraysInstancedBaseInstance(const gl::Context * context,gl::PrimitiveMode mode,GLint first,GLsizei count,GLsizei instanceCount,GLuint baseInstance)147 angle::Result ContextNULL::drawArraysInstancedBaseInstance(const gl::Context *context,
148 gl::PrimitiveMode mode,
149 GLint first,
150 GLsizei count,
151 GLsizei instanceCount,
152 GLuint baseInstance)
153 {
154 return angle::Result::Continue;
155 }
156
drawElements(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices)157 angle::Result ContextNULL::drawElements(const gl::Context *context,
158 gl::PrimitiveMode mode,
159 GLsizei count,
160 gl::DrawElementsType type,
161 const void *indices)
162 {
163 return angle::Result::Continue;
164 }
165
drawElementsBaseVertex(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLint baseVertex)166 angle::Result ContextNULL::drawElementsBaseVertex(const gl::Context *context,
167 gl::PrimitiveMode mode,
168 GLsizei count,
169 gl::DrawElementsType type,
170 const void *indices,
171 GLint baseVertex)
172 {
173 return angle::Result::Continue;
174 }
175
drawElementsInstanced(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instances)176 angle::Result ContextNULL::drawElementsInstanced(const gl::Context *context,
177 gl::PrimitiveMode mode,
178 GLsizei count,
179 gl::DrawElementsType type,
180 const void *indices,
181 GLsizei instances)
182 {
183 return angle::Result::Continue;
184 }
185
drawElementsInstancedBaseVertex(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instances,GLint baseVertex)186 angle::Result ContextNULL::drawElementsInstancedBaseVertex(const gl::Context *context,
187 gl::PrimitiveMode mode,
188 GLsizei count,
189 gl::DrawElementsType type,
190 const void *indices,
191 GLsizei instances,
192 GLint baseVertex)
193 {
194 return angle::Result::Continue;
195 }
196
drawElementsInstancedBaseVertexBaseInstance(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instances,GLint baseVertex,GLuint baseInstance)197 angle::Result ContextNULL::drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context,
198 gl::PrimitiveMode mode,
199 GLsizei count,
200 gl::DrawElementsType type,
201 const void *indices,
202 GLsizei instances,
203 GLint baseVertex,
204 GLuint baseInstance)
205 {
206 return angle::Result::Continue;
207 }
208
drawRangeElements(const gl::Context * context,gl::PrimitiveMode mode,GLuint start,GLuint end,GLsizei count,gl::DrawElementsType type,const void * indices)209 angle::Result ContextNULL::drawRangeElements(const gl::Context *context,
210 gl::PrimitiveMode mode,
211 GLuint start,
212 GLuint end,
213 GLsizei count,
214 gl::DrawElementsType type,
215 const void *indices)
216 {
217 return angle::Result::Continue;
218 }
219
drawRangeElementsBaseVertex(const gl::Context * context,gl::PrimitiveMode mode,GLuint start,GLuint end,GLsizei count,gl::DrawElementsType type,const void * indices,GLint baseVertex)220 angle::Result ContextNULL::drawRangeElementsBaseVertex(const gl::Context *context,
221 gl::PrimitiveMode mode,
222 GLuint start,
223 GLuint end,
224 GLsizei count,
225 gl::DrawElementsType type,
226 const void *indices,
227 GLint baseVertex)
228 {
229 return angle::Result::Continue;
230 }
231
drawArraysIndirect(const gl::Context * context,gl::PrimitiveMode mode,const void * indirect)232 angle::Result ContextNULL::drawArraysIndirect(const gl::Context *context,
233 gl::PrimitiveMode mode,
234 const void *indirect)
235 {
236 return angle::Result::Continue;
237 }
238
drawElementsIndirect(const gl::Context * context,gl::PrimitiveMode mode,gl::DrawElementsType type,const void * indirect)239 angle::Result ContextNULL::drawElementsIndirect(const gl::Context *context,
240 gl::PrimitiveMode mode,
241 gl::DrawElementsType type,
242 const void *indirect)
243 {
244 return angle::Result::Continue;
245 }
246
multiDrawArrays(const gl::Context * context,gl::PrimitiveMode mode,const GLint * firsts,const GLsizei * counts,GLsizei drawcount)247 angle::Result ContextNULL::multiDrawArrays(const gl::Context *context,
248 gl::PrimitiveMode mode,
249 const GLint *firsts,
250 const GLsizei *counts,
251 GLsizei drawcount)
252 {
253 return angle::Result::Continue;
254 }
255
multiDrawArraysInstanced(const gl::Context * context,gl::PrimitiveMode mode,const GLint * firsts,const GLsizei * counts,const GLsizei * instanceCounts,GLsizei drawcount)256 angle::Result ContextNULL::multiDrawArraysInstanced(const gl::Context *context,
257 gl::PrimitiveMode mode,
258 const GLint *firsts,
259 const GLsizei *counts,
260 const GLsizei *instanceCounts,
261 GLsizei drawcount)
262 {
263 return angle::Result::Continue;
264 }
265
multiDrawElements(const gl::Context * context,gl::PrimitiveMode mode,const GLsizei * counts,gl::DrawElementsType type,const GLvoid * const * indices,GLsizei drawcount)266 angle::Result ContextNULL::multiDrawElements(const gl::Context *context,
267 gl::PrimitiveMode mode,
268 const GLsizei *counts,
269 gl::DrawElementsType type,
270 const GLvoid *const *indices,
271 GLsizei drawcount)
272 {
273 return angle::Result::Continue;
274 }
275
multiDrawElementsInstanced(const gl::Context * context,gl::PrimitiveMode mode,const GLsizei * counts,gl::DrawElementsType type,const GLvoid * const * indices,const GLsizei * instanceCounts,GLsizei drawcount)276 angle::Result ContextNULL::multiDrawElementsInstanced(const gl::Context *context,
277 gl::PrimitiveMode mode,
278 const GLsizei *counts,
279 gl::DrawElementsType type,
280 const GLvoid *const *indices,
281 const GLsizei *instanceCounts,
282 GLsizei drawcount)
283 {
284 return angle::Result::Continue;
285 }
286
multiDrawArraysInstancedBaseInstance(const gl::Context * context,gl::PrimitiveMode mode,const GLint * firsts,const GLsizei * counts,const GLsizei * instanceCounts,const GLuint * baseInstances,GLsizei drawcount)287 angle::Result ContextNULL::multiDrawArraysInstancedBaseInstance(const gl::Context *context,
288 gl::PrimitiveMode mode,
289 const GLint *firsts,
290 const GLsizei *counts,
291 const GLsizei *instanceCounts,
292 const GLuint *baseInstances,
293 GLsizei drawcount)
294 {
295 return angle::Result::Continue;
296 }
297
multiDrawElementsInstancedBaseVertexBaseInstance(const gl::Context * context,gl::PrimitiveMode mode,const GLsizei * counts,gl::DrawElementsType type,const GLvoid * const * indices,const GLsizei * instanceCounts,const GLint * baseVertices,const GLuint * baseInstances,GLsizei drawcount)298 angle::Result ContextNULL::multiDrawElementsInstancedBaseVertexBaseInstance(
299 const gl::Context *context,
300 gl::PrimitiveMode mode,
301 const GLsizei *counts,
302 gl::DrawElementsType type,
303 const GLvoid *const *indices,
304 const GLsizei *instanceCounts,
305 const GLint *baseVertices,
306 const GLuint *baseInstances,
307 GLsizei drawcount)
308 {
309 return angle::Result::Continue;
310 }
311
getResetStatus()312 gl::GraphicsResetStatus ContextNULL::getResetStatus()
313 {
314 return gl::GraphicsResetStatus::NoError;
315 }
316
insertEventMarker(GLsizei length,const char * marker)317 angle::Result ContextNULL::insertEventMarker(GLsizei length, const char *marker)
318 {
319 return angle::Result::Continue;
320 }
321
pushGroupMarker(GLsizei length,const char * marker)322 angle::Result ContextNULL::pushGroupMarker(GLsizei length, const char *marker)
323 {
324 return angle::Result::Continue;
325 }
326
popGroupMarker()327 angle::Result ContextNULL::popGroupMarker()
328 {
329 return angle::Result::Continue;
330 }
331
pushDebugGroup(const gl::Context * context,GLenum source,GLuint id,const std::string & message)332 angle::Result ContextNULL::pushDebugGroup(const gl::Context *context,
333 GLenum source,
334 GLuint id,
335 const std::string &message)
336 {
337 return angle::Result::Continue;
338 }
339
popDebugGroup(const gl::Context * context)340 angle::Result ContextNULL::popDebugGroup(const gl::Context *context)
341 {
342 return angle::Result::Continue;
343 }
344
syncState(const gl::Context * context,const gl::State::DirtyBits & dirtyBits,const gl::State::DirtyBits & bitMask)345 angle::Result ContextNULL::syncState(const gl::Context *context,
346 const gl::State::DirtyBits &dirtyBits,
347 const gl::State::DirtyBits &bitMask)
348 {
349 return angle::Result::Continue;
350 }
351
getGPUDisjoint()352 GLint ContextNULL::getGPUDisjoint()
353 {
354 return 0;
355 }
356
getTimestamp()357 GLint64 ContextNULL::getTimestamp()
358 {
359 return 0;
360 }
361
onMakeCurrent(const gl::Context * context)362 angle::Result ContextNULL::onMakeCurrent(const gl::Context *context)
363 {
364 return angle::Result::Continue;
365 }
366
getNativeCaps() const367 gl::Caps ContextNULL::getNativeCaps() const
368 {
369 return mCaps;
370 }
371
getNativeTextureCaps() const372 const gl::TextureCapsMap &ContextNULL::getNativeTextureCaps() const
373 {
374 return mTextureCaps;
375 }
376
getNativeExtensions() const377 const gl::Extensions &ContextNULL::getNativeExtensions() const
378 {
379 return mExtensions;
380 }
381
getNativeLimitations() const382 const gl::Limitations &ContextNULL::getNativeLimitations() const
383 {
384 return mLimitations;
385 }
386
createCompiler()387 CompilerImpl *ContextNULL::createCompiler()
388 {
389 return new CompilerNULL();
390 }
391
createShader(const gl::ShaderState & data)392 ShaderImpl *ContextNULL::createShader(const gl::ShaderState &data)
393 {
394 return new ShaderNULL(data);
395 }
396
createProgram(const gl::ProgramState & data)397 ProgramImpl *ContextNULL::createProgram(const gl::ProgramState &data)
398 {
399 return new ProgramNULL(data);
400 }
401
createFramebuffer(const gl::FramebufferState & data)402 FramebufferImpl *ContextNULL::createFramebuffer(const gl::FramebufferState &data)
403 {
404 return new FramebufferNULL(data);
405 }
406
createTexture(const gl::TextureState & state)407 TextureImpl *ContextNULL::createTexture(const gl::TextureState &state)
408 {
409 return new TextureNULL(state);
410 }
411
createRenderbuffer(const gl::RenderbufferState & state)412 RenderbufferImpl *ContextNULL::createRenderbuffer(const gl::RenderbufferState &state)
413 {
414 return new RenderbufferNULL(state);
415 }
416
createBuffer(const gl::BufferState & state)417 BufferImpl *ContextNULL::createBuffer(const gl::BufferState &state)
418 {
419 return new BufferNULL(state, mAllocationTracker);
420 }
421
createVertexArray(const gl::VertexArrayState & data)422 VertexArrayImpl *ContextNULL::createVertexArray(const gl::VertexArrayState &data)
423 {
424 return new VertexArrayNULL(data);
425 }
426
createQuery(gl::QueryType type)427 QueryImpl *ContextNULL::createQuery(gl::QueryType type)
428 {
429 return new QueryNULL(type);
430 }
431
createFenceNV()432 FenceNVImpl *ContextNULL::createFenceNV()
433 {
434 return new FenceNVNULL();
435 }
436
createSync()437 SyncImpl *ContextNULL::createSync()
438 {
439 return new SyncNULL();
440 }
441
createTransformFeedback(const gl::TransformFeedbackState & state)442 TransformFeedbackImpl *ContextNULL::createTransformFeedback(const gl::TransformFeedbackState &state)
443 {
444 return new TransformFeedbackNULL(state);
445 }
446
createSampler(const gl::SamplerState & state)447 SamplerImpl *ContextNULL::createSampler(const gl::SamplerState &state)
448 {
449 return new SamplerNULL(state);
450 }
451
createProgramPipeline(const gl::ProgramPipelineState & state)452 ProgramPipelineImpl *ContextNULL::createProgramPipeline(const gl::ProgramPipelineState &state)
453 {
454 return new ProgramPipelineNULL(state);
455 }
456
createMemoryObject()457 MemoryObjectImpl *ContextNULL::createMemoryObject()
458 {
459 UNREACHABLE();
460 return nullptr;
461 }
462
createSemaphore()463 SemaphoreImpl *ContextNULL::createSemaphore()
464 {
465 UNREACHABLE();
466 return nullptr;
467 }
468
createOverlay(const gl::OverlayState & state)469 OverlayImpl *ContextNULL::createOverlay(const gl::OverlayState &state)
470 {
471 return new OverlayImpl(state);
472 }
473
dispatchCompute(const gl::Context * context,GLuint numGroupsX,GLuint numGroupsY,GLuint numGroupsZ)474 angle::Result ContextNULL::dispatchCompute(const gl::Context *context,
475 GLuint numGroupsX,
476 GLuint numGroupsY,
477 GLuint numGroupsZ)
478 {
479 return angle::Result::Continue;
480 }
481
dispatchComputeIndirect(const gl::Context * context,GLintptr indirect)482 angle::Result ContextNULL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
483 {
484 return angle::Result::Continue;
485 }
486
memoryBarrier(const gl::Context * context,GLbitfield barriers)487 angle::Result ContextNULL::memoryBarrier(const gl::Context *context, GLbitfield barriers)
488 {
489 return angle::Result::Continue;
490 }
491
memoryBarrierByRegion(const gl::Context * context,GLbitfield barriers)492 angle::Result ContextNULL::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
493 {
494 return angle::Result::Continue;
495 }
496
handleError(GLenum errorCode,const char * message,const char * file,const char * function,unsigned int line)497 void ContextNULL::handleError(GLenum errorCode,
498 const char *message,
499 const char *file,
500 const char *function,
501 unsigned int line)
502 {
503 std::stringstream errorStream;
504 errorStream << "Internal NULL back-end error: " << message << ".";
505 mErrors->handleError(errorCode, errorStream.str().c_str(), file, function, line);
506 }
507 } // namespace rx
508