• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <set>
14 #include <string>
15 
16 #include "angle_gl.h"
17 #include "common/MemoryBuffer.h"
18 #include "common/PackedEnums.h"
19 #include "common/angleutils.h"
20 #include "libANGLE/Caps.h"
21 #include "libANGLE/Constants.h"
22 #include "libANGLE/Context_gl_1_0_autogen.h"
23 #include "libANGLE/Context_gl_1_1_autogen.h"
24 #include "libANGLE/Context_gl_1_2_autogen.h"
25 #include "libANGLE/Context_gl_1_3_autogen.h"
26 #include "libANGLE/Context_gl_1_4_autogen.h"
27 #include "libANGLE/Context_gl_1_5_autogen.h"
28 #include "libANGLE/Context_gl_2_0_autogen.h"
29 #include "libANGLE/Context_gl_2_1_autogen.h"
30 #include "libANGLE/Context_gl_3_0_autogen.h"
31 #include "libANGLE/Context_gl_3_1_autogen.h"
32 #include "libANGLE/Context_gl_3_2_autogen.h"
33 #include "libANGLE/Context_gl_3_3_autogen.h"
34 #include "libANGLE/Context_gl_4_0_autogen.h"
35 #include "libANGLE/Context_gl_4_1_autogen.h"
36 #include "libANGLE/Context_gl_4_2_autogen.h"
37 #include "libANGLE/Context_gl_4_3_autogen.h"
38 #include "libANGLE/Context_gl_4_4_autogen.h"
39 #include "libANGLE/Context_gl_4_5_autogen.h"
40 #include "libANGLE/Context_gl_4_6_autogen.h"
41 #include "libANGLE/Context_gles_1_0_autogen.h"
42 #include "libANGLE/Context_gles_2_0_autogen.h"
43 #include "libANGLE/Context_gles_3_0_autogen.h"
44 #include "libANGLE/Context_gles_3_1_autogen.h"
45 #include "libANGLE/Context_gles_ext_autogen.h"
46 #include "libANGLE/Error.h"
47 #include "libANGLE/HandleAllocator.h"
48 #include "libANGLE/RefCountObject.h"
49 #include "libANGLE/ResourceManager.h"
50 #include "libANGLE/ResourceMap.h"
51 #include "libANGLE/State.h"
52 #include "libANGLE/VertexAttribute.h"
53 #include "libANGLE/WorkerThread.h"
54 #include "libANGLE/angletypes.h"
55 
56 namespace angle
57 {
58 class FrameCapture;
59 struct FrontendFeatures;
60 }  // namespace angle
61 
62 namespace rx
63 {
64 class ContextImpl;
65 class EGLImplFactory;
66 }  // namespace rx
67 
68 namespace egl
69 {
70 class AttributeMap;
71 class Surface;
72 struct Config;
73 class Thread;
74 }  // namespace egl
75 
76 namespace gl
77 {
78 class Buffer;
79 class Compiler;
80 class FenceNV;
81 class Framebuffer;
82 class GLES1Renderer;
83 class MemoryProgramCache;
84 class MemoryObject;
85 class Program;
86 class ProgramPipeline;
87 class Query;
88 class Renderbuffer;
89 class Sampler;
90 class Semaphore;
91 class Shader;
92 class Sync;
93 class Texture;
94 class TransformFeedback;
95 class VertexArray;
96 struct VertexAttribute;
97 
98 class ErrorSet : angle::NonCopyable
99 {
100   public:
101     explicit ErrorSet(Context *context);
102     ~ErrorSet();
103 
104     bool empty() const;
105     GLenum popError();
106 
107     void handleError(GLenum errorCode,
108                      const char *message,
109                      const char *file,
110                      const char *function,
111                      unsigned int line);
112 
113     void validationError(GLenum errorCode, const char *message);
114 
115   private:
116     Context *mContext;
117     std::set<GLenum> mErrors;
118 };
119 
120 enum class VertexAttribTypeCase
121 {
122     Invalid        = 0,
123     Valid          = 1,
124     ValidSize4Only = 2,
125 };
126 
127 // Helper class for managing cache variables and state changes.
128 class StateCache final : angle::NonCopyable
129 {
130   public:
131     StateCache();
132     ~StateCache();
133 
134     void initialize(Context *context);
135 
136     // Places that can trigger updateActiveAttribsMask:
137     // 1. onVertexArrayBindingChange.
138     // 2. onProgramExecutableChange.
139     // 3. onVertexArrayStateChange.
140     // 4. onGLES1ClientStateChange.
getActiveBufferedAttribsMask()141     AttributesMask getActiveBufferedAttribsMask() const { return mCachedActiveBufferedAttribsMask; }
getActiveClientAttribsMask()142     AttributesMask getActiveClientAttribsMask() const { return mCachedActiveClientAttribsMask; }
getActiveDefaultAttribsMask()143     AttributesMask getActiveDefaultAttribsMask() const { return mCachedActiveDefaultAttribsMask; }
hasAnyEnabledClientAttrib()144     bool hasAnyEnabledClientAttrib() const { return mCachedHasAnyEnabledClientAttrib; }
hasAnyActiveClientAttrib()145     bool hasAnyActiveClientAttrib() const { return mCachedActiveClientAttribsMask.any(); }
146 
147     // Places that can trigger updateVertexElementLimits:
148     // 1. onVertexArrayBindingChange.
149     // 2. onProgramExecutableChange.
150     // 3. onVertexArrayFormatChange.
151     // 4. onVertexArrayBufferChange.
152     // 5. onVertexArrayStateChange.
getNonInstancedVertexElementLimit()153     GLint64 getNonInstancedVertexElementLimit() const
154     {
155         return mCachedNonInstancedVertexElementLimit;
156     }
getInstancedVertexElementLimit()157     GLint64 getInstancedVertexElementLimit() const { return mCachedInstancedVertexElementLimit; }
158 
159     // Places that can trigger updateBasicDrawStatesError:
160     // 1. onVertexArrayBindingChange.
161     // 2. onProgramExecutableChange.
162     // 3. onVertexArrayBufferContentsChange.
163     // 4. onVertexArrayStateChange.
164     // 5. onVertexArrayBufferStateChange.
165     // 6. onDrawFramebufferChange.
166     // 7. onContextCapChange.
167     // 8. onStencilStateChange.
168     // 9. onDefaultVertexAttributeChange.
169     // 10. onActiveTextureChange.
170     // 11. onQueryChange.
171     // 12. onActiveTransformFeedbackChange.
172     // 13. onUniformBufferStateChange.
173     // 14. onColorMaskChange.
174     // 15. onBufferBindingChange.
hasBasicDrawStatesError(Context * context)175     bool hasBasicDrawStatesError(Context *context) const
176     {
177         if (mCachedBasicDrawStatesError == 0)
178         {
179             return false;
180         }
181         if (mCachedBasicDrawStatesError != kInvalidPointer)
182         {
183             return true;
184         }
185         return getBasicDrawStatesErrorImpl(context) != 0;
186     }
187 
getBasicDrawStatesError(Context * context)188     intptr_t getBasicDrawStatesError(Context *context) const
189     {
190         if (mCachedBasicDrawStatesError != kInvalidPointer)
191         {
192             return mCachedBasicDrawStatesError;
193         }
194 
195         return getBasicDrawStatesErrorImpl(context);
196     }
197 
198     // Places that can trigger updateBasicDrawElementsError:
199     // 1. onActiveTransformFeedbackChange.
200     // 2. onVertexArrayBufferStateChange.
201     // 3. onBufferBindingChange.
getBasicDrawElementsError(Context * context)202     intptr_t getBasicDrawElementsError(Context *context) const
203     {
204         if (mCachedBasicDrawElementsError != kInvalidPointer)
205         {
206             return mCachedBasicDrawElementsError;
207         }
208 
209         return getBasicDrawElementsErrorImpl(context);
210     }
211 
212     // Places that can trigger updateValidDrawModes:
213     // 1. onProgramExecutableChange.
214     // 2. onActiveTransformFeedbackChange.
isValidDrawMode(PrimitiveMode primitiveMode)215     bool isValidDrawMode(PrimitiveMode primitiveMode) const
216     {
217         return mCachedValidDrawModes[primitiveMode];
218     }
219 
220     // Cannot change except on Context/Extension init.
isValidBindTextureType(TextureType type)221     bool isValidBindTextureType(TextureType type) const
222     {
223         return mCachedValidBindTextureTypes[type];
224     }
225 
226     // Cannot change except on Context/Extension init.
isValidDrawElementsType(DrawElementsType type)227     bool isValidDrawElementsType(DrawElementsType type) const
228     {
229         return mCachedValidDrawElementsTypes[type];
230     }
231 
232     // Places that can trigger updateTransformFeedbackActiveUnpaused:
233     // 1. onActiveTransformFeedbackChange.
isTransformFeedbackActiveUnpaused()234     bool isTransformFeedbackActiveUnpaused() const
235     {
236         return mCachedTransformFeedbackActiveUnpaused;
237     }
238 
239     // Cannot change except on Context/Extension init.
getVertexAttribTypeValidation(VertexAttribType type)240     VertexAttribTypeCase getVertexAttribTypeValidation(VertexAttribType type) const
241     {
242         return mCachedVertexAttribTypesValidation[type];
243     }
244 
getIntegerVertexAttribTypeValidation(VertexAttribType type)245     VertexAttribTypeCase getIntegerVertexAttribTypeValidation(VertexAttribType type) const
246     {
247         return mCachedIntegerVertexAttribTypesValidation[type];
248     }
249 
250     // Places that can trigger updateActiveShaderStorageBufferIndices:
251     // 1. onProgramExecutableChange.
getActiveShaderStorageBufferIndices()252     StorageBuffersMask getActiveShaderStorageBufferIndices() const
253     {
254         return mCachedActiveShaderStorageBufferIndices;
255     }
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 onColorMaskChange(Context *context);
274     void onBufferBindingChange(Context *context);
275 
276   private:
277     // Cache update functions.
278     void updateActiveAttribsMask(Context *context);
279     void updateVertexElementLimits(Context *context);
280     void updateVertexElementLimitsImpl(Context *context);
281     void updateValidDrawModes(Context *context);
282     void updateValidBindTextureTypes(Context *context);
283     void updateValidDrawElementsTypes(Context *context);
284     void updateBasicDrawStatesError();
285     void updateBasicDrawElementsError();
286     void updateTransformFeedbackActiveUnpaused(Context *context);
287     void updateVertexAttribTypesValidation(Context *context);
288     void updateActiveShaderStorageBufferIndices(Context *context);
289 
290     void setValidDrawModes(bool pointsOK, bool linesOK, bool trisOK, bool lineAdjOK, bool triAdjOK);
291 
292     intptr_t getBasicDrawStatesErrorImpl(Context *context) const;
293     intptr_t getBasicDrawElementsErrorImpl(Context *context) const;
294 
295     static constexpr intptr_t kInvalidPointer = 1;
296 
297     AttributesMask mCachedActiveBufferedAttribsMask;
298     AttributesMask mCachedActiveClientAttribsMask;
299     AttributesMask mCachedActiveDefaultAttribsMask;
300     bool mCachedHasAnyEnabledClientAttrib;
301     GLint64 mCachedNonInstancedVertexElementLimit;
302     GLint64 mCachedInstancedVertexElementLimit;
303     mutable intptr_t mCachedBasicDrawStatesError;
304     mutable intptr_t mCachedBasicDrawElementsError;
305     bool mCachedTransformFeedbackActiveUnpaused;
306     StorageBuffersMask mCachedActiveShaderStorageBufferIndices;
307 
308     // Reserve an extra slot at the end of these maps for invalid enum.
309     angle::PackedEnumMap<PrimitiveMode, bool, angle::EnumSize<PrimitiveMode>() + 1>
310         mCachedValidDrawModes;
311     angle::PackedEnumMap<TextureType, bool, angle::EnumSize<TextureType>() + 1>
312         mCachedValidBindTextureTypes;
313     angle::PackedEnumMap<DrawElementsType, bool, angle::EnumSize<DrawElementsType>() + 1>
314         mCachedValidDrawElementsTypes;
315     angle::PackedEnumMap<VertexAttribType,
316                          VertexAttribTypeCase,
317                          angle::EnumSize<VertexAttribType>() + 1>
318         mCachedVertexAttribTypesValidation;
319     angle::PackedEnumMap<VertexAttribType,
320                          VertexAttribTypeCase,
321                          angle::EnumSize<VertexAttribType>() + 1>
322         mCachedIntegerVertexAttribTypesValidation;
323 };
324 
325 class Context final : public egl::LabeledObject, angle::NonCopyable, public angle::ObserverInterface
326 {
327   public:
328     Context(egl::Display *display,
329             const egl::Config *config,
330             const Context *shareContext,
331             TextureManager *shareTextures,
332             MemoryProgramCache *memoryProgramCache,
333             const EGLenum clientType,
334             const egl::AttributeMap &attribs,
335             const egl::DisplayExtensions &displayExtensions,
336             const egl::ClientExtensions &clientExtensions);
337 
338     egl::Error onDestroy(const egl::Display *display);
339     ~Context() override;
340 
341     void setLabel(EGLLabelKHR label) override;
342     EGLLabelKHR getLabel() const override;
343 
344     egl::Error makeCurrent(egl::Display *display, egl::Surface *surface);
345     egl::Error unMakeCurrent(const egl::Display *display);
346 
347     // These create  and destroy methods are merely pass-throughs to
348     // ResourceManager, which owns these object types
349     BufferID createBuffer();
350     TextureID createTexture();
351     RenderbufferID createRenderbuffer();
352     GLuint createProgramPipeline();
353     GLuint createMemoryObject();
354     GLuint createSemaphore();
355 
356     void deleteBuffer(BufferID buffer);
357     void deleteTexture(TextureID texture);
358     void deleteRenderbuffer(RenderbufferID renderbuffer);
359     void deleteProgramPipeline(GLuint pipeline);
360     void deleteMemoryObject(GLuint memoryObject);
361     void deleteSemaphore(GLuint semaphore);
362 
363     // CHROMIUM_path_rendering
364     bool isPathGenerated(GLuint path) const;
365 
366     void bindReadFramebuffer(GLuint framebufferHandle);
367     void bindDrawFramebuffer(GLuint framebufferHandle);
368 
369     Buffer *getBuffer(BufferID handle) const;
370     FenceNV *getFenceNV(GLuint handle);
371     Sync *getSync(GLsync handle) const;
getTexture(TextureID handle)372     ANGLE_INLINE Texture *getTexture(TextureID handle) const
373     {
374         return mState.mTextureManager->getTexture(handle);
375     }
376 
377     Framebuffer *getFramebuffer(GLuint handle) const;
378     Renderbuffer *getRenderbuffer(RenderbufferID handle) const;
379     VertexArray *getVertexArray(GLuint handle) const;
380     Sampler *getSampler(GLuint handle) const;
381     Query *getQuery(GLuint handle, bool create, QueryType type);
382     Query *getQuery(GLuint handle) const;
383     TransformFeedback *getTransformFeedback(GLuint handle) const;
384     ProgramPipeline *getProgramPipeline(GLuint handle) const;
385     MemoryObject *getMemoryObject(GLuint handle) const;
386     Semaphore *getSemaphore(GLuint handle) const;
387 
388     Texture *getTextureByType(TextureType type) const;
389     Texture *getTextureByTarget(TextureTarget target) const;
390     Texture *getSamplerTexture(unsigned int sampler, TextureType type) const;
391 
392     Compiler *getCompiler() const;
393 
394     bool isVertexArrayGenerated(GLuint vertexArray);
395     bool isTransformFeedbackGenerated(GLuint vertexArray);
396 
397     void getBooleanvImpl(GLenum pname, GLboolean *params);
398     void getFloatvImpl(GLenum pname, GLfloat *params);
399     void getIntegervImpl(GLenum pname, GLint *params);
400     void getInteger64vImpl(GLenum pname, GLint64 *params);
401     void getPointerv(GLenum pname, void **params) const;
402 
403     // Framebuffers are owned by the Context, so these methods do not pass through
404     GLuint createFramebuffer();
405     void deleteFramebuffer(GLuint framebuffer);
406 
407     bool hasActiveTransformFeedback(GLuint program) const;
408 
409     // GL emulation: Interface to entry points
410     ANGLE_GL_1_0_CONTEXT_API
411     ANGLE_GL_1_1_CONTEXT_API
412     ANGLE_GL_1_2_CONTEXT_API
413     ANGLE_GL_1_3_CONTEXT_API
414     ANGLE_GL_1_4_CONTEXT_API
415     ANGLE_GL_1_5_CONTEXT_API
416     ANGLE_GL_2_0_CONTEXT_API
417     ANGLE_GL_2_1_CONTEXT_API
418     ANGLE_GL_3_0_CONTEXT_API
419     ANGLE_GL_3_1_CONTEXT_API
420     ANGLE_GL_3_2_CONTEXT_API
421     ANGLE_GL_3_3_CONTEXT_API
422     ANGLE_GL_4_0_CONTEXT_API
423     ANGLE_GL_4_1_CONTEXT_API
424     ANGLE_GL_4_2_CONTEXT_API
425     ANGLE_GL_4_3_CONTEXT_API
426     ANGLE_GL_4_4_CONTEXT_API
427     ANGLE_GL_4_5_CONTEXT_API
428     ANGLE_GL_4_6_CONTEXT_API
429 
430     // GLES emulation: Interface to entry points
431     ANGLE_GLES_1_0_CONTEXT_API
432     ANGLE_GLES_2_0_CONTEXT_API
433     ANGLE_GLES_3_0_CONTEXT_API
434     ANGLE_GLES_3_1_CONTEXT_API
435     ANGLE_GLES_EXT_CONTEXT_API
436 
437     // Consumes an error.
438     void handleError(GLenum errorCode,
439                      const char *message,
440                      const char *file,
441                      const char *function,
442                      unsigned int line);
443 
444     void validationError(GLenum errorCode, const char *message);
445 
446     void markContextLost(GraphicsResetStatus status);
447 
isContextLost()448     bool isContextLost() const { return mContextLost; }
449 
getGraphicsResetStrategy()450     GLenum getGraphicsResetStrategy() const { return mResetStrategy; }
451     bool isResetNotificationEnabled();
452 
453     const egl::Config *getConfig() const;
454     EGLenum getClientType() const;
455     EGLenum getRenderBuffer() const;
456 
457     const GLubyte *getString(GLenum name) const;
458     const GLubyte *getStringi(GLenum name, GLuint index) const;
459 
460     size_t getExtensionStringCount() const;
461 
462     bool isExtensionRequestable(const char *name);
463     size_t getRequestableExtensionStringCount() const;
464 
getImplementation()465     rx::ContextImpl *getImplementation() const { return mImplementation.get(); }
466 
467     ANGLE_NO_DISCARD bool getScratchBuffer(size_t requestedSizeBytes,
468                                            angle::MemoryBuffer **scratchBufferOut) const;
469     ANGLE_NO_DISCARD bool getZeroFilledBuffer(size_t requstedSizeBytes,
470                                               angle::MemoryBuffer **zeroBufferOut) const;
getScratchBuffer()471     angle::ScratchBuffer *getScratchBuffer() const { return &mScratchBuffer; }
472 
473     angle::Result prepareForCopyImage();
474     angle::Result prepareForDispatch();
475 
getMemoryProgramCache()476     MemoryProgramCache *getMemoryProgramCache() const { return mMemoryProgramCache; }
477 
hasBeenCurrent()478     bool hasBeenCurrent() const { return mHasBeenCurrent; }
getDisplay()479     egl::Display *getDisplay() const { return mDisplay; }
getCurrentDrawSurface()480     egl::Surface *getCurrentDrawSurface() const { return mCurrentSurface; }
getCurrentReadSurface()481     egl::Surface *getCurrentReadSurface() const { return mCurrentSurface; }
482 
isRobustResourceInitEnabled()483     bool isRobustResourceInitEnabled() const { return mState.isRobustResourceInitEnabled(); }
484 
485     bool isCurrentTransformFeedback(const TransformFeedback *tf) const;
486 
isCurrentVertexArray(const VertexArray * va)487     bool isCurrentVertexArray(const VertexArray *va) const
488     {
489         return mState.isCurrentVertexArray(va);
490     }
491 
isShared()492     bool isShared() const { return mShared; }
493     // Once a context is setShared() it cannot be undone
setShared()494     void setShared() { mShared = true; }
495 
getState()496     const State &getState() const { return mState; }
getClientMajorVersion()497     GLint getClientMajorVersion() const { return mState.getClientMajorVersion(); }
getClientMinorVersion()498     GLint getClientMinorVersion() const { return mState.getClientMinorVersion(); }
getClientVersion()499     const Version &getClientVersion() const { return mState.getClientVersion(); }
getCaps()500     const Caps &getCaps() const { return mState.getCaps(); }
getTextureCaps()501     const TextureCapsMap &getTextureCaps() const { return mState.getTextureCaps(); }
getExtensions()502     const Extensions &getExtensions() const { return mState.getExtensions(); }
getLimitations()503     const Limitations &getLimitations() const { return mState.getLimitations(); }
skipValidation()504     bool skipValidation() const { return mSkipValidation; }
505     bool isGLES1() const;
506 
507     // Specific methods needed for validation.
508     bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const;
509     bool getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams) const;
510 
getProgramResolveLink(GLuint handle)511     ANGLE_INLINE Program *getProgramResolveLink(GLuint handle) const
512     {
513         Program *program = mState.mShaderProgramManager->getProgram(handle);
514         if (program)
515         {
516             program->resolveLink(this);
517         }
518         return program;
519     }
520 
521     Program *getProgramNoResolveLink(GLuint handle) const;
522     Shader *getShader(GLuint handle) const;
523 
isTextureGenerated(TextureID texture)524     ANGLE_INLINE bool isTextureGenerated(TextureID texture) const
525     {
526         return mState.mTextureManager->isHandleGenerated(texture);
527     }
528 
isBufferGenerated(BufferID buffer)529     ANGLE_INLINE bool isBufferGenerated(BufferID buffer) const
530     {
531         return mState.mBufferManager->isHandleGenerated(buffer);
532     }
533 
534     bool isRenderbufferGenerated(RenderbufferID renderbuffer) const;
535     bool isFramebufferGenerated(GLuint framebuffer) const;
536     bool isProgramPipelineGenerated(GLuint pipeline) const;
537 
538     bool usingDisplayTextureShareGroup() const;
539 
540     // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
541     GLenum getConvertedRenderbufferFormat(GLenum internalformat) const;
542 
isWebGL()543     bool isWebGL() const { return mState.isWebGL(); }
isWebGL1()544     bool isWebGL1() const { return mState.isWebGL1(); }
545 
isValidBufferBinding(BufferBinding binding)546     bool isValidBufferBinding(BufferBinding binding) const { return mValidBufferBindings[binding]; }
547 
548     // GLES1 emulation: Renderer level (for validation)
549     int vertexArrayIndex(ClientVertexArrayType type) const;
550     static int TexCoordArrayIndex(unsigned int unit);
551 
552     // GL_KHR_parallel_shader_compile
getWorkerThreadPool()553     std::shared_ptr<angle::WorkerThreadPool> getWorkerThreadPool() const { return mThreadPool; }
554 
getStateCache()555     const StateCache &getStateCache() const { return mStateCache; }
getStateCache()556     StateCache &getStateCache() { return mStateCache; }
557 
558     void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
559 
560     void onSamplerUniformChange(size_t textureUnitIndex);
561 
isBufferAccessValidationEnabled()562     bool isBufferAccessValidationEnabled() const { return mBufferAccessValidationEnabled; }
563 
564     const angle::FrontendFeatures &getFrontendFeatures() const;
565 
getFrameCapture()566     angle::FrameCapture *getFrameCapture() { return mFrameCapture.get(); }
567 
568     void onPostSwap() const;
569 
570   private:
571     void initialize();
572 
573     bool noopDraw(PrimitiveMode mode, GLsizei count);
574     bool noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount);
575 
576     angle::Result prepareForDraw(PrimitiveMode mode);
577     angle::Result prepareForClear(GLbitfield mask);
578     angle::Result prepareForClearBuffer(GLenum buffer, GLint drawbuffer);
579     angle::Result syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask);
580     angle::Result syncDirtyBits();
581     angle::Result syncDirtyBits(const State::DirtyBits &bitMask);
582     angle::Result syncDirtyObjects(const State::DirtyObjects &objectMask);
583     angle::Result syncStateForReadPixels();
584     angle::Result syncStateForTexImage();
585     angle::Result syncStateForBlit();
586     angle::Result syncStateForPathOperation();
587 
588     VertexArray *checkVertexArrayAllocation(GLuint vertexArrayHandle);
589     TransformFeedback *checkTransformFeedbackAllocation(GLuint transformFeedback);
590 
591     angle::Result onProgramLink(Program *programObject);
592 
593     void detachBuffer(Buffer *buffer);
594     void detachTexture(TextureID texture);
595     void detachFramebuffer(GLuint framebuffer);
596     void detachRenderbuffer(RenderbufferID renderbuffer);
597     void detachVertexArray(GLuint vertexArray);
598     void detachTransformFeedback(GLuint transformFeedback);
599     void detachSampler(GLuint sampler);
600     void detachProgramPipeline(GLuint pipeline);
601 
602     // A small helper method to facilitate using the ANGLE_CONTEXT_TRY macro.
603     void tryGenPaths(GLsizei range, GLuint *createdOut);
604 
605     egl::Error setDefaultFramebuffer(egl::Surface *surface);
606     egl::Error unsetDefaultFramebuffer();
607 
608     void initRendererString();
609     void initVersionStrings();
610     void initExtensionStrings();
611 
612     Extensions generateSupportedExtensions() const;
613     void initCaps();
614     void updateCaps();
615 
616     gl::LabeledObject *getLabeledObject(GLenum identifier, GLuint name) const;
617     gl::LabeledObject *getLabeledObjectFromPtr(const void *ptr) const;
618 
619     void setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v);
620 
621     State mState;
622     bool mShared;
623     bool mSkipValidation;
624     bool mDisplayTextureShareGroup;
625 
626     // Recorded errors
627     ErrorSet mErrors;
628 
629     // Stores for each buffer binding type whether is it allowed to be used in this context.
630     angle::PackedEnumBitSet<BufferBinding> mValidBufferBindings;
631 
632     std::unique_ptr<rx::ContextImpl> mImplementation;
633 
634     EGLLabelKHR mLabel;
635 
636     // Extensions supported by the implementation plus extensions that are implemented entirely
637     // within the frontend.
638     Extensions mSupportedExtensions;
639 
640     // Shader compiler. Lazily initialized hence the mutable value.
641     mutable BindingPointer<Compiler> mCompiler;
642 
643     const egl::Config *mConfig;
644 
645     TextureMap mZeroTextures;
646 
647     ResourceMap<FenceNV> mFenceNVMap;
648     HandleAllocator mFenceNVHandleAllocator;
649 
650     ResourceMap<Query> mQueryMap;
651     HandleAllocator mQueryHandleAllocator;
652 
653     ResourceMap<VertexArray> mVertexArrayMap;
654     HandleAllocator mVertexArrayHandleAllocator;
655 
656     ResourceMap<TransformFeedback> mTransformFeedbackMap;
657     HandleAllocator mTransformFeedbackHandleAllocator;
658 
659     const char *mVersionString;
660     const char *mShadingLanguageString;
661     const char *mRendererString;
662     const char *mExtensionString;
663     std::vector<const char *> mExtensionStrings;
664     const char *mRequestableExtensionString;
665     std::vector<const char *> mRequestableExtensionStrings;
666 
667     // GLES1 renderer state
668     std::unique_ptr<GLES1Renderer> mGLES1Renderer;
669 
670     // Current/lost context flags
671     bool mHasBeenCurrent;
672     bool mContextLost;
673     GraphicsResetStatus mResetStatus;
674     bool mContextLostForced;
675     GLenum mResetStrategy;
676     const bool mRobustAccess;
677     const bool mSurfacelessSupported;
678     const bool mExplicitContextAvailable;
679     egl::Surface *mCurrentSurface;
680     egl::Display *mDisplay;
681     const bool mWebGLContext;
682     bool mBufferAccessValidationEnabled;
683     const bool mExtensionsEnabled;
684     MemoryProgramCache *mMemoryProgramCache;
685 
686     State::DirtyObjects mDrawDirtyObjects;
687     State::DirtyObjects mPathOperationDirtyObjects;
688 
689     StateCache mStateCache;
690 
691     State::DirtyBits mAllDirtyBits;
692     State::DirtyBits mTexImageDirtyBits;
693     State::DirtyObjects mTexImageDirtyObjects;
694     State::DirtyBits mReadPixelsDirtyBits;
695     State::DirtyObjects mReadPixelsDirtyObjects;
696     State::DirtyBits mClearDirtyBits;
697     State::DirtyObjects mClearDirtyObjects;
698     State::DirtyBits mBlitDirtyBits;
699     State::DirtyObjects mBlitDirtyObjects;
700     State::DirtyBits mComputeDirtyBits;
701     State::DirtyObjects mComputeDirtyObjects;
702     State::DirtyBits mCopyImageDirtyBits;
703     State::DirtyObjects mCopyImageDirtyObjects;
704 
705     // Binding to container objects that use dependent state updates.
706     angle::ObserverBinding mVertexArrayObserverBinding;
707     angle::ObserverBinding mDrawFramebufferObserverBinding;
708     angle::ObserverBinding mReadFramebufferObserverBinding;
709     std::vector<angle::ObserverBinding> mUniformBufferObserverBindings;
710     std::vector<angle::ObserverBinding> mSamplerObserverBindings;
711 
712     // Not really a property of context state. The size and contexts change per-api-call.
713     mutable angle::ScratchBuffer mScratchBuffer;
714     mutable angle::ScratchBuffer mZeroFilledBuffer;
715 
716     std::shared_ptr<angle::WorkerThreadPool> mThreadPool;
717 
718     // Note: we use a raw pointer here so we can exclude frame capture sources from the build.
719     std::unique_ptr<angle::FrameCapture> mFrameCapture;
720 };
721 
722 }  // namespace gl
723 
724 #endif  // LIBANGLE_CONTEXT_H_
725