blob: 786b9ab967c0c03990052f80bf597036540ebe15 [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
Jamie Madill32643ce2018-10-19 11:38:03 -0400109angle::Result ContextNULL::initialize()
Geoff Langd08f3b32016-09-23 15:56:30 -0400110{
Jamie Madill32643ce2018-10-19 11:38:03 -0400111 return angle::Result::Continue();
Geoff Langd08f3b32016-09-23 15:56:30 -0400112}
113
Jamie Madill32643ce2018-10-19 11:38:03 -0400114angle::Result ContextNULL::flush(const gl::Context *context)
Geoff Langd08f3b32016-09-23 15:56:30 -0400115{
Jamie Madill32643ce2018-10-19 11:38:03 -0400116 return angle::Result::Continue();
Geoff Langd08f3b32016-09-23 15:56:30 -0400117}
118
Jamie Madill32643ce2018-10-19 11:38:03 -0400119angle::Result ContextNULL::finish(const gl::Context *context)
Geoff Langd08f3b32016-09-23 15:56:30 -0400120{
Jamie Madill32643ce2018-10-19 11:38:03 -0400121 return angle::Result::Continue();
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 Madill32643ce2018-10-19 11:38:03 -0400132angle::Result ContextNULL::drawArraysInstanced(const gl::Context *context,
133 gl::PrimitiveMode mode,
134 GLint first,
135 GLsizei count,
136 GLsizei instanceCount)
Geoff Langd08f3b32016-09-23 15:56:30 -0400137{
Jamie Madill32643ce2018-10-19 11:38:03 -0400138 return angle::Result::Continue();
Geoff Langd08f3b32016-09-23 15:56:30 -0400139}
140
Jamie Madill32643ce2018-10-19 11:38:03 -0400141angle::Result ContextNULL::drawElements(const gl::Context *context,
142 gl::PrimitiveMode mode,
143 GLsizei count,
144 GLenum type,
145 const void *indices)
Geoff Langd08f3b32016-09-23 15:56:30 -0400146{
Jamie Madill32643ce2018-10-19 11:38:03 -0400147 return angle::Result::Continue();
Geoff Langd08f3b32016-09-23 15:56:30 -0400148}
149
Jamie Madill32643ce2018-10-19 11:38:03 -0400150angle::Result ContextNULL::drawElementsInstanced(const gl::Context *context,
151 gl::PrimitiveMode mode,
152 GLsizei count,
153 GLenum type,
154 const void *indices,
155 GLsizei instances)
156{
157 return angle::Result::Continue();
158}
159
160angle::Result ContextNULL::drawRangeElements(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400161 gl::PrimitiveMode mode,
Jamie Madill32643ce2018-10-19 11:38:03 -0400162 GLuint start,
163 GLuint end,
Geoff Langd08f3b32016-09-23 15:56:30 -0400164 GLsizei count,
165 GLenum type,
Jamie Madill32643ce2018-10-19 11:38:03 -0400166 const void *indices)
Geoff Langd08f3b32016-09-23 15:56:30 -0400167{
Jamie Madill32643ce2018-10-19 11:38:03 -0400168 return angle::Result::Continue();
Geoff Langd08f3b32016-09-23 15:56:30 -0400169}
170
Jamie Madill32643ce2018-10-19 11:38:03 -0400171angle::Result ContextNULL::drawArraysIndirect(const gl::Context *context,
172 gl::PrimitiveMode mode,
173 const void *indirect)
Geoff Langd08f3b32016-09-23 15:56:30 -0400174{
Jamie Madill32643ce2018-10-19 11:38:03 -0400175 return angle::Result::Continue();
Geoff Lang76cdbd52016-09-23 16:51:04 -0400176}
177
Jamie Madill32643ce2018-10-19 11:38:03 -0400178angle::Result ContextNULL::drawElementsIndirect(const gl::Context *context,
179 gl::PrimitiveMode mode,
180 GLenum type,
181 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800182{
Jamie Madill32643ce2018-10-19 11:38:03 -0400183 return angle::Result::Continue();
Jiajia Qind9671222016-11-29 16:30:31 +0800184}
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,
Jamie Madill9d0bb3d2018-10-09 20:29:13 -0400300 const gl::State::DirtyBits &dirtyBits,
301 const gl::State::DirtyBits &bitMask)
Geoff Lang76cdbd52016-09-23 16:51:04 -0400302{
Jamie Madill6f755b22018-10-09 12:48:54 -0400303 return angle::Result::Continue();
Geoff Lang76cdbd52016-09-23 16:51:04 -0400304}
305
306GLint ContextNULL::getGPUDisjoint()
307{
308 return 0;
309}
310
311GLint64 ContextNULL::getTimestamp()
312{
313 return 0;
314}
315
Jamie Madill32643ce2018-10-19 11:38:03 -0400316angle::Result ContextNULL::onMakeCurrent(const gl::Context *context)
Geoff Lang76cdbd52016-09-23 16:51:04 -0400317{
Jamie Madill32643ce2018-10-19 11:38:03 -0400318 return angle::Result::Continue();
Geoff Lang76cdbd52016-09-23 16:51:04 -0400319}
320
Jiawei Shaod0a7d102018-05-07 12:40:20 +0800321gl::Caps ContextNULL::getNativeCaps() const
Geoff Lang76cdbd52016-09-23 16:51:04 -0400322{
323 return mCaps;
324}
325
326const gl::TextureCapsMap &ContextNULL::getNativeTextureCaps() const
327{
328 return mTextureCaps;
329}
330
331const gl::Extensions &ContextNULL::getNativeExtensions() const
332{
333 return mExtensions;
334}
335
336const gl::Limitations &ContextNULL::getNativeLimitations() const
337{
338 return mLimitations;
Geoff Langd08f3b32016-09-23 15:56:30 -0400339}
340
341CompilerImpl *ContextNULL::createCompiler()
342{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400343 return new CompilerNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400344}
345
346ShaderImpl *ContextNULL::createShader(const gl::ShaderState &data)
347{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400348 return new ShaderNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400349}
350
351ProgramImpl *ContextNULL::createProgram(const gl::ProgramState &data)
352{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400353 return new ProgramNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400354}
355
356FramebufferImpl *ContextNULL::createFramebuffer(const gl::FramebufferState &data)
357{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400358 return new FramebufferNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400359}
360
361TextureImpl *ContextNULL::createTexture(const gl::TextureState &state)
362{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400363 return new TextureNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400364}
365
Jamie Madille703c602018-02-20 10:21:48 -0500366RenderbufferImpl *ContextNULL::createRenderbuffer(const gl::RenderbufferState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400367{
Jamie Madille703c602018-02-20 10:21:48 -0500368 return new RenderbufferNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400369}
370
Jamie Madill8f775602016-11-03 16:45:34 -0400371BufferImpl *ContextNULL::createBuffer(const gl::BufferState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400372{
Geoff Lang1b60d8d2017-02-10 14:56:55 -0500373 return new BufferNULL(state, mAllocationTracker);
Geoff Langd08f3b32016-09-23 15:56:30 -0400374}
375
376VertexArrayImpl *ContextNULL::createVertexArray(const gl::VertexArrayState &data)
377{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400378 return new VertexArrayNULL(data);
Geoff Langd08f3b32016-09-23 15:56:30 -0400379}
380
Corentin Wallezad3ae902018-03-09 13:40:42 -0500381QueryImpl *ContextNULL::createQuery(gl::QueryType type)
Geoff Langd08f3b32016-09-23 15:56:30 -0400382{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400383 return new QueryNULL(type);
Geoff Langd08f3b32016-09-23 15:56:30 -0400384}
385
386FenceNVImpl *ContextNULL::createFenceNV()
387{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400388 return new FenceNVNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400389}
390
Jamie Madill70b5bb02017-08-28 13:32:37 -0400391SyncImpl *ContextNULL::createSync()
Geoff Langd08f3b32016-09-23 15:56:30 -0400392{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400393 return new SyncNULL();
Geoff Langd08f3b32016-09-23 15:56:30 -0400394}
395
396TransformFeedbackImpl *ContextNULL::createTransformFeedback(const gl::TransformFeedbackState &state)
397{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400398 return new TransformFeedbackNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400399}
400
Jamie Madill06ef36b2017-09-09 23:32:46 -0400401SamplerImpl *ContextNULL::createSampler(const gl::SamplerState &state)
Geoff Langd08f3b32016-09-23 15:56:30 -0400402{
Jamie Madill06ef36b2017-09-09 23:32:46 -0400403 return new SamplerNULL(state);
Geoff Langd08f3b32016-09-23 15:56:30 -0400404}
405
Yunchao Hea336b902017-08-02 16:05:21 +0800406ProgramPipelineImpl *ContextNULL::createProgramPipeline(const gl::ProgramPipelineState &state)
407{
408 return new ProgramPipelineNULL(state);
409}
410
Geoff Langd08f3b32016-09-23 15:56:30 -0400411std::vector<PathImpl *> ContextNULL::createPaths(GLsizei range)
412{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400413 std::vector<PathImpl *> result(range);
414 for (GLsizei idx = 0; idx < range; idx++)
415 {
416 result[idx] = new PathNULL();
417 }
418 return result;
Geoff Langd08f3b32016-09-23 15:56:30 -0400419}
420
Jamie Madill32643ce2018-10-19 11:38:03 -0400421angle::Result ContextNULL::dispatchCompute(const gl::Context *context,
422 GLuint numGroupsX,
423 GLuint numGroupsY,
424 GLuint numGroupsZ)
Xinghua Cao2b396592017-03-29 15:36:04 +0800425{
Jamie Madill32643ce2018-10-19 11:38:03 -0400426 return angle::Result::Continue();
Xinghua Cao2b396592017-03-29 15:36:04 +0800427}
428
Jamie Madill32643ce2018-10-19 11:38:03 -0400429angle::Result ContextNULL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
Qin Jiajia62fcf622017-11-30 16:16:12 +0800430{
Jamie Madill32643ce2018-10-19 11:38:03 -0400431 return angle::Result::Continue();
Qin Jiajia62fcf622017-11-30 16:16:12 +0800432}
433
Jamie Madill32643ce2018-10-19 11:38:03 -0400434angle::Result ContextNULL::memoryBarrier(const gl::Context *context, GLbitfield barriers)
Xinghua Cao89c422a2017-11-29 18:24:20 +0800435{
Jamie Madill32643ce2018-10-19 11:38:03 -0400436 return angle::Result::Continue();
Xinghua Cao89c422a2017-11-29 18:24:20 +0800437}
438
Jamie Madill32643ce2018-10-19 11:38:03 -0400439angle::Result ContextNULL::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
Xinghua Cao89c422a2017-11-29 18:24:20 +0800440{
Jamie Madill32643ce2018-10-19 11:38:03 -0400441 return angle::Result::Continue();
Xinghua Cao89c422a2017-11-29 18:24:20 +0800442}
443
Jamie Madillabfbc0f2018-10-09 12:48:52 -0400444void ContextNULL::handleError(GLenum errorCode,
445 const char *message,
446 const char *file,
447 const char *function,
448 unsigned int line)
449{
450 std::stringstream errorStream;
451 errorStream << "Internal OpenGL error: " << gl::FmtHex(errorCode) << ", in " << file << ", "
452 << function << ":" << line << ". " << message;
453
454 mErrors->handleError(gl::Error(errorCode, errorCode, errorStream.str()));
455}
Geoff Langd08f3b32016-09-23 15:56:30 -0400456} // namespace rx