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