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