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.mapBufferRangeEXT = true;
78 mExtensions.copyTextureCHROMIUM = true;
79 mExtensions.copyCompressedTextureCHROMIUM = true;
80 mExtensions.textureRectangleANGLE = true;
81 mExtensions.textureUsageANGLE = true;
82 mExtensions.vertexArrayObjectOES = true;
83 mExtensions.debugMarkerEXT = true;
84 mExtensions.translatedShaderSourceANGLE = true;
85
86 mExtensions.textureStorageEXT = true;
87 mExtensions.rgb8Rgba8OES = true;
88 mExtensions.textureCompressionDxt1EXT = true;
89 mExtensions.textureCompressionDxt3ANGLE = true;
90 mExtensions.textureCompressionDxt5ANGLE = true;
91 mExtensions.textureCompressionS3tcSrgbEXT = true;
92 mExtensions.textureCompressionAstcHdrKHR = true;
93 mExtensions.textureCompressionAstcLdrKHR = true;
94 mExtensions.textureCompressionAstcOES = true;
95 mExtensions.compressedETC1RGB8TextureOES = true;
96 mExtensions.compressedETC1RGB8SubTextureEXT = true;
97 mExtensions.lossyEtcDecodeANGLE = true;
98 mExtensions.geometryShaderEXT = true;
99 mExtensions.geometryShaderOES = true;
100 mExtensions.multiDrawIndirectEXT = true;
101
102 mExtensions.EGLImageOES = true;
103 mExtensions.EGLImageExternalOES = true;
104 mExtensions.EGLImageExternalEssl3OES = true;
105 mExtensions.EGLImageArrayEXT = true;
106 mExtensions.EGLStreamConsumerExternalNV = true;
107
108 const gl::Version maxClientVersion(3, 1);
109 mCaps = GenerateMinimumCaps(maxClientVersion, mExtensions);
110
111 InitMinimumTextureCapsMap(maxClientVersion, mExtensions, &mTextureCaps);
112 }
113
~ContextNULL()114 ContextNULL::~ContextNULL() {}
115
initialize()116 angle::Result ContextNULL::initialize()
117 {
118 return angle::Result::Continue;
119 }
120
flush(const gl::Context * context)121 angle::Result ContextNULL::flush(const gl::Context *context)
122 {
123 return angle::Result::Continue;
124 }
125
finish(const gl::Context * context)126 angle::Result ContextNULL::finish(const gl::Context *context)
127 {
128 return angle::Result::Continue;
129 }
130
drawArrays(const gl::Context * context,gl::PrimitiveMode mode,GLint first,GLsizei count)131 angle::Result ContextNULL::drawArrays(const gl::Context *context,
132 gl::PrimitiveMode mode,
133 GLint first,
134 GLsizei count)
135 {
136 return angle::Result::Continue;
137 }
138
drawArraysInstanced(const gl::Context * context,gl::PrimitiveMode mode,GLint first,GLsizei count,GLsizei instanceCount)139 angle::Result ContextNULL::drawArraysInstanced(const gl::Context *context,
140 gl::PrimitiveMode mode,
141 GLint first,
142 GLsizei count,
143 GLsizei instanceCount)
144 {
145 return angle::Result::Continue;
146 }
147
drawArraysInstancedBaseInstance(const gl::Context * context,gl::PrimitiveMode mode,GLint first,GLsizei count,GLsizei instanceCount,GLuint baseInstance)148 angle::Result ContextNULL::drawArraysInstancedBaseInstance(const gl::Context *context,
149 gl::PrimitiveMode mode,
150 GLint first,
151 GLsizei count,
152 GLsizei instanceCount,
153 GLuint baseInstance)
154 {
155 return angle::Result::Continue;
156 }
157
drawElements(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices)158 angle::Result ContextNULL::drawElements(const gl::Context *context,
159 gl::PrimitiveMode mode,
160 GLsizei count,
161 gl::DrawElementsType type,
162 const void *indices)
163 {
164 return angle::Result::Continue;
165 }
166
drawElementsBaseVertex(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLint baseVertex)167 angle::Result ContextNULL::drawElementsBaseVertex(const gl::Context *context,
168 gl::PrimitiveMode mode,
169 GLsizei count,
170 gl::DrawElementsType type,
171 const void *indices,
172 GLint baseVertex)
173 {
174 return angle::Result::Continue;
175 }
176
drawElementsInstanced(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instances)177 angle::Result ContextNULL::drawElementsInstanced(const gl::Context *context,
178 gl::PrimitiveMode mode,
179 GLsizei count,
180 gl::DrawElementsType type,
181 const void *indices,
182 GLsizei instances)
183 {
184 return angle::Result::Continue;
185 }
186
drawElementsInstancedBaseVertex(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instances,GLint baseVertex)187 angle::Result ContextNULL::drawElementsInstancedBaseVertex(const gl::Context *context,
188 gl::PrimitiveMode mode,
189 GLsizei count,
190 gl::DrawElementsType type,
191 const void *indices,
192 GLsizei instances,
193 GLint baseVertex)
194 {
195 return angle::Result::Continue;
196 }
197
drawElementsInstancedBaseVertexBaseInstance(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instances,GLint baseVertex,GLuint baseInstance)198 angle::Result ContextNULL::drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context,
199 gl::PrimitiveMode mode,
200 GLsizei count,
201 gl::DrawElementsType type,
202 const void *indices,
203 GLsizei instances,
204 GLint baseVertex,
205 GLuint baseInstance)
206 {
207 return angle::Result::Continue;
208 }
209
drawRangeElements(const gl::Context * context,gl::PrimitiveMode mode,GLuint start,GLuint end,GLsizei count,gl::DrawElementsType type,const void * indices)210 angle::Result ContextNULL::drawRangeElements(const gl::Context *context,
211 gl::PrimitiveMode mode,
212 GLuint start,
213 GLuint end,
214 GLsizei count,
215 gl::DrawElementsType type,
216 const void *indices)
217 {
218 return angle::Result::Continue;
219 }
220
drawRangeElementsBaseVertex(const gl::Context * context,gl::PrimitiveMode mode,GLuint start,GLuint end,GLsizei count,gl::DrawElementsType type,const void * indices,GLint baseVertex)221 angle::Result ContextNULL::drawRangeElementsBaseVertex(const gl::Context *context,
222 gl::PrimitiveMode mode,
223 GLuint start,
224 GLuint end,
225 GLsizei count,
226 gl::DrawElementsType type,
227 const void *indices,
228 GLint baseVertex)
229 {
230 return angle::Result::Continue;
231 }
232
drawArraysIndirect(const gl::Context * context,gl::PrimitiveMode mode,const void * indirect)233 angle::Result ContextNULL::drawArraysIndirect(const gl::Context *context,
234 gl::PrimitiveMode mode,
235 const void *indirect)
236 {
237 return angle::Result::Continue;
238 }
239
drawElementsIndirect(const gl::Context * context,gl::PrimitiveMode mode,gl::DrawElementsType type,const void * indirect)240 angle::Result ContextNULL::drawElementsIndirect(const gl::Context *context,
241 gl::PrimitiveMode mode,
242 gl::DrawElementsType type,
243 const void *indirect)
244 {
245 return angle::Result::Continue;
246 }
247
multiDrawArrays(const gl::Context * context,gl::PrimitiveMode mode,const GLint * firsts,const GLsizei * counts,GLsizei drawcount)248 angle::Result ContextNULL::multiDrawArrays(const gl::Context *context,
249 gl::PrimitiveMode mode,
250 const GLint *firsts,
251 const GLsizei *counts,
252 GLsizei drawcount)
253 {
254 return angle::Result::Continue;
255 }
256
multiDrawArraysInstanced(const gl::Context * context,gl::PrimitiveMode mode,const GLint * firsts,const GLsizei * counts,const GLsizei * instanceCounts,GLsizei drawcount)257 angle::Result ContextNULL::multiDrawArraysInstanced(const gl::Context *context,
258 gl::PrimitiveMode mode,
259 const GLint *firsts,
260 const GLsizei *counts,
261 const GLsizei *instanceCounts,
262 GLsizei drawcount)
263 {
264 return angle::Result::Continue;
265 }
266
multiDrawArraysIndirect(const gl::Context * context,gl::PrimitiveMode mode,const void * indirect,GLsizei drawcount,GLsizei stride)267 angle::Result ContextNULL::multiDrawArraysIndirect(const gl::Context *context,
268 gl::PrimitiveMode mode,
269 const void *indirect,
270 GLsizei drawcount,
271 GLsizei stride)
272 {
273 return angle::Result::Continue;
274 }
275
multiDrawElements(const gl::Context * context,gl::PrimitiveMode mode,const GLsizei * counts,gl::DrawElementsType type,const GLvoid * const * indices,GLsizei drawcount)276 angle::Result ContextNULL::multiDrawElements(const gl::Context *context,
277 gl::PrimitiveMode mode,
278 const GLsizei *counts,
279 gl::DrawElementsType type,
280 const GLvoid *const *indices,
281 GLsizei drawcount)
282 {
283 return angle::Result::Continue;
284 }
285
multiDrawElementsInstanced(const gl::Context * context,gl::PrimitiveMode mode,const GLsizei * counts,gl::DrawElementsType type,const GLvoid * const * indices,const GLsizei * instanceCounts,GLsizei drawcount)286 angle::Result ContextNULL::multiDrawElementsInstanced(const gl::Context *context,
287 gl::PrimitiveMode mode,
288 const GLsizei *counts,
289 gl::DrawElementsType type,
290 const GLvoid *const *indices,
291 const GLsizei *instanceCounts,
292 GLsizei drawcount)
293 {
294 return angle::Result::Continue;
295 }
296
multiDrawElementsIndirect(const gl::Context * context,gl::PrimitiveMode mode,gl::DrawElementsType type,const void * indirect,GLsizei drawcount,GLsizei stride)297 angle::Result ContextNULL::multiDrawElementsIndirect(const gl::Context *context,
298 gl::PrimitiveMode mode,
299 gl::DrawElementsType type,
300 const void *indirect,
301 GLsizei drawcount,
302 GLsizei stride)
303 {
304 return angle::Result::Continue;
305 }
306
multiDrawArraysInstancedBaseInstance(const gl::Context * context,gl::PrimitiveMode mode,const GLint * firsts,const GLsizei * counts,const GLsizei * instanceCounts,const GLuint * baseInstances,GLsizei drawcount)307 angle::Result ContextNULL::multiDrawArraysInstancedBaseInstance(const gl::Context *context,
308 gl::PrimitiveMode mode,
309 const GLint *firsts,
310 const GLsizei *counts,
311 const GLsizei *instanceCounts,
312 const GLuint *baseInstances,
313 GLsizei drawcount)
314 {
315 return angle::Result::Continue;
316 }
317
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)318 angle::Result ContextNULL::multiDrawElementsInstancedBaseVertexBaseInstance(
319 const gl::Context *context,
320 gl::PrimitiveMode mode,
321 const GLsizei *counts,
322 gl::DrawElementsType type,
323 const GLvoid *const *indices,
324 const GLsizei *instanceCounts,
325 const GLint *baseVertices,
326 const GLuint *baseInstances,
327 GLsizei drawcount)
328 {
329 return angle::Result::Continue;
330 }
331
getResetStatus()332 gl::GraphicsResetStatus ContextNULL::getResetStatus()
333 {
334 return gl::GraphicsResetStatus::NoError;
335 }
336
insertEventMarker(GLsizei length,const char * marker)337 angle::Result ContextNULL::insertEventMarker(GLsizei length, const char *marker)
338 {
339 return angle::Result::Continue;
340 }
341
pushGroupMarker(GLsizei length,const char * marker)342 angle::Result ContextNULL::pushGroupMarker(GLsizei length, const char *marker)
343 {
344 return angle::Result::Continue;
345 }
346
popGroupMarker()347 angle::Result ContextNULL::popGroupMarker()
348 {
349 return angle::Result::Continue;
350 }
351
pushDebugGroup(const gl::Context * context,GLenum source,GLuint id,const std::string & message)352 angle::Result ContextNULL::pushDebugGroup(const gl::Context *context,
353 GLenum source,
354 GLuint id,
355 const std::string &message)
356 {
357 return angle::Result::Continue;
358 }
359
popDebugGroup(const gl::Context * context)360 angle::Result ContextNULL::popDebugGroup(const gl::Context *context)
361 {
362 return angle::Result::Continue;
363 }
364
syncState(const gl::Context * context,const gl::State::DirtyBits & dirtyBits,const gl::State::DirtyBits & bitMask,gl::Command command)365 angle::Result ContextNULL::syncState(const gl::Context *context,
366 const gl::State::DirtyBits &dirtyBits,
367 const gl::State::DirtyBits &bitMask,
368 gl::Command command)
369 {
370 return angle::Result::Continue;
371 }
372
getGPUDisjoint()373 GLint ContextNULL::getGPUDisjoint()
374 {
375 return 0;
376 }
377
getTimestamp()378 GLint64 ContextNULL::getTimestamp()
379 {
380 return 0;
381 }
382
onMakeCurrent(const gl::Context * context)383 angle::Result ContextNULL::onMakeCurrent(const gl::Context *context)
384 {
385 return angle::Result::Continue;
386 }
387
getNativeCaps() const388 gl::Caps ContextNULL::getNativeCaps() const
389 {
390 return mCaps;
391 }
392
getNativeTextureCaps() const393 const gl::TextureCapsMap &ContextNULL::getNativeTextureCaps() const
394 {
395 return mTextureCaps;
396 }
397
getNativeExtensions() const398 const gl::Extensions &ContextNULL::getNativeExtensions() const
399 {
400 return mExtensions;
401 }
402
getNativeLimitations() const403 const gl::Limitations &ContextNULL::getNativeLimitations() const
404 {
405 return mLimitations;
406 }
407
createCompiler()408 CompilerImpl *ContextNULL::createCompiler()
409 {
410 return new CompilerNULL();
411 }
412
createShader(const gl::ShaderState & data)413 ShaderImpl *ContextNULL::createShader(const gl::ShaderState &data)
414 {
415 return new ShaderNULL(data);
416 }
417
createProgram(const gl::ProgramState & data)418 ProgramImpl *ContextNULL::createProgram(const gl::ProgramState &data)
419 {
420 return new ProgramNULL(data);
421 }
422
createFramebuffer(const gl::FramebufferState & data)423 FramebufferImpl *ContextNULL::createFramebuffer(const gl::FramebufferState &data)
424 {
425 return new FramebufferNULL(data);
426 }
427
createTexture(const gl::TextureState & state)428 TextureImpl *ContextNULL::createTexture(const gl::TextureState &state)
429 {
430 return new TextureNULL(state);
431 }
432
createRenderbuffer(const gl::RenderbufferState & state)433 RenderbufferImpl *ContextNULL::createRenderbuffer(const gl::RenderbufferState &state)
434 {
435 return new RenderbufferNULL(state);
436 }
437
createBuffer(const gl::BufferState & state)438 BufferImpl *ContextNULL::createBuffer(const gl::BufferState &state)
439 {
440 return new BufferNULL(state, mAllocationTracker);
441 }
442
createVertexArray(const gl::VertexArrayState & data)443 VertexArrayImpl *ContextNULL::createVertexArray(const gl::VertexArrayState &data)
444 {
445 return new VertexArrayNULL(data);
446 }
447
createQuery(gl::QueryType type)448 QueryImpl *ContextNULL::createQuery(gl::QueryType type)
449 {
450 return new QueryNULL(type);
451 }
452
createFenceNV()453 FenceNVImpl *ContextNULL::createFenceNV()
454 {
455 return new FenceNVNULL();
456 }
457
createSync()458 SyncImpl *ContextNULL::createSync()
459 {
460 return new SyncNULL();
461 }
462
createTransformFeedback(const gl::TransformFeedbackState & state)463 TransformFeedbackImpl *ContextNULL::createTransformFeedback(const gl::TransformFeedbackState &state)
464 {
465 return new TransformFeedbackNULL(state);
466 }
467
createSampler(const gl::SamplerState & state)468 SamplerImpl *ContextNULL::createSampler(const gl::SamplerState &state)
469 {
470 return new SamplerNULL(state);
471 }
472
createProgramPipeline(const gl::ProgramPipelineState & state)473 ProgramPipelineImpl *ContextNULL::createProgramPipeline(const gl::ProgramPipelineState &state)
474 {
475 return new ProgramPipelineNULL(state);
476 }
477
createMemoryObject()478 MemoryObjectImpl *ContextNULL::createMemoryObject()
479 {
480 UNREACHABLE();
481 return nullptr;
482 }
483
createSemaphore()484 SemaphoreImpl *ContextNULL::createSemaphore()
485 {
486 UNREACHABLE();
487 return nullptr;
488 }
489
createOverlay(const gl::OverlayState & state)490 OverlayImpl *ContextNULL::createOverlay(const gl::OverlayState &state)
491 {
492 return new OverlayImpl(state);
493 }
494
dispatchCompute(const gl::Context * context,GLuint numGroupsX,GLuint numGroupsY,GLuint numGroupsZ)495 angle::Result ContextNULL::dispatchCompute(const gl::Context *context,
496 GLuint numGroupsX,
497 GLuint numGroupsY,
498 GLuint numGroupsZ)
499 {
500 return angle::Result::Continue;
501 }
502
dispatchComputeIndirect(const gl::Context * context,GLintptr indirect)503 angle::Result ContextNULL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
504 {
505 return angle::Result::Continue;
506 }
507
memoryBarrier(const gl::Context * context,GLbitfield barriers)508 angle::Result ContextNULL::memoryBarrier(const gl::Context *context, GLbitfield barriers)
509 {
510 return angle::Result::Continue;
511 }
512
memoryBarrierByRegion(const gl::Context * context,GLbitfield barriers)513 angle::Result ContextNULL::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
514 {
515 return angle::Result::Continue;
516 }
517
handleError(GLenum errorCode,const char * message,const char * file,const char * function,unsigned int line)518 void ContextNULL::handleError(GLenum errorCode,
519 const char *message,
520 const char *file,
521 const char *function,
522 unsigned int line)
523 {
524 std::stringstream errorStream;
525 errorStream << "Internal NULL back-end error: " << message << ".";
526 mErrors->handleError(errorCode, errorStream.str().c_str(), file, function, line);
527 }
528 } // namespace rx
529