Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/libANGLE/Context.h
1693 views
1
//
2
// Copyright 2002 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
7
// Context.h: Defines the gl::Context class, managing all GL state and performing
8
// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
10
#ifndef LIBANGLE_CONTEXT_H_
11
#define LIBANGLE_CONTEXT_H_
12
13
#include <mutex>
14
#include <set>
15
#include <string>
16
17
#include "angle_gl.h"
18
#include "common/MemoryBuffer.h"
19
#include "common/PackedEnums.h"
20
#include "common/angleutils.h"
21
#include "libANGLE/Caps.h"
22
#include "libANGLE/Constants.h"
23
#include "libANGLE/Context_gl_1_autogen.h"
24
#include "libANGLE/Context_gl_2_autogen.h"
25
#include "libANGLE/Context_gl_3_autogen.h"
26
#include "libANGLE/Context_gl_4_autogen.h"
27
#include "libANGLE/Context_gles_1_0_autogen.h"
28
#include "libANGLE/Context_gles_2_0_autogen.h"
29
#include "libANGLE/Context_gles_3_0_autogen.h"
30
#include "libANGLE/Context_gles_3_1_autogen.h"
31
#include "libANGLE/Context_gles_3_2_autogen.h"
32
#include "libANGLE/Context_gles_ext_autogen.h"
33
#include "libANGLE/Error.h"
34
#include "libANGLE/HandleAllocator.h"
35
#include "libANGLE/RefCountObject.h"
36
#include "libANGLE/ResourceManager.h"
37
#include "libANGLE/ResourceMap.h"
38
#include "libANGLE/State.h"
39
#include "libANGLE/VertexAttribute.h"
40
#include "libANGLE/WorkerThread.h"
41
#include "libANGLE/angletypes.h"
42
43
namespace angle
44
{
45
class FrameCapture;
46
class FrameCaptureShared;
47
struct FrontendFeatures;
48
} // namespace angle
49
50
namespace rx
51
{
52
class ContextImpl;
53
class EGLImplFactory;
54
} // namespace rx
55
56
namespace egl
57
{
58
class AttributeMap;
59
class Surface;
60
struct Config;
61
class Thread;
62
} // namespace egl
63
64
namespace gl
65
{
66
class Buffer;
67
class Compiler;
68
class FenceNV;
69
class Framebuffer;
70
class GLES1Renderer;
71
class MemoryProgramCache;
72
class MemoryObject;
73
class Program;
74
class ProgramPipeline;
75
class Query;
76
class Renderbuffer;
77
class Sampler;
78
class Semaphore;
79
class Shader;
80
class Sync;
81
class Texture;
82
class TransformFeedback;
83
class VertexArray;
84
struct VertexAttribute;
85
86
class ErrorSet : angle::NonCopyable
87
{
88
public:
89
explicit ErrorSet(Context *context);
90
~ErrorSet();
91
92
bool empty() const;
93
GLenum popError();
94
95
void handleError(GLenum errorCode,
96
const char *message,
97
const char *file,
98
const char *function,
99
unsigned int line);
100
101
void validationError(GLenum errorCode, const char *message);
102
103
private:
104
Context *mContext;
105
std::set<GLenum> mErrors;
106
};
107
108
enum class VertexAttribTypeCase
109
{
110
Invalid = 0,
111
Valid = 1,
112
ValidSize4Only = 2,
113
ValidSize3or4 = 3,
114
};
115
116
// Helper class for managing cache variables and state changes.
117
class StateCache final : angle::NonCopyable
118
{
119
public:
120
StateCache();
121
~StateCache();
122
123
void initialize(Context *context);
124
125
// Places that can trigger updateActiveAttribsMask:
126
// 1. onVertexArrayBindingChange.
127
// 2. onProgramExecutableChange.
128
// 3. onVertexArrayStateChange.
129
// 4. onGLES1ClientStateChange.
130
AttributesMask getActiveBufferedAttribsMask() const { return mCachedActiveBufferedAttribsMask; }
131
AttributesMask getActiveClientAttribsMask() const { return mCachedActiveClientAttribsMask; }
132
AttributesMask getActiveDefaultAttribsMask() const { return mCachedActiveDefaultAttribsMask; }
133
bool hasAnyEnabledClientAttrib() const { return mCachedHasAnyEnabledClientAttrib; }
134
bool hasAnyActiveClientAttrib() const { return mCachedActiveClientAttribsMask.any(); }
135
136
// Places that can trigger updateVertexElementLimits:
137
// 1. onVertexArrayBindingChange.
138
// 2. onProgramExecutableChange.
139
// 3. onVertexArrayFormatChange.
140
// 4. onVertexArrayBufferChange.
141
// 5. onVertexArrayStateChange.
142
GLint64 getNonInstancedVertexElementLimit() const
143
{
144
return mCachedNonInstancedVertexElementLimit;
145
}
146
GLint64 getInstancedVertexElementLimit() const { return mCachedInstancedVertexElementLimit; }
147
148
// Places that can trigger updateBasicDrawStatesError:
149
// 1. onVertexArrayBindingChange.
150
// 2. onProgramExecutableChange.
151
// 3. onVertexArrayBufferContentsChange.
152
// 4. onVertexArrayStateChange.
153
// 5. onVertexArrayBufferStateChange.
154
// 6. onDrawFramebufferChange.
155
// 7. onContextCapChange.
156
// 8. onStencilStateChange.
157
// 9. onDefaultVertexAttributeChange.
158
// 10. onActiveTextureChange.
159
// 11. onQueryChange.
160
// 12. onActiveTransformFeedbackChange.
161
// 13. onUniformBufferStateChange.
162
// 14. onColorMaskChange.
163
// 15. onBufferBindingChange.
164
// 16. onBlendFuncIndexedChange.
165
bool hasBasicDrawStatesError(Context *context) const
166
{
167
if (mCachedBasicDrawStatesError == 0)
168
{
169
return false;
170
}
171
if (mCachedBasicDrawStatesError != kInvalidPointer)
172
{
173
return true;
174
}
175
return getBasicDrawStatesErrorImpl(context) != 0;
176
}
177
178
intptr_t getBasicDrawStatesError(const Context *context) const
179
{
180
if (mCachedBasicDrawStatesError != kInvalidPointer)
181
{
182
return mCachedBasicDrawStatesError;
183
}
184
185
return getBasicDrawStatesErrorImpl(context);
186
}
187
188
// Places that can trigger updateBasicDrawElementsError:
189
// 1. onActiveTransformFeedbackChange.
190
// 2. onVertexArrayBufferStateChange.
191
// 3. onBufferBindingChange.
192
// 4. onVertexArrayStateChange.
193
// 5. onVertexArrayBindingStateChange.
194
intptr_t getBasicDrawElementsError(const Context *context) const
195
{
196
if (mCachedBasicDrawElementsError != kInvalidPointer)
197
{
198
return mCachedBasicDrawElementsError;
199
}
200
201
return getBasicDrawElementsErrorImpl(context);
202
}
203
204
// Places that can trigger updateValidDrawModes:
205
// 1. onProgramExecutableChange.
206
// 2. onActiveTransformFeedbackChange.
207
bool isValidDrawMode(PrimitiveMode primitiveMode) const
208
{
209
return mCachedValidDrawModes[primitiveMode];
210
}
211
212
// Cannot change except on Context/Extension init.
213
bool isValidBindTextureType(TextureType type) const
214
{
215
return mCachedValidBindTextureTypes[type];
216
}
217
218
// Cannot change except on Context/Extension init.
219
bool isValidDrawElementsType(DrawElementsType type) const
220
{
221
return mCachedValidDrawElementsTypes[type];
222
}
223
224
// Places that can trigger updateTransformFeedbackActiveUnpaused:
225
// 1. onActiveTransformFeedbackChange.
226
bool isTransformFeedbackActiveUnpaused() const
227
{
228
return mCachedTransformFeedbackActiveUnpaused;
229
}
230
231
// Cannot change except on Context/Extension init.
232
VertexAttribTypeCase getVertexAttribTypeValidation(VertexAttribType type) const
233
{
234
return mCachedVertexAttribTypesValidation[type];
235
}
236
237
VertexAttribTypeCase getIntegerVertexAttribTypeValidation(VertexAttribType type) const
238
{
239
return mCachedIntegerVertexAttribTypesValidation[type];
240
}
241
242
// Places that can trigger updateActiveShaderStorageBufferIndices:
243
// 1. onProgramExecutableChange.
244
StorageBuffersMask getActiveShaderStorageBufferIndices() const
245
{
246
return mCachedActiveShaderStorageBufferIndices;
247
}
248
249
// Places that can trigger updateActiveImageUnitIndices:
250
// 1. onProgramExecutableChange.
251
const ImageUnitMask &getActiveImageUnitIndices() const { return mCachedActiveImageUnitIndices; }
252
253
// Places that can trigger updateCanDraw:
254
// 1. onProgramExecutableChange.
255
bool getCanDraw() const { return mCachedCanDraw; }
256
257
// State change notifications.
258
void onVertexArrayBindingChange(Context *context);
259
void onProgramExecutableChange(Context *context);
260
void onVertexArrayFormatChange(Context *context);
261
void onVertexArrayBufferContentsChange(Context *context);
262
void onVertexArrayStateChange(Context *context);
263
void onVertexArrayBufferStateChange(Context *context);
264
void onGLES1ClientStateChange(Context *context);
265
void onDrawFramebufferChange(Context *context);
266
void onContextCapChange(Context *context);
267
void onStencilStateChange(Context *context);
268
void onDefaultVertexAttributeChange(Context *context);
269
void onActiveTextureChange(Context *context);
270
void onQueryChange(Context *context);
271
void onActiveTransformFeedbackChange(Context *context);
272
void onUniformBufferStateChange(Context *context);
273
void onAtomicCounterBufferStateChange(Context *context);
274
void onShaderStorageBufferStateChange(Context *context);
275
void onColorMaskChange(Context *context);
276
void onBufferBindingChange(Context *context);
277
void onBlendFuncIndexedChange(Context *context);
278
279
private:
280
// Cache update functions.
281
void updateActiveAttribsMask(Context *context);
282
void updateVertexElementLimits(Context *context);
283
void updateVertexElementLimitsImpl(Context *context);
284
void updateValidDrawModes(Context *context);
285
void updateValidBindTextureTypes(Context *context);
286
void updateValidDrawElementsTypes(Context *context);
287
void updateBasicDrawStatesError();
288
void updateBasicDrawElementsError();
289
void updateTransformFeedbackActiveUnpaused(Context *context);
290
void updateVertexAttribTypesValidation(Context *context);
291
void updateActiveShaderStorageBufferIndices(Context *context);
292
void updateActiveImageUnitIndices(Context *context);
293
void updateCanDraw(Context *context);
294
295
void setValidDrawModes(bool pointsOK,
296
bool linesOK,
297
bool trisOK,
298
bool lineAdjOK,
299
bool triAdjOK,
300
bool patchOK);
301
302
intptr_t getBasicDrawStatesErrorImpl(const Context *context) const;
303
intptr_t getBasicDrawElementsErrorImpl(const Context *context) const;
304
305
static constexpr intptr_t kInvalidPointer = 1;
306
307
AttributesMask mCachedActiveBufferedAttribsMask;
308
AttributesMask mCachedActiveClientAttribsMask;
309
AttributesMask mCachedActiveDefaultAttribsMask;
310
bool mCachedHasAnyEnabledClientAttrib;
311
GLint64 mCachedNonInstancedVertexElementLimit;
312
GLint64 mCachedInstancedVertexElementLimit;
313
mutable intptr_t mCachedBasicDrawStatesError;
314
mutable intptr_t mCachedBasicDrawElementsError;
315
bool mCachedTransformFeedbackActiveUnpaused;
316
StorageBuffersMask mCachedActiveShaderStorageBufferIndices;
317
ImageUnitMask mCachedActiveImageUnitIndices;
318
319
// Reserve an extra slot at the end of these maps for invalid enum.
320
angle::PackedEnumMap<PrimitiveMode, bool, angle::EnumSize<PrimitiveMode>() + 1>
321
mCachedValidDrawModes;
322
angle::PackedEnumMap<TextureType, bool, angle::EnumSize<TextureType>() + 1>
323
mCachedValidBindTextureTypes;
324
angle::PackedEnumMap<DrawElementsType, bool, angle::EnumSize<DrawElementsType>() + 1>
325
mCachedValidDrawElementsTypes;
326
angle::PackedEnumMap<VertexAttribType,
327
VertexAttribTypeCase,
328
angle::EnumSize<VertexAttribType>() + 1>
329
mCachedVertexAttribTypesValidation;
330
angle::PackedEnumMap<VertexAttribType,
331
VertexAttribTypeCase,
332
angle::EnumSize<VertexAttribType>() + 1>
333
mCachedIntegerVertexAttribTypesValidation;
334
335
bool mCachedCanDraw;
336
};
337
338
using VertexArrayMap = ResourceMap<VertexArray, VertexArrayID>;
339
using QueryMap = ResourceMap<Query, QueryID>;
340
using TransformFeedbackMap = ResourceMap<TransformFeedback, TransformFeedbackID>;
341
342
class Context final : public egl::LabeledObject, angle::NonCopyable, public angle::ObserverInterface
343
{
344
public:
345
Context(egl::Display *display,
346
const egl::Config *config,
347
const Context *shareContext,
348
TextureManager *shareTextures,
349
SemaphoreManager *shareSemaphores,
350
MemoryProgramCache *memoryProgramCache,
351
const EGLenum clientType,
352
const egl::AttributeMap &attribs,
353
const egl::DisplayExtensions &displayExtensions,
354
const egl::ClientExtensions &clientExtensions);
355
356
// Use for debugging.
357
ContextID id() const { return mState.getContextID(); }
358
359
egl::Error initialize();
360
361
egl::Error onDestroy(const egl::Display *display);
362
~Context() override;
363
364
void setLabel(EGLLabelKHR label) override;
365
EGLLabelKHR getLabel() const override;
366
367
egl::Error makeCurrent(egl::Display *display,
368
egl::Surface *drawSurface,
369
egl::Surface *readSurface);
370
egl::Error unMakeCurrent(const egl::Display *display);
371
372
// These create and destroy methods are merely pass-throughs to
373
// ResourceManager, which owns these object types
374
BufferID createBuffer();
375
TextureID createTexture();
376
RenderbufferID createRenderbuffer();
377
ProgramPipelineID createProgramPipeline();
378
MemoryObjectID createMemoryObject();
379
SemaphoreID createSemaphore();
380
381
void deleteBuffer(BufferID buffer);
382
void deleteTexture(TextureID texture);
383
void deleteRenderbuffer(RenderbufferID renderbuffer);
384
void deleteProgramPipeline(ProgramPipelineID pipeline);
385
void deleteMemoryObject(MemoryObjectID memoryObject);
386
void deleteSemaphore(SemaphoreID semaphore);
387
388
void bindReadFramebuffer(FramebufferID framebufferHandle);
389
void bindDrawFramebuffer(FramebufferID framebufferHandle);
390
391
Buffer *getBuffer(BufferID handle) const;
392
FenceNV *getFenceNV(FenceNVID handle) const;
393
Sync *getSync(GLsync handle) const;
394
ANGLE_INLINE Texture *getTexture(TextureID handle) const
395
{
396
return mState.mTextureManager->getTexture(handle);
397
}
398
399
Framebuffer *getFramebuffer(FramebufferID handle) const;
400
Renderbuffer *getRenderbuffer(RenderbufferID handle) const;
401
VertexArray *getVertexArray(VertexArrayID handle) const;
402
Sampler *getSampler(SamplerID handle) const;
403
Query *getOrCreateQuery(QueryID handle, QueryType type);
404
Query *getQuery(QueryID handle) const;
405
TransformFeedback *getTransformFeedback(TransformFeedbackID handle) const;
406
ProgramPipeline *getProgramPipeline(ProgramPipelineID handle) const;
407
MemoryObject *getMemoryObject(MemoryObjectID handle) const;
408
Semaphore *getSemaphore(SemaphoreID handle) const;
409
410
Texture *getTextureByType(TextureType type) const;
411
Texture *getTextureByTarget(TextureTarget target) const;
412
Texture *getSamplerTexture(unsigned int sampler, TextureType type) const;
413
414
Compiler *getCompiler() const;
415
416
bool isVertexArrayGenerated(VertexArrayID vertexArray) const;
417
bool isTransformFeedbackGenerated(TransformFeedbackID transformFeedback) const;
418
419
bool isExternal() const { return mIsExternal; }
420
bool saveAndRestoreState() const { return mSaveAndRestoreState; }
421
422
void getBooleanvImpl(GLenum pname, GLboolean *params) const;
423
void getFloatvImpl(GLenum pname, GLfloat *params) const;
424
void getIntegervImpl(GLenum pname, GLint *params) const;
425
void getInteger64vImpl(GLenum pname, GLint64 *params) const;
426
void getIntegerVertexAttribImpl(GLenum pname, GLenum attribpname, GLint *params) const;
427
void getVertexAttribivImpl(GLuint index, GLenum pname, GLint *params) const;
428
429
// Framebuffers are owned by the Context, so these methods do not pass through
430
FramebufferID createFramebuffer();
431
void deleteFramebuffer(FramebufferID framebuffer);
432
433
bool hasActiveTransformFeedback(ShaderProgramID program) const;
434
435
// Desktop GL entry point interface
436
ANGLE_GL_1_CONTEXT_API
437
ANGLE_GL_2_CONTEXT_API
438
ANGLE_GL_3_CONTEXT_API
439
ANGLE_GL_4_CONTEXT_API
440
441
// GLES entry point interface
442
ANGLE_GLES_1_0_CONTEXT_API
443
ANGLE_GLES_2_0_CONTEXT_API
444
ANGLE_GLES_3_0_CONTEXT_API
445
ANGLE_GLES_3_1_CONTEXT_API
446
ANGLE_GLES_3_2_CONTEXT_API
447
ANGLE_GLES_EXT_CONTEXT_API
448
449
angle::Result handleNoopDrawEvent();
450
451
// Consumes an error.
452
void handleError(GLenum errorCode,
453
const char *message,
454
const char *file,
455
const char *function,
456
unsigned int line);
457
458
void validationError(GLenum errorCode, const char *message) const;
459
460
void markContextLost(GraphicsResetStatus status);
461
462
bool isContextLost() const { return mContextLost; }
463
void setContextLost();
464
465
GLenum getGraphicsResetStrategy() const { return mResetStrategy; }
466
bool isResetNotificationEnabled() const;
467
468
const egl::Config *getConfig() const;
469
EGLenum getClientType() const;
470
EGLenum getRenderBuffer() const;
471
EGLenum getContextPriority() const;
472
473
const GLubyte *getString(GLenum name) const;
474
const GLubyte *getStringi(GLenum name, GLuint index) const;
475
476
size_t getExtensionStringCount() const;
477
478
bool isExtensionRequestable(const char *name) const;
479
bool isExtensionDisablable(const char *name) const;
480
size_t getRequestableExtensionStringCount() const;
481
void setExtensionEnabled(const char *name, bool enabled);
482
void reinitializeAfterExtensionsChanged();
483
484
rx::ContextImpl *getImplementation() const { return mImplementation.get(); }
485
486
ANGLE_NO_DISCARD bool getScratchBuffer(size_t requestedSizeBytes,
487
angle::MemoryBuffer **scratchBufferOut) const;
488
ANGLE_NO_DISCARD bool getZeroFilledBuffer(size_t requstedSizeBytes,
489
angle::MemoryBuffer **zeroBufferOut) const;
490
angle::ScratchBuffer *getScratchBuffer() const;
491
492
angle::Result prepareForCopyImage();
493
angle::Result prepareForDispatch();
494
495
MemoryProgramCache *getMemoryProgramCache() const { return mMemoryProgramCache; }
496
std::mutex &getProgramCacheMutex() const;
497
498
bool hasBeenCurrent() const { return mHasBeenCurrent; }
499
egl::Display *getDisplay() const { return mDisplay; }
500
egl::Surface *getCurrentDrawSurface() const { return mCurrentDrawSurface; }
501
egl::Surface *getCurrentReadSurface() const { return mCurrentReadSurface; }
502
503
bool isRobustResourceInitEnabled() const { return mState.isRobustResourceInitEnabled(); }
504
505
bool isCurrentTransformFeedback(const TransformFeedback *tf) const;
506
507
bool isCurrentVertexArray(const VertexArray *va) const
508
{
509
return mState.isCurrentVertexArray(va);
510
}
511
512
bool isShared() const { return mShared; }
513
// Once a context is setShared() it cannot be undone
514
void setShared() { mShared = true; }
515
516
const State &getState() const { return mState; }
517
GLint getClientMajorVersion() const { return mState.getClientMajorVersion(); }
518
GLint getClientMinorVersion() const { return mState.getClientMinorVersion(); }
519
const Version &getClientVersion() const { return mState.getClientVersion(); }
520
const Caps &getCaps() const { return mState.getCaps(); }
521
const TextureCapsMap &getTextureCaps() const { return mState.getTextureCaps(); }
522
const Extensions &getExtensions() const { return mState.getExtensions(); }
523
const Limitations &getLimitations() const { return mState.getLimitations(); }
524
bool isGLES1() const;
525
526
bool skipValidation() const
527
{
528
// Ensure we don't skip validation when context becomes lost, since implementations
529
// generally assume a non-lost context, non-null objects, etc.
530
ASSERT(!isContextLost() || !mSkipValidation);
531
return mSkipValidation;
532
}
533
534
// Specific methods needed for validation.
535
bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const;
536
bool getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams) const;
537
538
ANGLE_INLINE Program *getProgramResolveLink(ShaderProgramID handle) const
539
{
540
Program *program = mState.mShaderProgramManager->getProgram(handle);
541
if (program)
542
{
543
program->resolveLink(this);
544
}
545
return program;
546
}
547
548
Program *getProgramNoResolveLink(ShaderProgramID handle) const;
549
Shader *getShader(ShaderProgramID handle) const;
550
551
ANGLE_INLINE bool isTextureGenerated(TextureID texture) const
552
{
553
return mState.mTextureManager->isHandleGenerated(texture);
554
}
555
556
ANGLE_INLINE bool isBufferGenerated(BufferID buffer) const
557
{
558
return mState.mBufferManager->isHandleGenerated(buffer);
559
}
560
561
bool isRenderbufferGenerated(RenderbufferID renderbuffer) const;
562
bool isFramebufferGenerated(FramebufferID framebuffer) const;
563
bool isProgramPipelineGenerated(ProgramPipelineID pipeline) const;
564
bool isQueryGenerated(QueryID query) const;
565
566
bool usingDisplayTextureShareGroup() const;
567
bool usingDisplaySemaphoreShareGroup() const;
568
569
// Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
570
GLenum getConvertedRenderbufferFormat(GLenum internalformat) const;
571
572
bool isWebGL() const { return mState.isWebGL(); }
573
bool isWebGL1() const { return mState.isWebGL1(); }
574
575
bool isValidBufferBinding(BufferBinding binding) const { return mValidBufferBindings[binding]; }
576
577
// GLES1 emulation: Renderer level (for validation)
578
int vertexArrayIndex(ClientVertexArrayType type) const;
579
static int TexCoordArrayIndex(unsigned int unit);
580
581
// GL_KHR_parallel_shader_compile
582
std::shared_ptr<angle::WorkerThreadPool> getWorkerThreadPool() const { return mThreadPool; }
583
584
const StateCache &getStateCache() const { return mStateCache; }
585
StateCache &getStateCache() { return mStateCache; }
586
587
void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
588
589
void onSamplerUniformChange(size_t textureUnitIndex);
590
591
bool isBufferAccessValidationEnabled() const { return mBufferAccessValidationEnabled; }
592
593
const angle::FrontendFeatures &getFrontendFeatures() const;
594
595
angle::FrameCapture *getFrameCapture() const { return mFrameCapture.get(); }
596
597
const VertexArrayMap &getVertexArraysForCapture() const { return mVertexArrayMap; }
598
const QueryMap &getQueriesForCapture() const { return mQueryMap; }
599
const TransformFeedbackMap &getTransformFeedbacksForCapture() const
600
{
601
return mTransformFeedbackMap;
602
}
603
604
void onPreSwap() const;
605
606
Program *getActiveLinkedProgram() const;
607
608
// EGL_ANGLE_power_preference implementation.
609
egl::Error releaseHighPowerGPU();
610
egl::Error reacquireHighPowerGPU();
611
void onGPUSwitch();
612
613
bool noopDraw(PrimitiveMode mode, GLsizei count) const;
614
bool noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount) const;
615
616
bool isClearBufferMaskedOut(GLenum buffer, GLint drawbuffer) const;
617
bool noopClearBuffer(GLenum buffer, GLint drawbuffer) const;
618
619
void addRef() const { mRefCount++; }
620
void release() const { mRefCount--; }
621
size_t getRefCount() const { return mRefCount; }
622
623
egl::ShareGroup *getShareGroup() const { return mState.getShareGroup(); }
624
625
bool supportsGeometryOrTesselation() const;
626
void dirtyAllState();
627
628
bool isDestroyed() const { return mIsDestroyed; }
629
void setIsDestroyed() { mIsDestroyed = true; }
630
631
// Needed by capture serialization logic that works with a "const" Context pointer.
632
void finishImmutable() const;
633
634
private:
635
void initializeDefaultResources();
636
637
angle::Result prepareForDraw(PrimitiveMode mode);
638
angle::Result prepareForClear(GLbitfield mask);
639
angle::Result prepareForClearBuffer(GLenum buffer, GLint drawbuffer);
640
angle::Result syncState(const State::DirtyBits &bitMask,
641
const State::DirtyObjects &objectMask,
642
Command command);
643
angle::Result syncDirtyBits();
644
angle::Result syncDirtyBits(const State::DirtyBits &bitMask);
645
angle::Result syncDirtyObjects(const State::DirtyObjects &objectMask, Command command);
646
angle::Result syncStateForReadPixels();
647
angle::Result syncStateForTexImage();
648
angle::Result syncStateForBlit();
649
angle::Result syncStateForClear();
650
angle::Result syncTextureForCopy(Texture *texture);
651
652
VertexArray *checkVertexArrayAllocation(VertexArrayID vertexArrayHandle);
653
TransformFeedback *checkTransformFeedbackAllocation(TransformFeedbackID transformFeedback);
654
655
angle::Result onProgramLink(Program *programObject);
656
657
void detachBuffer(Buffer *buffer);
658
void detachTexture(TextureID texture);
659
void detachFramebuffer(FramebufferID framebuffer);
660
void detachRenderbuffer(RenderbufferID renderbuffer);
661
void detachVertexArray(VertexArrayID vertexArray);
662
void detachTransformFeedback(TransformFeedbackID transformFeedback);
663
void detachSampler(SamplerID sampler);
664
void detachProgramPipeline(ProgramPipelineID pipeline);
665
666
egl::Error setDefaultFramebuffer(egl::Surface *drawSurface, egl::Surface *readSurface);
667
egl::Error unsetDefaultFramebuffer();
668
669
void initRendererString();
670
void initVersionStrings();
671
void initExtensionStrings();
672
673
Extensions generateSupportedExtensions() const;
674
void initCaps();
675
void updateCaps();
676
677
gl::LabeledObject *getLabeledObject(GLenum identifier, GLuint name) const;
678
gl::LabeledObject *getLabeledObjectFromPtr(const void *ptr) const;
679
680
void setUniform1iImpl(Program *program,
681
UniformLocation location,
682
GLsizei count,
683
const GLint *v);
684
void renderbufferStorageMultisampleImpl(GLenum target,
685
GLsizei samples,
686
GLenum internalformat,
687
GLsizei width,
688
GLsizei height,
689
MultisamplingMode mode);
690
691
void convertPpoToComputeOrDraw(bool isCompute);
692
693
State mState;
694
bool mShared;
695
bool mSkipValidation;
696
bool mDisplayTextureShareGroup;
697
bool mDisplaySemaphoreShareGroup;
698
699
// Recorded errors
700
ErrorSet mErrors;
701
702
// Stores for each buffer binding type whether is it allowed to be used in this context.
703
angle::PackedEnumBitSet<BufferBinding> mValidBufferBindings;
704
705
std::unique_ptr<rx::ContextImpl> mImplementation;
706
707
EGLLabelKHR mLabel;
708
709
// Extensions supported by the implementation plus extensions that are implemented entirely
710
// within the frontend.
711
Extensions mSupportedExtensions;
712
713
// Shader compiler. Lazily initialized hence the mutable value.
714
mutable BindingPointer<Compiler> mCompiler;
715
716
const egl::Config *mConfig;
717
718
TextureMap mZeroTextures;
719
720
ResourceMap<FenceNV, FenceNVID> mFenceNVMap;
721
HandleAllocator mFenceNVHandleAllocator;
722
723
QueryMap mQueryMap;
724
HandleAllocator mQueryHandleAllocator;
725
726
VertexArrayMap mVertexArrayMap;
727
HandleAllocator mVertexArrayHandleAllocator;
728
729
TransformFeedbackMap mTransformFeedbackMap;
730
HandleAllocator mTransformFeedbackHandleAllocator;
731
732
const char *mVersionString;
733
const char *mShadingLanguageString;
734
const char *mRendererString;
735
const char *mExtensionString;
736
std::vector<const char *> mExtensionStrings;
737
const char *mRequestableExtensionString;
738
std::vector<const char *> mRequestableExtensionStrings;
739
740
// GLES1 renderer state
741
std::unique_ptr<GLES1Renderer> mGLES1Renderer;
742
743
// Current/lost context flags
744
bool mHasBeenCurrent;
745
bool mContextLost; // Set with setContextLost so that we also set mSkipValidation=false.
746
GraphicsResetStatus mResetStatus;
747
bool mContextLostForced;
748
GLenum mResetStrategy;
749
const bool mRobustAccess;
750
const bool mSurfacelessSupported;
751
egl::Surface *mCurrentDrawSurface;
752
egl::Surface *mCurrentReadSurface;
753
egl::Display *mDisplay;
754
const bool mWebGLContext;
755
bool mBufferAccessValidationEnabled;
756
const bool mExtensionsEnabled;
757
MemoryProgramCache *mMemoryProgramCache;
758
759
State::DirtyObjects mDrawDirtyObjects;
760
761
StateCache mStateCache;
762
763
State::DirtyBits mAllDirtyBits;
764
State::DirtyBits mTexImageDirtyBits;
765
State::DirtyObjects mTexImageDirtyObjects;
766
State::DirtyBits mReadPixelsDirtyBits;
767
State::DirtyObjects mReadPixelsDirtyObjects;
768
State::DirtyBits mClearDirtyBits;
769
State::DirtyObjects mClearDirtyObjects;
770
State::DirtyBits mBlitDirtyBits;
771
State::DirtyObjects mBlitDirtyObjects;
772
State::DirtyBits mComputeDirtyBits;
773
State::DirtyObjects mComputeDirtyObjects;
774
State::DirtyBits mCopyImageDirtyBits;
775
State::DirtyObjects mCopyImageDirtyObjects;
776
777
// Binding to container objects that use dependent state updates.
778
angle::ObserverBinding mVertexArrayObserverBinding;
779
angle::ObserverBinding mDrawFramebufferObserverBinding;
780
angle::ObserverBinding mReadFramebufferObserverBinding;
781
std::vector<angle::ObserverBinding> mUniformBufferObserverBindings;
782
std::vector<angle::ObserverBinding> mAtomicCounterBufferObserverBindings;
783
std::vector<angle::ObserverBinding> mShaderStorageBufferObserverBindings;
784
std::vector<angle::ObserverBinding> mSamplerObserverBindings;
785
std::vector<angle::ObserverBinding> mImageObserverBindings;
786
787
// Not really a property of context state. The size and contexts change per-api-call.
788
mutable Optional<angle::ScratchBuffer> mScratchBuffer;
789
mutable Optional<angle::ScratchBuffer> mZeroFilledBuffer;
790
791
std::shared_ptr<angle::WorkerThreadPool> mThreadPool;
792
793
// Note: we use a raw pointer here so we can exclude frame capture sources from the build.
794
std::unique_ptr<angle::FrameCapture> mFrameCapture;
795
796
// Cache representation of the serialized context string.
797
mutable std::string mCachedSerializedStateString;
798
799
mutable size_t mRefCount;
800
801
OverlayType mOverlay;
802
803
const bool mIsExternal;
804
const bool mSaveAndRestoreState;
805
806
bool mIsDestroyed;
807
};
808
809
class ScopedContextRef
810
{
811
public:
812
ScopedContextRef(Context *context) : mContext(context)
813
{
814
if (mContext)
815
{
816
mContext->addRef();
817
}
818
}
819
~ScopedContextRef()
820
{
821
if (mContext)
822
{
823
mContext->release();
824
}
825
}
826
827
private:
828
Context *const mContext;
829
};
830
831
// Thread-local current valid context bound to the thread.
832
extern thread_local Context *gCurrentValidContext;
833
834
} // namespace gl
835
836
#endif // LIBANGLE_CONTEXT_H_
837
838