chromium/third_party/angle/src/libANGLE/State.cpp

//
// Copyright 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

// State.cpp: Implements the State class, encapsulating raw GL state.

#include "libANGLE/State.h"

#include <string.h>
#include <limits>

#include "common/bitset_utils.h"
#include "common/mathutil.h"
#include "common/matrix_utils.h"
#include "libANGLE/Buffer.h"
#include "libANGLE/Caps.h"
#include "libANGLE/Context.h"
#include "libANGLE/Debug.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/PixelLocalStorage.h"
#include "libANGLE/Query.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/queryconversions.h"
#include "libANGLE/queryutils.h"
#include "libANGLE/renderer/ContextImpl.h"
#include "libANGLE/renderer/TextureImpl.h"

namespace gl
{

namespace
{
bool GetAlternativeQueryType(QueryType type, QueryType *alternativeType)
{}

// Mapping from a buffer binding type to a dirty bit type.
constexpr angle::PackedEnumMap<BufferBinding, size_t> kBufferBindingDirtyBits =;

// Returns a buffer binding function depending on if a dirty bit is set.
template <BufferBinding Target>
constexpr std::pair<BufferBinding, State::BufferBindingSetter> GetBufferBindingSetter()
{}

ContextStateMember;

template <typename T>
T *AllocateOrGetSharedResourceManager(const State *shareContextState,
                                      ContextStateMember<T> member,
                                      T *shareResources = nullptr)
{}

// TODO(https://anglebug.com/42262534): Remove this helper function after blink and chromium part
// refactory done.
bool IsTextureCompatibleWithSampler(TextureType texture, TextureType sampler)
{}

uint32_t gIDCounter =;
}  // namespace

template <typename BindingT, typename... ArgsT>
ANGLE_INLINE void UpdateNonTFBufferBindingWebGL(const Context *context,
                                                BindingT *binding,
                                                Buffer *buffer,
                                                ArgsT... args)
{}

template <typename BindingT, typename... ArgsT>
void UpdateTFBufferBindingWebGL(const Context *context,
                                BindingT *binding,
                                bool indexed,
                                ArgsT... args)
{}

void UpdateBufferBinding(const Context *context,
                         BindingPointer<Buffer> *binding,
                         Buffer *buffer,
                         BufferBinding target)
{}

void UpdateIndexedBufferBinding(const Context *context,
                                OffsetBindingPointer<Buffer> *binding,
                                Buffer *buffer,
                                BufferBinding target,
                                GLintptr offset,
                                GLsizeiptr size)
{}

// These template functions must be defined before they are instantiated in kBufferSetters.
template <BufferBinding Target>
void State::setGenericBufferBindingWithBit(const Context *context, Buffer *buffer)
{}

template <BufferBinding Target>
void State::setGenericBufferBinding(const Context *context, Buffer *buffer)
{}

template <>
void State::setGenericBufferBinding<BufferBinding::TransformFeedback>(const Context *context,
                                                                      Buffer *buffer)
{}

template <>
void State::setGenericBufferBinding<BufferBinding::ElementArray>(const Context *context,
                                                                 Buffer *buffer)
{}

const angle::PackedEnumMap<BufferBinding, State::BufferBindingSetter> State::kBufferSetters =;

ActiveTexturesCache::ActiveTexturesCache() :{}

ActiveTexturesCache::~ActiveTexturesCache()
{}

void ActiveTexturesCache::clear()
{}

bool ActiveTexturesCache::empty() const
{}

ANGLE_INLINE void ActiveTexturesCache::reset(size_t textureIndex)
{}

ANGLE_INLINE void ActiveTexturesCache::set(size_t textureIndex, Texture *texture)
{}

PrivateState::PrivateState(const EGLenum clientType,
                           const Version &clientVersion,
                           EGLint profileMask,
                           bool debug,
                           bool bindGeneratesResourceCHROMIUM,
                           bool clientArraysEnabled,
                           bool robustResourceInit,
                           bool programBinaryCacheEnabled,
                           bool isExternal)
    :{}

PrivateState::~PrivateState() = default;

void PrivateState::initialize(Context *context)
{}

void PrivateState::initializeForCapture(const Context *context)
{}

void PrivateState::reset()
{}

void PrivateState::setColorClearValue(float red, float green, float blue, float alpha)
{}

void PrivateState::setDepthClearValue(float depth)
{}

void PrivateState::setStencilClearValue(int stencil)
{}

void PrivateState::setColorMask(bool red, bool green, bool blue, bool alpha)
{}

void PrivateState::setColorMaskIndexed(bool red, bool green, bool blue, bool alpha, GLuint index)
{}

void PrivateState::setDepthMask(bool mask)
{}

void PrivateState::setRasterizerDiscard(bool enabled)
{}

void PrivateState::setPrimitiveRestart(bool enabled)
{}

void PrivateState::setCullFace(bool enabled)
{}

void PrivateState::setCullMode(CullFaceMode mode)
{}

void PrivateState::setFrontFace(GLenum front)
{}

void PrivateState::setDepthClamp(bool enabled)
{}

void PrivateState::setDepthTest(bool enabled)
{}

void PrivateState::setDepthFunc(GLenum depthFunc)
{}

void PrivateState::setDepthRange(float zNear, float zFar)
{}

void PrivateState::setClipControl(ClipOrigin origin, ClipDepthMode depth)
{}

void PrivateState::setBlend(bool enabled)
{}

void PrivateState::setBlendIndexed(bool enabled, GLuint index)
{}

ANGLE_INLINE bool PrivateState::hasConstantColor(GLenum sourceRGB, GLenum destRGB) const
{}

ANGLE_INLINE bool PrivateState::hasConstantAlpha(GLenum sourceRGB, GLenum destRGB) const
{}

void PrivateState::setBlendFactors(GLenum sourceRGB,
                                   GLenum destRGB,
                                   GLenum sourceAlpha,
                                   GLenum destAlpha)
{}

void PrivateState::setBlendFactorsIndexed(GLenum sourceRGB,
                                          GLenum destRGB,
                                          GLenum sourceAlpha,
                                          GLenum destAlpha,
                                          GLuint index)
{}

void PrivateState::setBlendColor(float red, float green, float blue, float alpha)
{}

void PrivateState::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation)
{}

void PrivateState::setBlendEquationIndexed(GLenum rgbEquation, GLenum alphaEquation, GLuint index)
{}

void PrivateState::setStencilTest(bool enabled)
{}

void PrivateState::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask)
{}

void PrivateState::setStencilBackParams(GLenum stencilBackFunc,
                                        GLint stencilBackRef,
                                        GLuint stencilBackMask)
{}

void PrivateState::setStencilWritemask(GLuint stencilWritemask)
{}

void PrivateState::setStencilBackWritemask(GLuint stencilBackWritemask)
{}

void PrivateState::setStencilOperations(GLenum stencilFail,
                                        GLenum stencilPassDepthFail,
                                        GLenum stencilPassDepthPass)
{}

void PrivateState::setStencilBackOperations(GLenum stencilBackFail,
                                            GLenum stencilBackPassDepthFail,
                                            GLenum stencilBackPassDepthPass)
{}

void PrivateState::setPolygonMode(PolygonMode mode)
{}

void PrivateState::setPolygonOffsetPoint(bool enabled)
{}

void PrivateState::setPolygonOffsetLine(bool enabled)
{}

void PrivateState::setPolygonOffsetFill(bool enabled)
{}

void PrivateState::setPolygonOffsetParams(GLfloat factor, GLfloat units, GLfloat clamp)
{}

void PrivateState::setSampleAlphaToCoverage(bool enabled)
{}

void PrivateState::setSampleCoverage(bool enabled)
{}

void PrivateState::setSampleCoverageParams(GLclampf value, bool invert)
{}

void PrivateState::setSampleMaskEnabled(bool enabled)
{}

void PrivateState::setSampleMaskParams(GLuint maskNumber, GLbitfield mask)
{}

void PrivateState::setSampleAlphaToOne(bool enabled)
{}

void PrivateState::setBlendAdvancedCoherent(bool enabled)
{}

void PrivateState::setMultisampling(bool enabled)
{}

void PrivateState::setSampleShading(bool enabled)
{}

void PrivateState::setMinSampleShading(float value)
{}

void PrivateState::setScissorTest(bool enabled)
{}

void PrivateState::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height)
{}

void PrivateState::setDither(bool enabled)
{}

void PrivateState::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height)
{}

void PrivateState::setShadingRate(GLenum rate)
{}

void PrivateState::setPackAlignment(GLint alignment)
{}

void PrivateState::setPackReverseRowOrder(bool reverseRowOrder)
{}

void PrivateState::setPackRowLength(GLint rowLength)
{}

void PrivateState::setPackSkipRows(GLint skipRows)
{}

void PrivateState::setPackSkipPixels(GLint skipPixels)
{}

void PrivateState::setUnpackAlignment(GLint alignment)
{}

void PrivateState::setUnpackRowLength(GLint rowLength)
{}

void PrivateState::setUnpackImageHeight(GLint imageHeight)
{}

void PrivateState::setUnpackSkipImages(GLint skipImages)
{}

void PrivateState::setUnpackSkipRows(GLint skipRows)
{}

void PrivateState::setUnpackSkipPixels(GLint skipPixels)
{}

void PrivateState::setCoverageModulation(GLenum components)
{}

void PrivateState::setFramebufferSRGB(bool sRGB)
{}

void PrivateState::setPatchVertices(GLuint value)
{}

void PrivateState::setPixelLocalStorageActivePlanes(GLsizei n)
{}

void PrivateState::setLineWidth(GLfloat width)
{}

void PrivateState::setGenerateMipmapHint(GLenum hint)
{}

void PrivateState::setFragmentShaderDerivativeHint(GLenum hint)
{}

void PrivateState::setActiveSampler(unsigned int active)
{}

AttributesMask PrivateState::getAndResetDirtyCurrentValues() const
{}

void PrivateState::setClipDistanceEnable(int idx, bool enable)
{}

void PrivateState::setBoundingBox(GLfloat minX,
                                  GLfloat minY,
                                  GLfloat minZ,
                                  GLfloat minW,
                                  GLfloat maxX,
                                  GLfloat maxY,
                                  GLfloat maxZ,
                                  GLfloat maxW)
{}

void PrivateState::setLogicOpEnabled(bool enabled)
{}

void PrivateState::setLogicOp(LogicalOperation opcode)
{}

void PrivateState::setVertexAttribf(GLuint index, const GLfloat values[4])
{}

void PrivateState::setVertexAttribu(GLuint index, const GLuint values[4])
{}

void PrivateState::setVertexAttribi(GLuint index, const GLint values[4])
{}

void PrivateState::setEnableFeature(GLenum feature, bool enabled)
{}

void PrivateState::setEnableFeatureIndexed(GLenum feature, bool enabled, GLuint index)
{}

bool PrivateState::getEnableFeature(GLenum feature) const
{}

bool PrivateState::getEnableFeatureIndexed(GLenum feature, GLuint index) const
{}

void PrivateState::getBooleanv(GLenum pname, GLboolean *params) const
{}

void PrivateState::getFloatv(GLenum pname, GLfloat *params) const
{}

void PrivateState::getIntegerv(GLenum pname, GLint *params) const
{}

void PrivateState::getIntegeri_v(GLenum target, GLuint index, GLint *data) const
{}

void PrivateState::getBooleani_v(GLenum target, GLuint index, GLboolean *data) const
{}

State::State(const State *shareContextState,
             egl::ShareGroup *shareGroup,
             TextureManager *shareTextures,
             SemaphoreManager *shareSemaphores,
             egl::ContextMutex *contextMutex,
             const OverlayType *overlay,
             const EGLenum clientType,
             const Version &clientVersion,
             EGLint profileMask,
             bool debug,
             bool bindGeneratesResourceCHROMIUM,
             bool clientArraysEnabled,
             bool robustResourceInit,
             bool programBinaryCacheEnabled,
             EGLenum contextPriority,
             bool hasRobustAccess,
             bool hasProtectedContent,
             bool isExternal)
    :{}

State::~State() {}

void State::initialize(Context *context)
{}

void State::reset(const Context *context)
{}

ANGLE_INLINE void State::unsetActiveTextures(const ActiveTextureMask &textureMask)
{}

ANGLE_INLINE void State::updateActiveTextureStateOnSync(const Context *context,
                                                        size_t textureIndex,
                                                        const Sampler *sampler,
                                                        Texture *texture)
{}

ANGLE_INLINE void State::setActiveTextureDirty(size_t textureIndex, Texture *texture)
{}

ANGLE_INLINE void State::updateTextureBinding(const Context *context,
                                              size_t textureIndex,
                                              Texture *texture)
{}

bool State::allActiveDrawBufferChannelsMasked() const
{}

bool State::anyActiveDrawBufferChannelMasked() const
{}

void State::setSamplerTexture(const Context *context, TextureType type, Texture *texture)
{}

Texture *State::getTargetTexture(TextureType type) const
{}

TextureID State::getSamplerTextureId(unsigned int sampler, TextureType type) const
{}

void State::detachTexture(Context *context, const TextureMap &zeroTextures, TextureID texture)
{}

void State::initializeZeroTextures(const Context *context, const TextureMap &zeroTextures)
{}

void State::invalidateTextureBindings(TextureType type)
{}

void State::setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler)
{}

void State::detachSampler(const Context *context, SamplerID sampler)
{}

void State::setRenderbufferBinding(const Context *context, Renderbuffer *renderbuffer)
{}

void State::detachRenderbuffer(Context *context, RenderbufferID renderbuffer)
{}

void State::setReadFramebufferBinding(Framebuffer *framebuffer)
{}

void State::setDrawFramebufferBinding(Framebuffer *framebuffer)
{}

Framebuffer *State::getTargetFramebuffer(GLenum target) const
{}

Framebuffer *State::getDefaultFramebuffer() const
{}

bool State::removeReadFramebufferBinding(FramebufferID framebuffer)
{}

bool State::removeDrawFramebufferBinding(FramebufferID framebuffer)
{}

void State::setVertexArrayBinding(const Context *context, VertexArray *vertexArray)
{}

bool State::removeVertexArrayBinding(const Context *context, VertexArrayID vertexArray)
{}

VertexArrayID State::getVertexArrayId() const
{}

void State::bindVertexBuffer(const Context *context,
                             GLuint bindingIndex,
                             Buffer *boundBuffer,
                             GLintptr offset,
                             GLsizei stride)
{}

void State::setVertexAttribFormat(GLuint attribIndex,
                                  GLint size,
                                  VertexAttribType type,
                                  bool normalized,
                                  bool pureInteger,
                                  GLuint relativeOffset)
{}

void State::setVertexBindingDivisor(const Context *context, GLuint bindingIndex, GLuint divisor)
{}

angle::Result State::setProgram(const Context *context, Program *newProgram)
{}

void State::setTransformFeedbackBinding(const Context *context,
                                        TransformFeedback *transformFeedback)
{}

bool State::removeTransformFeedbackBinding(const Context *context,
                                           TransformFeedbackID transformFeedback)
{}

angle::Result State::setProgramPipelineBinding(const Context *context, ProgramPipeline *pipeline)
{}

void State::detachProgramPipeline(const Context *context, ProgramPipelineID pipeline)
{}

bool State::isQueryActive(QueryType type) const
{}

bool State::isQueryActive(Query *query) const
{}

void State::setActiveQuery(const Context *context, QueryType type, Query *query)
{}

QueryID State::getActiveQueryId(QueryType type) const
{}

Query *State::getActiveQuery(QueryType type) const
{}

angle::Result State::setIndexedBufferBinding(const Context *context,
                                             BufferBinding target,
                                             GLuint index,
                                             Buffer *buffer,
                                             GLintptr offset,
                                             GLsizeiptr size)
{}

const OffsetBindingPointer<Buffer> &State::getIndexedUniformBuffer(size_t index) const
{}

const OffsetBindingPointer<Buffer> &State::getIndexedAtomicCounterBuffer(size_t index) const
{}

const OffsetBindingPointer<Buffer> &State::getIndexedShaderStorageBuffer(size_t index) const
{}

angle::Result State::detachBuffer(Context *context, const Buffer *buffer)
{}

void State::setEnableVertexAttribArray(unsigned int attribNum, bool enabled)
{}

void State::setVertexAttribDivisor(const Context *context, GLuint index, GLuint divisor)
{}

const void *State::getVertexAttribPointer(unsigned int attribNum) const
{}

void State::getBooleanv(GLenum pname, GLboolean *params) const
{}

angle::Result State::getIntegerv(const Context *context, GLenum pname, GLint *params) const
{}

void State::getPointerv(const Context *context, GLenum pname, void **params) const
{}

void State::getIntegeri_v(const Context *context, GLenum target, GLuint index, GLint *data) const
{}

void State::getInteger64i_v(GLenum target, GLuint index, GLint64 *data) const
{}

void State::getBooleani_v(GLenum target, GLuint index, GLboolean *data) const
{}

// TODO(http://anglebug.com/42262534): Remove this helper function after blink and chromium part
// refactor done.
Texture *State::getTextureForActiveSampler(TextureType type, size_t index)
{}

angle::Result State::syncActiveTextures(const Context *context, Command command)
{}

angle::Result State::syncTexturesInit(const Context *context, Command command)
{}

angle::Result State::syncImagesInit(const Context *context, Command command)
{}

angle::Result State::syncReadAttachments(const Context *context, Command command)
{}

angle::Result State::syncDrawAttachments(const Context *context, Command command)
{}

angle::Result State::syncReadFramebuffer(const Context *context, Command command)
{}

angle::Result State::syncDrawFramebuffer(const Context *context, Command command)
{}

angle::Result State::syncTextures(const Context *context, Command command)
{}

angle::Result State::syncImages(const Context *context, Command command)
{}

angle::Result State::syncSamplers(const Context *context, Command command)
{}

angle::Result State::syncVertexArray(const Context *context, Command command)
{}

angle::Result State::syncProgramPipelineObject(const Context *context, Command command)
{}

angle::Result State::syncDirtyObject(const Context *context, GLenum target)
{}

void State::setObjectDirty(GLenum target)
{}

angle::Result State::installProgramExecutable(const Context *context)
{}

angle::Result State::installProgramPipelineExecutable(const Context *context)
{}

angle::Result State::installProgramPipelineExecutableIfNotAlready(const Context *context)
{}

angle::Result State::onExecutableChange(const Context *context)
{}

void State::setTextureDirty(size_t textureUnitIndex)
{}

void State::setSamplerDirty(size_t samplerIndex)
{}

void State::setImageUnit(const Context *context,
                         size_t unit,
                         Texture *texture,
                         GLint level,
                         GLboolean layered,
                         GLint layer,
                         GLenum access,
                         GLenum format)
{}

void State::setMaxShaderCompilerThreads(GLuint count)
{}

// Handle a dirty texture event.
void State::onActiveTextureChange(const Context *context, size_t textureUnit)
{}

void State::onActiveTextureStateChange(const Context *context, size_t textureUnit)
{}

void State::onImageStateChange(const Context *context, size_t unit)
{}

void State::onUniformBufferStateChange(size_t uniformBufferIndex)
{}

void State::onAtomicCounterBufferStateChange(size_t atomicCounterBufferIndex)
{}

void State::onShaderStorageBufferStateChange(size_t shaderStorageBufferIndex)
{}

void State::initializeForCapture(const Context *context)
{}

}  // namespace gl