blob: f66ec1c30870a80c299e2ad4a7e3daba4af11ee7 [file] [log] [blame]
Geoff Langd08f3b32016-09-23 15:56:30 -04001//
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
Jamie Madillabfbc0f2018-10-09 12:48:52 -040014#include "libANGLE/Context.h"
Geoff Lang76cdbd52016-09-23 16:51:04 -040015#include "libANGLE/renderer/null/BufferNULL.h"
16#include "libANGLE/renderer/null/CompilerNULL.h"
17#include "libANGLE/renderer/null/DisplayNULL.h"
18#include "libANGLE/renderer/null/FenceNVNULL.h"
Geoff Lang76cdbd52016-09-23 16:51:04 -040019#include "libANGLE/renderer/null/FramebufferNULL.h"
20#include "libANGLE/renderer/null/ImageNULL.h"
21#include "libANGLE/renderer/null/PathNULL.h"
22#include "libANGLE/renderer/null/ProgramNULL.h"
Yunchao Hea336b902017-08-02 16:05:21 +080023#include "libANGLE/renderer/null/ProgramPipelineNULL.h"
Geoff Lang76cdbd52016-09-23 16:51:04 -040024#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"
Jamie Madill70b5bb02017-08-28 13:32:37 -040028#include "libANGLE/renderer/null/SyncNULL.h"
Geoff Lang76cdbd52016-09-23 16:51:04 -040029#include "libANGLE/renderer/null/TextureNULL.h"
30#include "libANGLE/renderer/null/TransformFeedbackNULL.h"
31#include "libANGLE/renderer/null/VertexArrayNULL.h"
32
Geoff Langd08f3b32016-09-23 15:56:30 -040033namespace rx
34{
35
Geoff Lang1b60d8d2017-02-10 14:56:55 -050036AllocationTrackerNULL::AllocationTrackerNULL(size_t maxTotalAllocationSize)
37 : mAllocatedBytes(0), mMaxBytes(maxTotalAllocationSize)
Geoff Langd08f3b32016-09-23 15:56:30 -040038{
Geoff Lang1b60d8d2017-02-10 14:56:55 -050039}
40
41AllocationTrackerNULL::~AllocationTrackerNULL()
42{
43 // ASSERT that all objects with the NULL renderer clean up after themselves
44 ASSERT(mAllocatedBytes == 0);
45}
46
47bool 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
63ContextNULL::ContextNULL(const gl::ContextState &state, AllocationTrackerNULL *allocationTracker)
64 : ContextImpl(state), mAllocationTracker(allocationTracker)
65{
66 ASSERT(mAllocationTracker != nullptr);
67
Jamie Madill493f9572018-05-24 19:52:15 -040068 mExtensions = gl::Extensions();
69 mExtensions.fence = true;
70 mExtensions.instancedArrays = true;
71 mExtensions.pixelBufferObject = true;
72 mExtensions.mapBuffer = true;
73 mExtensions.mapBufferRange = true;
74 mExtensions.copyTexture = true;
75 mExtensions.copyCompressedTexture = true;
76 mExtensions.textureRectangle = true;
Geoff Lang73dcc602017-11-08 16:41:52 -050077 mExtensions.textureUsage = true;
78 mExtensions.vertexArrayObject = true;
79 mExtensions.debugMarker = true;
80 mExtensions.translatedShaderSource = true;
Geoff Lang1e031b22017-02-10 15:01:28 -050081
Geoff Langd54d3042017-11-07 14:56:07 -050082 mExtensions.textureStorage = true;
Jamie Madill493f9572018-05-24 19:52:15 -040083 mExtensions.rgb8rgba8 = true;
Geoff Lang86f81162017-10-30 15:10:45 -040084 mExtensions.textureCompressionDXT1 = true;
85 mExtensions.textureCompressionDXT3 = true;
86 mExtensions.textureCompressionDXT5 = true;
87 mExtensions.textureCompressionS3TCsRGB = true;
88 mExtensions.textureCompressionASTCHDR = true;
89 mExtensions.textureCompressionASTCLDR = true;
90 mExtensions.compressedETC1RGB8Texture = true;
91 mExtensions.lossyETCDecode = true;
Jiawei Shao361df072017-11-22 09:33:59 +080092 mExtensions.geometryShader = true;
Geoff Langd84a00b2017-10-27 17:27:26 -040093
Geoff Lang025aafd2017-10-30 15:16:37 -040094 mExtensions.eglImage = true;
95 mExtensions.eglImageExternal = true;
96 mExtensions.eglImageExternalEssl3 = true;
97 mExtensions.eglStreamConsumerExternal = true;
98
Geoff Lang4751aab2017-10-30 15:14:52 -040099 const gl::Version maxClientVersion(3, 1);
100 mCaps = GenerateMinimumCaps(maxClientVersion, mExtensions);
101
Jamie Madill7b62cf92017-11-02 15:20:49 -0400102 InitMinimumTextureCapsMap(maxClientVersion, mExtensions, &mTextureCaps);
Geoff Langd08f3b32016-09-23 15:56:30 -0400103}
104
105ContextNULL::~ContextNULL()
106{
107}
108
109gl::Error ContextNULL::initialize()
110{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400111 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400112}
113
Jamie Madillafa02a22017-11-23 12:57:38 -0500114gl::Error ContextNULL::flush(const gl::Context *context)
Geoff Langd08f3b32016-09-23 15:56:30 -0400115{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400116 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400117}
118
Jamie Madillafa02a22017-11-23 12:57:38 -0500119gl::Error ContextNULL::finish(const gl::Context *context)
Geoff Langd08f3b32016-09-23 15:56:30 -0400120{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400121 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400122}
123
Jamie Madillc564c072017-06-01 12:45:42 -0400124gl::Error ContextNULL::drawArrays(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400125 gl::PrimitiveMode mode,
Jamie Madillc564c072017-06-01 12:45:42 -0400126 GLint first,
127 GLsizei count)
Geoff Langd08f3b32016-09-23 15:56:30 -0400128{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400129 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400130}
131
Jamie Madillc564c072017-06-01 12:45:42 -0400132gl::Error ContextNULL::drawArraysInstanced(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400133 gl::PrimitiveMode mode,
Geoff Langd08f3b32016-09-23 15:56:30 -0400134 GLint first,
135 GLsizei count,
136 GLsizei instanceCount)
137{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400138 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400139}
140
Jamie Madillc564c072017-06-01 12:45:42 -0400141gl::Error ContextNULL::drawElements(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400142 gl::PrimitiveMode mode,
Geoff Langd08f3b32016-09-23 15:56:30 -0400143 GLsizei count,
144 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800145 const void *indices)
Geoff Langd08f3b32016-09-23 15:56:30 -0400146{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400147 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400148}
149
Jamie Madillc564c072017-06-01 12:45:42 -0400150gl::Error ContextNULL::drawElementsInstanced(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400151 gl::PrimitiveMode mode,
Geoff Langd08f3b32016-09-23 15:56:30 -0400152 GLsizei count,
153 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -0400154 const void *indices,
Qin Jiajia1da00652017-06-20 17:16:25 +0800155 GLsizei instances)
Geoff Langd08f3b32016-09-23 15:56:30 -0400156{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400157 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400158}
159
Jamie Madillc564c072017-06-01 12:45:42 -0400160gl::Error ContextNULL::drawRangeElements(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400161 gl::PrimitiveMode mode,
Geoff Langd08f3b32016-09-23 15:56:30 -0400162 GLuint start,
163 GLuint end,
164 GLsizei count,
165 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800166 const void *indices)
Geoff Langd08f3b32016-09-23 15:56:30 -0400167{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400168 return gl::NoError();
169}
170
Jamie Madillc564c072017-06-01 12:45:42 -0400171gl::Error ContextNULL::drawArraysIndirect(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400172 gl::PrimitiveMode mode,
Jamie Madillc564c072017-06-01 12:45:42 -0400173 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800174{
175 return gl::NoError();
176}
177
Jamie Madillc564c072017-06-01 12:45:42 -0400178gl::Error ContextNULL::drawElementsIndirect(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400179 gl::PrimitiveMode mode,
Jamie Madillc564c072017-06-01 12:45:42 -0400180 GLenum type,
181 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800182{
183 return gl::NoError();
184}
185
Geoff Lang76cdbd52016-09-23 16:51:04 -0400186void ContextNULL::stencilFillPath(const gl::Path *path, GLenum fillMode, GLuint mask)
187{
188}
189
190void ContextNULL::stencilStrokePath(const gl::Path *path, GLint reference, GLuint mask)
191{
192}
193
194void ContextNULL::coverFillPath(const gl::Path *path, GLenum coverMode)
195{
196}
197
198void ContextNULL::coverStrokePath(const gl::Path *path, GLenum coverMode)
199{
200}
201
202void ContextNULL::stencilThenCoverFillPath(const gl::Path *path,
203 GLenum fillMode,
204 GLuint mask,
205 GLenum coverMode)
206{
207}
208
209void ContextNULL::stencilThenCoverStrokePath(const gl::Path *path,
210 GLint reference,
211 GLuint mask,
212 GLenum coverMode)
213{
214}
215
216void ContextNULL::coverFillPathInstanced(const std::vector<gl::Path *> &paths,
217 GLenum coverMode,
218 GLenum transformType,
219 const GLfloat *transformValues)
220{
221}
222
223void ContextNULL::coverStrokePathInstanced(const std::vector<gl::Path *> &paths,
224 GLenum coverMode,
225 GLenum transformType,
226 const GLfloat *transformValues)
227{
228}
229
230void ContextNULL::stencilFillPathInstanced(const std::vector<gl::Path *> &paths,
231 GLenum fillMode,
232 GLuint mask,
233 GLenum transformType,
234 const GLfloat *transformValues)
235{
236}
237
238void ContextNULL::stencilStrokePathInstanced(const std::vector<gl::Path *> &paths,
239 GLint reference,
240 GLuint mask,
241 GLenum transformType,
242 const GLfloat *transformValues)
243{
244}
245
246void ContextNULL::stencilThenCoverFillPathInstanced(const std::vector<gl::Path *> &paths,
247 GLenum coverMode,
248 GLenum fillMode,
249 GLuint mask,
250 GLenum transformType,
251 const GLfloat *transformValues)
252{
253}
254
255void ContextNULL::stencilThenCoverStrokePathInstanced(const std::vector<gl::Path *> &paths,
256 GLenum coverMode,
257 GLint reference,
258 GLuint mask,
259 GLenum transformType,
260 const GLfloat *transformValues)
261{
262}
263
264GLenum ContextNULL::getResetStatus()
265{
266 return GL_NO_ERROR;
267}
268
269std::string ContextNULL::getVendorString() const
270{
271 return "NULL";
272}
273
274std::string ContextNULL::getRendererDescription() const
275{
276 return "NULL";
277}
278
279void ContextNULL::insertEventMarker(GLsizei length, const char *marker)
280{
281}
282
283void ContextNULL::pushGroupMarker(GLsizei length, const char *marker)
284{
285}
286
287void ContextNULL::popGroupMarker()
288{
289}
290
Geoff Lang5d5253a2017-11-22 14:51:12 -0500291void ContextNULL::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message)
292{
293}
294
295void ContextNULL::popDebugGroup()
296{
297}
298
Jamie Madill189ad872018-07-09 13:32:37 -0400299gl::Error ContextNULL::syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits)
Geoff Lang76cdbd52016-09-23 16:51:04 -0400300{
Jamie Madill189ad872018-07-09 13:32:37 -0400301 return gl::NoError();
Geoff Lang76cdbd52016-09-23 16:51:04 -0400302}
303
304GLint ContextNULL::getGPUDisjoint()
305{
306 return 0;
307}
308
309GLint64 ContextNULL::getTimestamp()
310{
311 return 0;
312}
313
Luc Ferron5396f2a2018-07-12 08:24:23 -0400314gl::Error ContextNULL::onMakeCurrent(const gl::Context *context)
Geoff Lang76cdbd52016-09-23 16:51:04 -0400315{
Luc Ferron5396f2a2018-07-12 08:24:23 -0400316 return gl::NoError();
Geoff Lang76cdbd52016-09-23 16:51:04 -0400317}
318
Jiawei Shaod0a7d102018-05-07 12:40:20 +0800319gl::Caps ContextNULL::getNativeCaps() const
Geoff Lang76cdbd52016-09-23 16:51:04 -0400320{
321 return mCaps;
322}
323
324const gl::TextureCapsMap &ContextNULL::getNativeTextureCaps() const
325{
326 return mTextureCaps;
327}
328
329const gl::Extensions &ContextNULL::getNativeExtensions() const
330{
331 return mExtensions;
332}
333
334const gl::Limitations &ContextNULL::getNativeLimitations() const
335{
336 return mLimitations;
Geoff Langd08f3b32016-09-23 15:56:30 -0400337}
338
339CompilerImpl *ContextNULL::createCompiler()
340{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400341 return new CompilerNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400342}
343
344ShaderImpl *ContextNULL::createShader(const gl::ShaderState &data)
345{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400346 return new ShaderNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400347}
348
349ProgramImpl *ContextNULL::createProgram(const gl::ProgramState &data)
350{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400351 return new ProgramNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400352}
353
354FramebufferImpl *ContextNULL::createFramebuffer(const gl::FramebufferState &data)
355{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400356 return new FramebufferNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400357}
358
359TextureImpl *ContextNULL::createTexture(const gl::TextureState &state)
360{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400361 return new TextureNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400362}
363
Jamie Madille703c602018-02-20 10:21:48 -0500364RenderbufferImpl *ContextNULL::createRenderbuffer(const gl::RenderbufferState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400365{
Jamie Madille703c602018-02-20 10:21:48 -0500366 return new RenderbufferNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400367}
368
Jamie Madill8f775602016-11-03 16:45:34 -0400369BufferImpl *ContextNULL::createBuffer(const gl::BufferState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400370{
Geoff Lang1b60d8d2017-02-10 14:56:55 -0500371 return new BufferNULL(state, mAllocationTracker);
Geoff Langd08f3b32016-09-23 15:56:30 -0400372}
373
374VertexArrayImpl *ContextNULL::createVertexArray(const gl::VertexArrayState &data)
375{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400376 return new VertexArrayNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400377}
378
Corentin Wallezad3ae902018-03-09 13:40:42 -0500379QueryImpl *ContextNULL::createQuery(gl::QueryType type)
Geoff Langd08f3b32016-09-23 15:56:30 -0400380{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400381 return new QueryNULL(type);
Geoff Langd08f3b32016-09-23 15:56:30 -0400382}
383
384FenceNVImpl *ContextNULL::createFenceNV()
385{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400386 return new FenceNVNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400387}
388
Jamie Madill70b5bb02017-08-28 13:32:37 -0400389SyncImpl *ContextNULL::createSync()
Geoff Langd08f3b32016-09-23 15:56:30 -0400390{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400391 return new SyncNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400392}
393
394TransformFeedbackImpl *ContextNULL::createTransformFeedback(const gl::TransformFeedbackState &state)
395{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400396 return new TransformFeedbackNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400397}
398
Jamie Madill06ef36b2017-09-09 23:32:46 -0400399SamplerImpl *ContextNULL::createSampler(const gl::SamplerState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400400{
Jamie Madill06ef36b2017-09-09 23:32:46 -0400401 return new SamplerNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400402}
403
Yunchao Hea336b902017-08-02 16:05:21 +0800404ProgramPipelineImpl *ContextNULL::createProgramPipeline(const gl::ProgramPipelineState &state)
405{
406 return new ProgramPipelineNULL(state);
407}
408
Geoff Langd08f3b32016-09-23 15:56:30 -0400409std::vector<PathImpl *> ContextNULL::createPaths(GLsizei range)
410{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400411 std::vector<PathImpl *> result(range);
412 for (GLsizei idx = 0; idx < range; idx++)
413 {
414 result[idx] = new PathNULL();
415 }
416 return result;
Geoff Langd08f3b32016-09-23 15:56:30 -0400417}
418
Jamie Madillfe548342017-06-19 11:13:24 -0400419gl::Error ContextNULL::dispatchCompute(const gl::Context *context,
420 GLuint numGroupsX,
421 GLuint numGroupsY,
422 GLuint numGroupsZ)
Xinghua Cao2b396592017-03-29 15:36:04 +0800423{
424 return gl::NoError();
425}
426
Qin Jiajia62fcf622017-11-30 16:16:12 +0800427gl::Error ContextNULL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
428{
429 return gl::NoError();
430}
431
Xinghua Cao89c422a2017-11-29 18:24:20 +0800432gl::Error ContextNULL::memoryBarrier(const gl::Context *context, GLbitfield barriers)
433{
434 return gl::NoError();
435}
436
437gl::Error ContextNULL::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
438{
439 return gl::NoError();
440}
441
Jamie Madillabfbc0f2018-10-09 12:48:52 -0400442void ContextNULL::handleError(GLenum errorCode,
443 const char *message,
444 const char *file,
445 const char *function,
446 unsigned int line)
447{
448 std::stringstream errorStream;
449 errorStream << "Internal OpenGL error: " << gl::FmtHex(errorCode) << ", in " << file << ", "
450 << function << ":" << line << ". " << message;
451
452 mErrors->handleError(gl::Error(errorCode, errorCode, errorStream.str()));
453}
Geoff Langd08f3b32016-09-23 15:56:30 -0400454} // namespace rx