Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Unified Diff: src/gpu/gl/GrGLGpu.h

Issue 1870553002: Revert of Track GL buffer state based on unique resource ID (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/gl/GrGLCaps.cpp ('k') | src/gpu/gl/GrGLGpu.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLGpu.h
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index c2dda0a222be2ef16a73b1d8cd4fc1f5c4b6543c..c77076fc51fb6a8d14a675e464c87fb0ce683362 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -32,7 +32,7 @@
#define PROGRAM_CACHE_STATS
#endif
-class GrGLGpu final : public GrGpu {
+class GrGLGpu : public GrGpu {
public:
static GrGpu* Create(GrBackendContext backendContext, const GrContextOptions& options,
GrContext* context);
@@ -73,20 +73,31 @@
// These functions should be used to bind GL objects. They track the GL state and skip redundant
// bindings. Making the equivalent glBind calls directly will confuse the state tracking.
void bindVertexArray(GrGLuint id) {
- fHWVertexArrayState.setVertexArrayID(this, id);
+ fHWGeometryState.setVertexArrayID(this, id);
+ }
+ void bindIndexBufferAndDefaultVertexArray(GrGLuint id) {
+ fHWGeometryState.setIndexBufferIDOnDefaultVertexArray(this, id);
+ }
+ void bindVertexBuffer(GrGLuint id) {
+ fHWGeometryState.setVertexBufferID(this, id);
}
// These callbacks update state tracking when GL objects are deleted. They are called from
// GrGLResource onRelease functions.
void notifyVertexArrayDelete(GrGLuint id) {
- fHWVertexArrayState.notifyVertexArrayDelete(id);
- }
-
- // Binds a buffer to the GL target corresponding to 'type', updates internal state tracking, and
- // returns the GL target the buffer was bound to.
- // When 'type' is kIndex_GrBufferType, this function will also implicitly bind the default VAO.
- // If the caller wishes to bind an index buffer to a specific VAO, it can call glBind directly.
- GrGLenum bindBuffer(GrBufferType type, const GrGLBuffer*);
+ fHWGeometryState.notifyVertexArrayDelete(id);
+ }
+ void notifyVertexBufferDelete(GrGLuint id) {
+ fHWGeometryState.notifyVertexBufferDelete(id);
+ }
+ void notifyIndexBufferDelete(GrGLuint id) {
+ fHWGeometryState.notifyIndexBufferDelete(id);
+ }
+
+ // id and type (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, etc.) of buffer to bind
+ void bindBuffer(GrGLuint id, GrGLenum type);
+
+ void releaseBuffer(GrGLuint id, GrGLenum type);
const GrGLContext* glContextForTesting() const override {
return &this->glContext();
@@ -127,7 +138,7 @@
GrGpuResource::LifeCycle lifeCycle,
const SkTArray<GrMipLevel>& texels) override;
- GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern) override;
+ GrBuffer* onCreateBuffer(GrBufferType, size_t size, GrAccessPattern) override;
GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override;
GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
GrWrapOwnership) override;
@@ -220,7 +231,7 @@
bool hasExtension(const char* ext) const { return fGLContext->hasExtension(ext); }
- bool copySurfaceAsDraw(GrSurface* dst,
+ void copySurfaceAsDraw(GrSurface* dst,
GrSurface* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint);
@@ -233,7 +244,8 @@
const SkIRect& srcRect,
const SkIPoint& dstPoint);
- void stampPLSSetupRect(const SkRect& bounds);
+ void stampRectUsingProgram(GrGLuint program, const SkRect& bounds, GrGLint posXformUniform,
+ GrGLuint arrayBuffer);
void setupPixelLocalStorage(const GrPipeline&, const GrPrimitiveProcessor&);
@@ -361,9 +373,11 @@
SkAutoTUnref<GrGLContext> fGLContext;
- bool createCopyProgram(int progIdx);
- bool createWireRectProgram();
- bool createPLSSetupProgram();
+ void createCopyPrograms();
+ void createWireRectProgram();
+ void createUnitRectBuffer();
+
+ void createPLSSetupProgram();
// GL program-related state
ProgramCache* fProgramCache;
@@ -398,19 +412,22 @@
GrGLIRect fHWViewport;
/**
- * Tracks vertex attrib array state.
+ * Tracks bound vertex and index buffers and vertex attrib array state.
*/
- class HWVertexArrayState {
+ class HWGeometryState {
public:
- HWVertexArrayState() : fCoreProfileVertexArray(nullptr) { this->invalidate(); }
-
- ~HWVertexArrayState() { delete fCoreProfileVertexArray; }
+ HWGeometryState() { fVBOVertexArray = nullptr; this->invalidate(); }
+
+ ~HWGeometryState() { delete fVBOVertexArray; }
void invalidate() {
fBoundVertexArrayIDIsValid = false;
+ fBoundVertexBufferIDIsValid = false;
+ fDefaultVertexArrayBoundIndexBufferID = false;
+ fDefaultVertexArrayBoundIndexBufferIDIsValid = false;
fDefaultVertexArrayAttribState.invalidate();
- if (fCoreProfileVertexArray) {
- fCoreProfileVertexArray->invalidateCachedState();
+ if (fVBOVertexArray) {
+ fVBOVertexArray->invalidateCachedState();
}
}
@@ -433,41 +450,89 @@
}
}
+ void notifyVertexBufferDelete(GrGLuint id) {
+ if (fBoundVertexBufferIDIsValid && id == fBoundVertexBufferID) {
+ fBoundVertexBufferID = 0;
+ }
+ if (fVBOVertexArray) {
+ fVBOVertexArray->notifyVertexBufferDelete(id);
+ }
+ fDefaultVertexArrayAttribState.notifyVertexBufferDelete(id);
+ }
+
+ void notifyIndexBufferDelete(GrGLuint id) {
+ if (fDefaultVertexArrayBoundIndexBufferIDIsValid &&
+ id == fDefaultVertexArrayBoundIndexBufferID) {
+ fDefaultVertexArrayBoundIndexBufferID = 0;
+ }
+ if (fVBOVertexArray) {
+ fVBOVertexArray->notifyIndexBufferDelete(id);
+ }
+ }
+
+ void setVertexBufferID(GrGLGpu* gpu, GrGLuint id) {
+ if (!fBoundVertexBufferIDIsValid || id != fBoundVertexBufferID) {
+ GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ARRAY_BUFFER, id));
+ fBoundVertexBufferIDIsValid = true;
+ fBoundVertexBufferID = id;
+ }
+ }
+
/**
- * Binds the vertex array that should be used for internal draws, and returns its attrib
- * state. This binds the default VAO (ID=zero) unless we are on a core profile, in which
- * case we use a dummy array instead.
- *
- * If an index buffer is privided, it will be bound to the vertex array. Otherwise the
- * index buffer binding will be left unchanged.
- *
- * The returned GrGLAttribArrayState should be used to set vertex attribute arrays.
+ * Binds the default vertex array and binds the index buffer. This is used when binding
+ * an index buffer in order to update it.
*/
- GrGLAttribArrayState* bindInternalVertexArray(GrGLGpu*, const GrGLBuffer* ibuff = nullptr);
+ void setIndexBufferIDOnDefaultVertexArray(GrGLGpu* gpu, GrGLuint id) {
+ this->setVertexArrayID(gpu, 0);
+ if (!fDefaultVertexArrayBoundIndexBufferIDIsValid ||
+ id != fDefaultVertexArrayBoundIndexBufferID) {
+ GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id));
+ fDefaultVertexArrayBoundIndexBufferIDIsValid = true;
+ fDefaultVertexArrayBoundIndexBufferID = id;
+ }
+ }
+
+ /**
+ * Binds the vertex array object that should be used to render from the vertex buffer.
+ * The vertex array is bound and its attrib array state object is returned. The vertex
+ * buffer is bound. The index buffer (if non-nullptr) is bound to the vertex array. The
+ * returned GrGLAttribArrayState should be used to set vertex attribute arrays.
+ */
+ GrGLAttribArrayState* bindArrayAndBuffersToDraw(GrGLGpu* gpu,
+ const GrGLBuffer* vbuffer,
+ const GrGLBuffer* ibuffer);
+
+ /** Variants of the above that takes GL buffer IDs. Note that 0 does not imply that a
+ buffer won't be bound. The "default buffer" will be bound, which is used for client-side
+ array rendering. */
+ GrGLAttribArrayState* bindArrayAndBufferToDraw(GrGLGpu* gpu, GrGLuint vbufferID);
+ GrGLAttribArrayState* bindArrayAndBuffersToDraw(GrGLGpu* gpu,
+ GrGLuint vbufferID,
+ GrGLuint ibufferID);
private:
+ GrGLAttribArrayState* internalBind(GrGLGpu* gpu, GrGLuint vbufferID, GrGLuint* ibufferID);
+
GrGLuint fBoundVertexArrayID;
+ GrGLuint fBoundVertexBufferID;
bool fBoundVertexArrayIDIsValid;
-
+ bool fBoundVertexBufferIDIsValid;
+
+ GrGLuint fDefaultVertexArrayBoundIndexBufferID;
+ bool fDefaultVertexArrayBoundIndexBufferIDIsValid;
// We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0
// is bound. However, this class is internal to GrGLGpu and this object never leaks out of
// GrGLGpu.
GrGLAttribArrayState fDefaultVertexArrayAttribState;
- // This is used when we're using a core profile.
- GrGLVertexArray* fCoreProfileVertexArray;
- } fHWVertexArrayState;
-
- struct {
- GrGLenum fGLTarget;
- uint32_t fBoundBufferUniqueID;
- bool fBufferZeroKnownBound;
-
- void invalidate() {
- fBoundBufferUniqueID = SK_InvalidUniqueID;
- fBufferZeroKnownBound = false;
- }
- } fHWBufferState[kGrBufferTypeCount];
+ // This is used when we're using a core profile and the vertices are in a VBO.
+ GrGLVertexArray* fVBOVertexArray;
+ } fHWGeometryState;
+
+ GrGLuint fHWBoundTextureBufferID;
+ GrGLuint fHWBoundDrawIndirectBufferID;
+ bool fHWBoundTextureBufferIDIsValid;
+ bool fHWBoundDrawIndirectBufferIDIsValid;
struct {
GrBlendEquation fEquation;
@@ -510,14 +575,14 @@
GrGLint fTexCoordXformUniform;
GrGLint fPosXformUniform;
} fCopyPrograms[3];
- SkAutoTUnref<GrGLBuffer> fCopyProgramArrayBuffer;
+ GrGLuint fCopyProgramArrayBuffer;
struct {
GrGLuint fProgram;
GrGLint fColorUniform;
GrGLint fRectUniform;
} fWireRectProgram;
- SkAutoTUnref<GrGLBuffer> fWireRectArrayBuffer;
+ GrGLuint fWireRectArrayBuffer;
static int TextureTargetToCopyProgramIdx(GrGLenum target) {
switch (target) {
@@ -534,9 +599,9 @@
}
struct {
- GrGLuint fProgram;
- GrGLint fPosXformUniform;
- SkAutoTUnref<GrGLBuffer> fArrayBuffer;
+ GrGLuint fProgram;
+ GrGLint fPosXformUniform;
+ GrGLuint fArrayBuffer;
} fPLSSetupProgram;
bool fHWPLSEnabled;
« no previous file with comments | « src/gpu/gl/GrGLCaps.cpp ('k') | src/gpu/gl/GrGLGpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698