blob: db73ce8070408de4fa430a7d1192f6f55bbd5c74 [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 Madill6f755b22018-10-09 12:48:54 -0400124angle::Result ContextNULL::drawArrays(const gl::Context *context,
125 gl::PrimitiveMode mode,
126 GLint first,
127 GLsizei count)
Geoff Langd08f3b32016-09-23 15:56:30 -0400128{
Jamie Madill6f755b22018-10-09 12:48:54 -0400129 return angle::Result::Continue();
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 Madill6f755b22018-10-09 12:48:54 -0400299angle::Result ContextNULL::syncState(const gl::Context *context,
300 const gl::State::DirtyBits &dirtyBits)
Geoff Lang76cdbd52016-09-23 16:51:04 -0400301{
Jamie Madill6f755b22018-10-09 12:48:54 -0400302 return angle::Result::Continue();
Geoff Lang76cdbd52016-09-23 16:51:04 -0400303}
304
305GLint ContextNULL::getGPUDisjoint()
306{
307 return 0;
308}
309
310GLint64 ContextNULL::getTimestamp()
311{
312 return 0;
313}
314
Luc Ferron5396f2a2018-07-12 08:24:23 -0400315gl::Error ContextNULL::onMakeCurrent(const gl::Context *context)
Geoff Lang76cdbd52016-09-23 16:51:04 -0400316{
Luc Ferron5396f2a2018-07-12 08:24:23 -0400317 return gl::NoError();
Geoff Lang76cdbd52016-09-23 16:51:04 -0400318}
319
Jiawei Shaod0a7d102018-05-07 12:40:20 +0800320gl::Caps ContextNULL::getNativeCaps() const
Geoff Lang76cdbd52016-09-23 16:51:04 -0400321{
322 return mCaps;
323}
324
325const gl::TextureCapsMap &ContextNULL::getNativeTextureCaps() const
326{
327 return mTextureCaps;
328}
329
330const gl::Extensions &ContextNULL::getNativeExtensions() const
331{
332 return mExtensions;
333}
334
335const gl::Limitations &ContextNULL::getNativeLimitations() const
336{
337 return mLimitations;
Geoff Langd08f3b32016-09-23 15:56:30 -0400338}
339
340CompilerImpl *ContextNULL::createCompiler()
341{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400342 return new CompilerNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400343}
344
345ShaderImpl *ContextNULL::createShader(const gl::ShaderState &data)
346{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400347 return new ShaderNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400348}
349
350ProgramImpl *ContextNULL::createProgram(const gl::ProgramState &data)
351{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400352 return new ProgramNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400353}
354
355FramebufferImpl *ContextNULL::createFramebuffer(const gl::FramebufferState &data)
356{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400357 return new FramebufferNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400358}
359
360TextureImpl *ContextNULL::createTexture(const gl::TextureState &state)
361{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400362 return new TextureNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400363}
364
Jamie Madille703c602018-02-20 10:21:48 -0500365RenderbufferImpl *ContextNULL::createRenderbuffer(const gl::RenderbufferState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400366{
Jamie Madille703c602018-02-20 10:21:48 -0500367 return new RenderbufferNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400368}
369
Jamie Madill8f775602016-11-03 16:45:34 -0400370BufferImpl *ContextNULL::createBuffer(const gl::BufferState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400371{
Geoff Lang1b60d8d2017-02-10 14:56:55 -0500372 return new BufferNULL(state, mAllocationTracker);
Geoff Langd08f3b32016-09-23 15:56:30 -0400373}
374
375VertexArrayImpl *ContextNULL::createVertexArray(const gl::VertexArrayState &data)
376{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400377 return new VertexArrayNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400378}
379
Corentin Wallezad3ae902018-03-09 13:40:42 -0500380QueryImpl *ContextNULL::createQuery(gl::QueryType type)
Geoff Langd08f3b32016-09-23 15:56:30 -0400381{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400382 return new QueryNULL(type);
Geoff Langd08f3b32016-09-23 15:56:30 -0400383}
384
385FenceNVImpl *ContextNULL::createFenceNV()
386{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400387 return new FenceNVNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400388}
389
Jamie Madill70b5bb02017-08-28 13:32:37 -0400390SyncImpl *ContextNULL::createSync()
Geoff Langd08f3b32016-09-23 15:56:30 -0400391{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400392 return new SyncNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400393}
394
395TransformFeedbackImpl *ContextNULL::createTransformFeedback(const gl::TransformFeedbackState &state)
396{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400397 return new TransformFeedbackNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400398}
399
Jamie Madill06ef36b2017-09-09 23:32:46 -0400400SamplerImpl *ContextNULL::createSampler(const gl::SamplerState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400401{
Jamie Madill06ef36b2017-09-09 23:32:46 -0400402 return new SamplerNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400403}
404
Yunchao Hea336b902017-08-02 16:05:21 +0800405ProgramPipelineImpl *ContextNULL::createProgramPipeline(const gl::ProgramPipelineState &state)
406{
407 return new ProgramPipelineNULL(state);
408}
409
Geoff Langd08f3b32016-09-23 15:56:30 -0400410std::vector<PathImpl *> ContextNULL::createPaths(GLsizei range)
411{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400412 std::vector<PathImpl *> result(range);
413 for (GLsizei idx = 0; idx < range; idx++)
414 {
415 result[idx] = new PathNULL();
416 }
417 return result;
Geoff Langd08f3b32016-09-23 15:56:30 -0400418}
419
Jamie Madillfe548342017-06-19 11:13:24 -0400420gl::Error ContextNULL::dispatchCompute(const gl::Context *context,
421 GLuint numGroupsX,
422 GLuint numGroupsY,
423 GLuint numGroupsZ)
Xinghua Cao2b396592017-03-29 15:36:04 +0800424{
425 return gl::NoError();
426}
427
Qin Jiajia62fcf622017-11-30 16:16:12 +0800428gl::Error ContextNULL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
429{
430 return gl::NoError();
431}
432
Xinghua Cao89c422a2017-11-29 18:24:20 +0800433gl::Error ContextNULL::memoryBarrier(const gl::Context *context, GLbitfield barriers)
434{
435 return gl::NoError();
436}
437
438gl::Error ContextNULL::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
439{
440 return gl::NoError();
441}
442
Jamie Madillabfbc0f2018-10-09 12:48:52 -0400443void ContextNULL::handleError(GLenum errorCode,
444 const char *message,
445 const char *file,
446 const char *function,
447 unsigned int line)
448{
449 std::stringstream errorStream;
450 errorStream << "Internal OpenGL error: " << gl::FmtHex(errorCode) << ", in " << file << ", "
451 << function << ":" << line << ". " << message;
452
453 mErrors->handleError(gl::Error(errorCode, errorCode, errorStream.str()));
454}
Geoff Langd08f3b32016-09-23 15:56:30 -0400455} // namespace rx