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