• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.framebufferBlit        = true;
72     mExtensions.instancedArraysANGLE   = true;
73     mExtensions.instancedArraysEXT     = true;
74     mExtensions.pixelBufferObjectNV    = true;
75     mExtensions.mapBufferOES           = true;
76     mExtensions.mapBufferRange         = true;
77     mExtensions.copyTexture            = true;
78     mExtensions.copyCompressedTexture  = true;
79     mExtensions.textureRectangle       = true;
80     mExtensions.textureUsage           = true;
81     mExtensions.vertexArrayObjectOES   = true;
82     mExtensions.debugMarker            = true;
83     mExtensions.translatedShaderSource = true;
84 
85     mExtensions.textureStorage               = true;
86     mExtensions.rgb8rgba8OES                 = true;
87     mExtensions.textureCompressionDXT1       = true;
88     mExtensions.textureCompressionDXT3       = true;
89     mExtensions.textureCompressionDXT5       = true;
90     mExtensions.textureCompressionS3TCsRGB   = true;
91     mExtensions.textureCompressionASTCHDRKHR = true;
92     mExtensions.textureCompressionASTCLDRKHR = true;
93     mExtensions.textureCompressionASTCOES    = true;
94     mExtensions.compressedETC1RGB8TextureOES = true;
95     mExtensions.compressedETC1RGB8SubTexture = true;
96     mExtensions.lossyETCDecode               = true;
97     mExtensions.geometryShader               = true;
98 
99     mExtensions.eglImageOES                 = true;
100     mExtensions.eglImageExternalOES         = true;
101     mExtensions.eglImageExternalEssl3OES    = true;
102     mExtensions.eglStreamConsumerExternalNV = true;
103 
104     const gl::Version maxClientVersion(3, 1);
105     mCaps = GenerateMinimumCaps(maxClientVersion, mExtensions);
106 
107     InitMinimumTextureCapsMap(maxClientVersion, mExtensions, &mTextureCaps);
108 }
109 
~ContextNULL()110 ContextNULL::~ContextNULL() {}
111 
initialize()112 angle::Result ContextNULL::initialize()
113 {
114     return angle::Result::Continue;
115 }
116 
flush(const gl::Context * context)117 angle::Result ContextNULL::flush(const gl::Context *context)
118 {
119     return angle::Result::Continue;
120 }
121 
finish(const gl::Context * context)122 angle::Result ContextNULL::finish(const gl::Context *context)
123 {
124     return angle::Result::Continue;
125 }
126 
drawArrays(const gl::Context * context,gl::PrimitiveMode mode,GLint first,GLsizei count)127 angle::Result ContextNULL::drawArrays(const gl::Context *context,
128                                       gl::PrimitiveMode mode,
129                                       GLint first,
130                                       GLsizei count)
131 {
132     return angle::Result::Continue;
133 }
134 
drawArraysInstanced(const gl::Context * context,gl::PrimitiveMode mode,GLint first,GLsizei count,GLsizei instanceCount)135 angle::Result ContextNULL::drawArraysInstanced(const gl::Context *context,
136                                                gl::PrimitiveMode mode,
137                                                GLint first,
138                                                GLsizei count,
139                                                GLsizei instanceCount)
140 {
141     return angle::Result::Continue;
142 }
143 
drawArraysInstancedBaseInstance(const gl::Context * context,gl::PrimitiveMode mode,GLint first,GLsizei count,GLsizei instanceCount,GLuint baseInstance)144 angle::Result ContextNULL::drawArraysInstancedBaseInstance(const gl::Context *context,
145                                                            gl::PrimitiveMode mode,
146                                                            GLint first,
147                                                            GLsizei count,
148                                                            GLsizei instanceCount,
149                                                            GLuint baseInstance)
150 {
151     return angle::Result::Continue;
152 }
153 
drawElements(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices)154 angle::Result ContextNULL::drawElements(const gl::Context *context,
155                                         gl::PrimitiveMode mode,
156                                         GLsizei count,
157                                         gl::DrawElementsType type,
158                                         const void *indices)
159 {
160     return angle::Result::Continue;
161 }
162 
drawElementsBaseVertex(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLint baseVertex)163 angle::Result ContextNULL::drawElementsBaseVertex(const gl::Context *context,
164                                                   gl::PrimitiveMode mode,
165                                                   GLsizei count,
166                                                   gl::DrawElementsType type,
167                                                   const void *indices,
168                                                   GLint baseVertex)
169 {
170     return angle::Result::Continue;
171 }
172 
drawElementsInstanced(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instances)173 angle::Result ContextNULL::drawElementsInstanced(const gl::Context *context,
174                                                  gl::PrimitiveMode mode,
175                                                  GLsizei count,
176                                                  gl::DrawElementsType type,
177                                                  const void *indices,
178                                                  GLsizei instances)
179 {
180     return angle::Result::Continue;
181 }
182 
drawElementsInstancedBaseVertex(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instances,GLint baseVertex)183 angle::Result ContextNULL::drawElementsInstancedBaseVertex(const gl::Context *context,
184                                                            gl::PrimitiveMode mode,
185                                                            GLsizei count,
186                                                            gl::DrawElementsType type,
187                                                            const void *indices,
188                                                            GLsizei instances,
189                                                            GLint baseVertex)
190 {
191     return angle::Result::Continue;
192 }
193 
drawElementsInstancedBaseVertexBaseInstance(const gl::Context * context,gl::PrimitiveMode mode,GLsizei count,gl::DrawElementsType type,const void * indices,GLsizei instances,GLint baseVertex,GLuint baseInstance)194 angle::Result ContextNULL::drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context,
195                                                                        gl::PrimitiveMode mode,
196                                                                        GLsizei count,
197                                                                        gl::DrawElementsType type,
198                                                                        const void *indices,
199                                                                        GLsizei instances,
200                                                                        GLint baseVertex,
201                                                                        GLuint baseInstance)
202 {
203     return angle::Result::Continue;
204 }
205 
drawRangeElements(const gl::Context * context,gl::PrimitiveMode mode,GLuint start,GLuint end,GLsizei count,gl::DrawElementsType type,const void * indices)206 angle::Result ContextNULL::drawRangeElements(const gl::Context *context,
207                                              gl::PrimitiveMode mode,
208                                              GLuint start,
209                                              GLuint end,
210                                              GLsizei count,
211                                              gl::DrawElementsType type,
212                                              const void *indices)
213 {
214     return angle::Result::Continue;
215 }
216 
drawRangeElementsBaseVertex(const gl::Context * context,gl::PrimitiveMode mode,GLuint start,GLuint end,GLsizei count,gl::DrawElementsType type,const void * indices,GLint baseVertex)217 angle::Result ContextNULL::drawRangeElementsBaseVertex(const gl::Context *context,
218                                                        gl::PrimitiveMode mode,
219                                                        GLuint start,
220                                                        GLuint end,
221                                                        GLsizei count,
222                                                        gl::DrawElementsType type,
223                                                        const void *indices,
224                                                        GLint baseVertex)
225 {
226     return angle::Result::Continue;
227 }
228 
drawArraysIndirect(const gl::Context * context,gl::PrimitiveMode mode,const void * indirect)229 angle::Result ContextNULL::drawArraysIndirect(const gl::Context *context,
230                                               gl::PrimitiveMode mode,
231                                               const void *indirect)
232 {
233     return angle::Result::Continue;
234 }
235 
drawElementsIndirect(const gl::Context * context,gl::PrimitiveMode mode,gl::DrawElementsType type,const void * indirect)236 angle::Result ContextNULL::drawElementsIndirect(const gl::Context *context,
237                                                 gl::PrimitiveMode mode,
238                                                 gl::DrawElementsType type,
239                                                 const void *indirect)
240 {
241     return angle::Result::Continue;
242 }
243 
getResetStatus()244 gl::GraphicsResetStatus ContextNULL::getResetStatus()
245 {
246     return gl::GraphicsResetStatus::NoError;
247 }
248 
getVendorString() const249 std::string ContextNULL::getVendorString() const
250 {
251     return "NULL";
252 }
253 
getRendererDescription() const254 std::string ContextNULL::getRendererDescription() const
255 {
256     return "NULL";
257 }
258 
insertEventMarker(GLsizei length,const char * marker)259 angle::Result ContextNULL::insertEventMarker(GLsizei length, const char *marker)
260 {
261     return angle::Result::Continue;
262 }
263 
pushGroupMarker(GLsizei length,const char * marker)264 angle::Result ContextNULL::pushGroupMarker(GLsizei length, const char *marker)
265 {
266     return angle::Result::Continue;
267 }
268 
popGroupMarker()269 angle::Result ContextNULL::popGroupMarker()
270 {
271     return angle::Result::Continue;
272 }
273 
pushDebugGroup(const gl::Context * context,GLenum source,GLuint id,const std::string & message)274 angle::Result ContextNULL::pushDebugGroup(const gl::Context *context,
275                                           GLenum source,
276                                           GLuint id,
277                                           const std::string &message)
278 {
279     return angle::Result::Continue;
280 }
281 
popDebugGroup(const gl::Context * context)282 angle::Result ContextNULL::popDebugGroup(const gl::Context *context)
283 {
284     return angle::Result::Continue;
285 }
286 
syncState(const gl::Context * context,const gl::State::DirtyBits & dirtyBits,const gl::State::DirtyBits & bitMask)287 angle::Result ContextNULL::syncState(const gl::Context *context,
288                                      const gl::State::DirtyBits &dirtyBits,
289                                      const gl::State::DirtyBits &bitMask)
290 {
291     return angle::Result::Continue;
292 }
293 
getGPUDisjoint()294 GLint ContextNULL::getGPUDisjoint()
295 {
296     return 0;
297 }
298 
getTimestamp()299 GLint64 ContextNULL::getTimestamp()
300 {
301     return 0;
302 }
303 
onMakeCurrent(const gl::Context * context)304 angle::Result ContextNULL::onMakeCurrent(const gl::Context *context)
305 {
306     return angle::Result::Continue;
307 }
308 
getNativeCaps() const309 gl::Caps ContextNULL::getNativeCaps() const
310 {
311     return mCaps;
312 }
313 
getNativeTextureCaps() const314 const gl::TextureCapsMap &ContextNULL::getNativeTextureCaps() const
315 {
316     return mTextureCaps;
317 }
318 
getNativeExtensions() const319 const gl::Extensions &ContextNULL::getNativeExtensions() const
320 {
321     return mExtensions;
322 }
323 
getNativeLimitations() const324 const gl::Limitations &ContextNULL::getNativeLimitations() const
325 {
326     return mLimitations;
327 }
328 
createCompiler()329 CompilerImpl *ContextNULL::createCompiler()
330 {
331     return new CompilerNULL();
332 }
333 
createShader(const gl::ShaderState & data)334 ShaderImpl *ContextNULL::createShader(const gl::ShaderState &data)
335 {
336     return new ShaderNULL(data);
337 }
338 
createProgram(const gl::ProgramState & data)339 ProgramImpl *ContextNULL::createProgram(const gl::ProgramState &data)
340 {
341     return new ProgramNULL(data);
342 }
343 
createFramebuffer(const gl::FramebufferState & data)344 FramebufferImpl *ContextNULL::createFramebuffer(const gl::FramebufferState &data)
345 {
346     return new FramebufferNULL(data);
347 }
348 
createTexture(const gl::TextureState & state)349 TextureImpl *ContextNULL::createTexture(const gl::TextureState &state)
350 {
351     return new TextureNULL(state);
352 }
353 
createRenderbuffer(const gl::RenderbufferState & state)354 RenderbufferImpl *ContextNULL::createRenderbuffer(const gl::RenderbufferState &state)
355 {
356     return new RenderbufferNULL(state);
357 }
358 
createBuffer(const gl::BufferState & state)359 BufferImpl *ContextNULL::createBuffer(const gl::BufferState &state)
360 {
361     return new BufferNULL(state, mAllocationTracker);
362 }
363 
createVertexArray(const gl::VertexArrayState & data)364 VertexArrayImpl *ContextNULL::createVertexArray(const gl::VertexArrayState &data)
365 {
366     return new VertexArrayNULL(data);
367 }
368 
createQuery(gl::QueryType type)369 QueryImpl *ContextNULL::createQuery(gl::QueryType type)
370 {
371     return new QueryNULL(type);
372 }
373 
createFenceNV()374 FenceNVImpl *ContextNULL::createFenceNV()
375 {
376     return new FenceNVNULL();
377 }
378 
createSync()379 SyncImpl *ContextNULL::createSync()
380 {
381     return new SyncNULL();
382 }
383 
createTransformFeedback(const gl::TransformFeedbackState & state)384 TransformFeedbackImpl *ContextNULL::createTransformFeedback(const gl::TransformFeedbackState &state)
385 {
386     return new TransformFeedbackNULL(state);
387 }
388 
createSampler(const gl::SamplerState & state)389 SamplerImpl *ContextNULL::createSampler(const gl::SamplerState &state)
390 {
391     return new SamplerNULL(state);
392 }
393 
createProgramPipeline(const gl::ProgramPipelineState & state)394 ProgramPipelineImpl *ContextNULL::createProgramPipeline(const gl::ProgramPipelineState &state)
395 {
396     return new ProgramPipelineNULL(state);
397 }
398 
createMemoryObject()399 MemoryObjectImpl *ContextNULL::createMemoryObject()
400 {
401     UNREACHABLE();
402     return nullptr;
403 }
404 
createSemaphore()405 SemaphoreImpl *ContextNULL::createSemaphore()
406 {
407     UNREACHABLE();
408     return nullptr;
409 }
410 
createOverlay(const gl::OverlayState & state)411 OverlayImpl *ContextNULL::createOverlay(const gl::OverlayState &state)
412 {
413     return new OverlayImpl(state);
414 }
415 
dispatchCompute(const gl::Context * context,GLuint numGroupsX,GLuint numGroupsY,GLuint numGroupsZ)416 angle::Result ContextNULL::dispatchCompute(const gl::Context *context,
417                                            GLuint numGroupsX,
418                                            GLuint numGroupsY,
419                                            GLuint numGroupsZ)
420 {
421     return angle::Result::Continue;
422 }
423 
dispatchComputeIndirect(const gl::Context * context,GLintptr indirect)424 angle::Result ContextNULL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
425 {
426     return angle::Result::Continue;
427 }
428 
memoryBarrier(const gl::Context * context,GLbitfield barriers)429 angle::Result ContextNULL::memoryBarrier(const gl::Context *context, GLbitfield barriers)
430 {
431     return angle::Result::Continue;
432 }
433 
memoryBarrierByRegion(const gl::Context * context,GLbitfield barriers)434 angle::Result ContextNULL::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
435 {
436     return angle::Result::Continue;
437 }
438 
handleError(GLenum errorCode,const char * message,const char * file,const char * function,unsigned int line)439 void ContextNULL::handleError(GLenum errorCode,
440                               const char *message,
441                               const char *file,
442                               const char *function,
443                               unsigned int line)
444 {
445     std::stringstream errorStream;
446     errorStream << "Internal NULL back-end error: " << message << ".";
447     mErrors->handleError(errorCode, errorStream.str().c_str(), file, function, line);
448 }
449 }  // namespace rx
450