Index: tools/gpu/gl/debug/DebugGLContext.cpp |
diff --git a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp b/tools/gpu/gl/debug/DebugGLContext.cpp |
similarity index 76% |
rename from src/gpu/gl/debug/GrGLCreateDebugInterface.cpp |
rename to tools/gpu/gl/debug/DebugGLContext.cpp |
index 02b5cf704d8f19e9aa49747a4bc86f48f9adf0ef..f4cbbea6802f83606aa376da8319c2f838adf058 100644 |
--- a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp |
+++ b/tools/gpu/gl/debug/DebugGLContext.cpp |
@@ -1,3 +1,4 @@ |
+ |
/* |
* Copyright 2012 Google Inc. |
* |
@@ -5,8 +6,7 @@ |
* found in the LICENSE file. |
*/ |
- |
-#include "gl/GrGLInterface.h" |
+#include "DebugGLContext.h" |
#include "GrBufferObj.h" |
#include "GrFrameBufferObj.h" |
@@ -217,254 +217,254 @@ public: |
} |
} |
- GrGLvoid useProgram(GrGLuint programID) override { |
+ GrGLvoid useProgram(GrGLuint programID) override { |
- // A programID of 0 is legal |
- GrProgramObj *program = FIND(programID, GrProgramObj, kProgram_ObjTypes); |
+ // A programID of 0 is legal |
+ GrProgramObj *program = FIND(programID, GrProgramObj, kProgram_ObjTypes); |
- this->useProgram(program); |
- } |
+ this->useProgram(program); |
+ } |
- GrGLvoid bindFramebuffer(GrGLenum target, GrGLuint frameBufferID) override { |
+ GrGLvoid bindFramebuffer(GrGLenum target, GrGLuint frameBufferID) override { |
- GrAlwaysAssert(GR_GL_FRAMEBUFFER == target || |
- GR_GL_READ_FRAMEBUFFER == target || |
- GR_GL_DRAW_FRAMEBUFFER); |
+ GrAlwaysAssert(GR_GL_FRAMEBUFFER == target || |
+ GR_GL_READ_FRAMEBUFFER == target || |
+ GR_GL_DRAW_FRAMEBUFFER); |
- // a frameBufferID of 0 is acceptable - it binds to the default |
- // frame buffer |
- GrFrameBufferObj *frameBuffer = FIND(frameBufferID, GrFrameBufferObj, |
- kFrameBuffer_ObjTypes); |
+ // a frameBufferID of 0 is acceptable - it binds to the default |
+ // frame buffer |
+ GrFrameBufferObj *frameBuffer = FIND(frameBufferID, GrFrameBufferObj, |
+ kFrameBuffer_ObjTypes); |
- this->setFrameBuffer(frameBuffer); |
- } |
+ this->setFrameBuffer(frameBuffer); |
+ } |
- GrGLvoid bindRenderbuffer(GrGLenum target, GrGLuint renderBufferID) override { |
+ GrGLvoid bindRenderbuffer(GrGLenum target, GrGLuint renderBufferID) override { |
- GrAlwaysAssert(GR_GL_RENDERBUFFER == target); |
+ GrAlwaysAssert(GR_GL_RENDERBUFFER == target); |
- // a renderBufferID of 0 is acceptable - it unbinds the bound render buffer |
- GrRenderBufferObj *renderBuffer = FIND(renderBufferID, GrRenderBufferObj, |
- kRenderBuffer_ObjTypes); |
+ // a renderBufferID of 0 is acceptable - it unbinds the bound render buffer |
+ GrRenderBufferObj *renderBuffer = FIND(renderBufferID, GrRenderBufferObj, |
+ kRenderBuffer_ObjTypes); |
- this->setRenderBuffer(renderBuffer); |
- } |
+ this->setRenderBuffer(renderBuffer); |
+ } |
- GrGLvoid deleteTextures(GrGLsizei n, const GrGLuint* textures) override { |
- // first potentially unbind the texture |
- for (unsigned int i = 0; i < kDefaultMaxTextureUnits; ++i) { |
- GrTextureUnitObj *pTU = this->getTextureUnit(i); |
+ GrGLvoid deleteTextures(GrGLsizei n, const GrGLuint* textures) override { |
+ // first potentially unbind the texture |
+ for (unsigned int i = 0; i < kDefaultMaxTextureUnits; ++i) { |
+ GrTextureUnitObj *pTU = this->getTextureUnit(i); |
- if (pTU->getTexture()) { |
- for (int j = 0; j < n; ++j) { |
+ if (pTU->getTexture()) { |
+ for (int j = 0; j < n; ++j) { |
- if (textures[j] == pTU->getTexture()->getID()) { |
- // this ID is the current texture - revert the binding to 0 |
- pTU->setTexture(nullptr); |
- } |
- } |
- } |
- } |
+ if (textures[j] == pTU->getTexture()->getID()) { |
+ // this ID is the current texture - revert the binding to 0 |
+ pTU->setTexture(nullptr); |
+ } |
+ } |
+ } |
+ } |
- // TODO: fuse the following block with DeleteRenderBuffers? |
- // Open GL will remove a deleted render buffer from the active |
- // frame buffer but not from any other frame buffer |
- if (this->getFrameBuffer()) { |
+ // TODO: fuse the following block with DeleteRenderBuffers? |
+ // Open GL will remove a deleted render buffer from the active |
+ // frame buffer but not from any other frame buffer |
+ if (this->getFrameBuffer()) { |
- GrFrameBufferObj *frameBuffer = this->getFrameBuffer(); |
+ GrFrameBufferObj *frameBuffer = this->getFrameBuffer(); |
- for (int i = 0; i < n; ++i) { |
+ for (int i = 0; i < n; ++i) { |
- if (frameBuffer->getColor() && |
- textures[i] == frameBuffer->getColor()->getID()) { |
- frameBuffer->setColor(nullptr); |
- } |
- if (frameBuffer->getDepth() && |
- textures[i] == frameBuffer->getDepth()->getID()) { |
- frameBuffer->setDepth(nullptr); |
- } |
- if (frameBuffer->getStencil() && |
- textures[i] == frameBuffer->getStencil()->getID()) { |
- frameBuffer->setStencil(nullptr); |
- } |
- } |
- } |
+ if (frameBuffer->getColor() && |
+ textures[i] == frameBuffer->getColor()->getID()) { |
+ frameBuffer->setColor(nullptr); |
+ } |
+ if (frameBuffer->getDepth() && |
+ textures[i] == frameBuffer->getDepth()->getID()) { |
+ frameBuffer->setDepth(nullptr); |
+ } |
+ if (frameBuffer->getStencil() && |
+ textures[i] == frameBuffer->getStencil()->getID()) { |
+ frameBuffer->setStencil(nullptr); |
+ } |
+ } |
+ } |
- // then actually "delete" the buffers |
- for (int i = 0; i < n; ++i) { |
- GrTextureObj *buffer = FIND(textures[i], GrTextureObj, kTexture_ObjTypes); |
- GrAlwaysAssert(buffer); |
+ // then actually "delete" the buffers |
+ for (int i = 0; i < n; ++i) { |
+ GrTextureObj *buffer = FIND(textures[i], GrTextureObj, kTexture_ObjTypes); |
+ GrAlwaysAssert(buffer); |
- // OpenGL gives no guarantees if a texture is deleted while attached to |
- // something other than the currently bound frame buffer |
- GrAlwaysAssert(!buffer->getBound()); |
+ // OpenGL gives no guarantees if a texture is deleted while attached to |
+ // something other than the currently bound frame buffer |
+ GrAlwaysAssert(!buffer->getBound()); |
- GrAlwaysAssert(!buffer->getDeleted()); |
- buffer->deleteAction(); |
- } |
+ GrAlwaysAssert(!buffer->getDeleted()); |
+ buffer->deleteAction(); |
+ } |
- } |
+ } |
- GrGLvoid deleteFramebuffers(GrGLsizei n, const GrGLuint *frameBuffers) override { |
+ GrGLvoid deleteFramebuffers(GrGLsizei n, const GrGLuint *frameBuffers) override { |
- // first potentially unbind the buffers |
- if (this->getFrameBuffer()) { |
- for (int i = 0; i < n; ++i) { |
+ // first potentially unbind the buffers |
+ if (this->getFrameBuffer()) { |
+ for (int i = 0; i < n; ++i) { |
- if (frameBuffers[i] == |
- this->getFrameBuffer()->getID()) { |
- // this ID is the current frame buffer - rebind to the default |
- this->setFrameBuffer(nullptr); |
- } |
- } |
- } |
- |
- // then actually "delete" the buffers |
- for (int i = 0; i < n; ++i) { |
- GrFrameBufferObj *buffer = FIND(frameBuffers[i], GrFrameBufferObj, |
- kFrameBuffer_ObjTypes); |
- GrAlwaysAssert(buffer); |
- |
- GrAlwaysAssert(!buffer->getDeleted()); |
- buffer->deleteAction(); |
- } |
- } |
- |
- GrGLvoid deleteRenderbuffers(GrGLsizei n,const GrGLuint *renderBuffers) override { |
- |
- // first potentially unbind the buffers |
- if (this->getRenderBuffer()) { |
- for (int i = 0; i < n; ++i) { |
- |
- if (renderBuffers[i] == |
- this->getRenderBuffer()->getID()) { |
- // this ID is the current render buffer - make no |
- // render buffer be bound |
- this->setRenderBuffer(nullptr); |
- } |
- } |
- } |
- |
- // TODO: fuse the following block with DeleteTextures? |
- // Open GL will remove a deleted render buffer from the active frame |
- // buffer but not from any other frame buffer |
- if (this->getFrameBuffer()) { |
- |
- GrFrameBufferObj *frameBuffer = this->getFrameBuffer(); |
- |
- for (int i = 0; i < n; ++i) { |
- |
- if (frameBuffer->getColor() && |
- renderBuffers[i] == frameBuffer->getColor()->getID()) { |
- frameBuffer->setColor(nullptr); |
- } |
- if (frameBuffer->getDepth() && |
- renderBuffers[i] == frameBuffer->getDepth()->getID()) { |
- frameBuffer->setDepth(nullptr); |
- } |
- if (frameBuffer->getStencil() && |
- renderBuffers[i] == frameBuffer->getStencil()->getID()) { |
- frameBuffer->setStencil(nullptr); |
- } |
- } |
- } |
- |
- // then actually "delete" the buffers |
- for (int i = 0; i < n; ++i) { |
- GrRenderBufferObj *buffer = FIND(renderBuffers[i], GrRenderBufferObj, |
- kRenderBuffer_ObjTypes); |
- GrAlwaysAssert(buffer); |
- |
- // OpenGL gives no guarantees if a render buffer is deleted |
- // while attached to something other than the currently |
- // bound frame buffer |
- GrAlwaysAssert(!buffer->getColorBound()); |
- GrAlwaysAssert(!buffer->getDepthBound()); |
- // However, at GrContext destroy time we release all GrRsources and so stencil buffers |
- // may get deleted before FBOs that refer to them. |
- //GrAlwaysAssert(!buffer->getStencilBound()); |
- |
- GrAlwaysAssert(!buffer->getDeleted()); |
- buffer->deleteAction(); |
- } |
- } |
- |
- GrGLvoid framebufferRenderbuffer(GrGLenum target, |
- GrGLenum attachment, |
- GrGLenum renderbuffertarget, |
- GrGLuint renderBufferID) override { |
- |
- GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); |
- GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment || |
- GR_GL_DEPTH_ATTACHMENT == attachment || |
- GR_GL_STENCIL_ATTACHMENT == attachment); |
- GrAlwaysAssert(GR_GL_RENDERBUFFER == renderbuffertarget); |
- |
- GrFrameBufferObj *framebuffer = this->getFrameBuffer(); |
- // A render buffer cannot be attached to the default framebuffer |
- GrAlwaysAssert(framebuffer); |
- |
- // a renderBufferID of 0 is acceptable - it unbinds the current |
- // render buffer |
- GrRenderBufferObj *renderbuffer = FIND(renderBufferID, GrRenderBufferObj, |
- kRenderBuffer_ObjTypes); |
- |
- switch (attachment) { |
- case GR_GL_COLOR_ATTACHMENT0: |
- framebuffer->setColor(renderbuffer); |
- break; |
- case GR_GL_DEPTH_ATTACHMENT: |
- framebuffer->setDepth(renderbuffer); |
- break; |
- case GR_GL_STENCIL_ATTACHMENT: |
- framebuffer->setStencil(renderbuffer); |
- break; |
- default: |
- GrAlwaysAssert(false); |
- break; |
- }; |
- |
- } |
- |
- //////////////////////////////////////////////////////////////////////////////// |
- GrGLvoid framebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget, |
- GrGLuint textureID, GrGLint level) override { |
- |
- GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); |
- GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment || |
- GR_GL_DEPTH_ATTACHMENT == attachment || |
- GR_GL_STENCIL_ATTACHMENT == attachment); |
- GrAlwaysAssert(GR_GL_TEXTURE_2D == textarget); |
- |
- GrFrameBufferObj *framebuffer = this->getFrameBuffer(); |
- // A texture cannot be attached to the default framebuffer |
- GrAlwaysAssert(framebuffer); |
- |
- // A textureID of 0 is allowed - it unbinds the currently bound texture |
- GrTextureObj *texture = FIND(textureID, GrTextureObj, kTexture_ObjTypes); |
- if (texture) { |
- // The texture shouldn't be bound to a texture unit - this |
- // could lead to a feedback loop |
- GrAlwaysAssert(!texture->getBound()); |
- } |
- |
- GrAlwaysAssert(0 == level); |
- |
- switch (attachment) { |
- case GR_GL_COLOR_ATTACHMENT0: |
- framebuffer->setColor(texture); |
- break; |
- case GR_GL_DEPTH_ATTACHMENT: |
- framebuffer->setDepth(texture); |
- break; |
- case GR_GL_STENCIL_ATTACHMENT: |
- framebuffer->setStencil(texture); |
- break; |
- default: |
- GrAlwaysAssert(false); |
- break; |
- }; |
- } |
+ if (frameBuffers[i] == |
+ this->getFrameBuffer()->getID()) { |
+ // this ID is the current frame buffer - rebind to the default |
+ this->setFrameBuffer(nullptr); |
+ } |
+ } |
+ } |
+ |
+ // then actually "delete" the buffers |
+ for (int i = 0; i < n; ++i) { |
+ GrFrameBufferObj *buffer = FIND(frameBuffers[i], GrFrameBufferObj, |
+ kFrameBuffer_ObjTypes); |
+ GrAlwaysAssert(buffer); |
+ |
+ GrAlwaysAssert(!buffer->getDeleted()); |
+ buffer->deleteAction(); |
+ } |
+ } |
+ |
+ GrGLvoid deleteRenderbuffers(GrGLsizei n,const GrGLuint *renderBuffers) override { |
+ |
+ // first potentially unbind the buffers |
+ if (this->getRenderBuffer()) { |
+ for (int i = 0; i < n; ++i) { |
+ |
+ if (renderBuffers[i] == |
+ this->getRenderBuffer()->getID()) { |
+ // this ID is the current render buffer - make no |
+ // render buffer be bound |
+ this->setRenderBuffer(nullptr); |
+ } |
+ } |
+ } |
+ |
+ // TODO: fuse the following block with DeleteTextures? |
+ // Open GL will remove a deleted render buffer from the active frame |
+ // buffer but not from any other frame buffer |
+ if (this->getFrameBuffer()) { |
+ |
+ GrFrameBufferObj *frameBuffer = this->getFrameBuffer(); |
+ |
+ for (int i = 0; i < n; ++i) { |
+ |
+ if (frameBuffer->getColor() && |
+ renderBuffers[i] == frameBuffer->getColor()->getID()) { |
+ frameBuffer->setColor(nullptr); |
+ } |
+ if (frameBuffer->getDepth() && |
+ renderBuffers[i] == frameBuffer->getDepth()->getID()) { |
+ frameBuffer->setDepth(nullptr); |
+ } |
+ if (frameBuffer->getStencil() && |
+ renderBuffers[i] == frameBuffer->getStencil()->getID()) { |
+ frameBuffer->setStencil(nullptr); |
+ } |
+ } |
+ } |
+ |
+ // then actually "delete" the buffers |
+ for (int i = 0; i < n; ++i) { |
+ GrRenderBufferObj *buffer = FIND(renderBuffers[i], GrRenderBufferObj, |
+ kRenderBuffer_ObjTypes); |
+ GrAlwaysAssert(buffer); |
+ |
+ // OpenGL gives no guarantees if a render buffer is deleted |
+ // while attached to something other than the currently |
+ // bound frame buffer |
+ GrAlwaysAssert(!buffer->getColorBound()); |
+ GrAlwaysAssert(!buffer->getDepthBound()); |
+ // However, at GrContext destroy time we release all GrRsources and so stencil buffers |
+ // may get deleted before FBOs that refer to them. |
+ //GrAlwaysAssert(!buffer->getStencilBound()); |
+ |
+ GrAlwaysAssert(!buffer->getDeleted()); |
+ buffer->deleteAction(); |
+ } |
+ } |
+ |
+ GrGLvoid framebufferRenderbuffer(GrGLenum target, |
+ GrGLenum attachment, |
+ GrGLenum renderbuffertarget, |
+ GrGLuint renderBufferID) override { |
+ |
+ GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); |
+ GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment || |
+ GR_GL_DEPTH_ATTACHMENT == attachment || |
+ GR_GL_STENCIL_ATTACHMENT == attachment); |
+ GrAlwaysAssert(GR_GL_RENDERBUFFER == renderbuffertarget); |
+ |
+ GrFrameBufferObj *framebuffer = this->getFrameBuffer(); |
+ // A render buffer cannot be attached to the default framebuffer |
+ GrAlwaysAssert(framebuffer); |
+ |
+ // a renderBufferID of 0 is acceptable - it unbinds the current |
+ // render buffer |
+ GrRenderBufferObj *renderbuffer = FIND(renderBufferID, GrRenderBufferObj, |
+ kRenderBuffer_ObjTypes); |
+ |
+ switch (attachment) { |
+ case GR_GL_COLOR_ATTACHMENT0: |
+ framebuffer->setColor(renderbuffer); |
+ break; |
+ case GR_GL_DEPTH_ATTACHMENT: |
+ framebuffer->setDepth(renderbuffer); |
+ break; |
+ case GR_GL_STENCIL_ATTACHMENT: |
+ framebuffer->setStencil(renderbuffer); |
+ break; |
+ default: |
+ GrAlwaysAssert(false); |
+ break; |
+ }; |
+ |
+ } |
+ |
+ //////////////////////////////////////////////////////////////////////////////// |
+ GrGLvoid framebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget, |
+ GrGLuint textureID, GrGLint level) override { |
+ |
+ GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); |
+ GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment || |
+ GR_GL_DEPTH_ATTACHMENT == attachment || |
+ GR_GL_STENCIL_ATTACHMENT == attachment); |
+ GrAlwaysAssert(GR_GL_TEXTURE_2D == textarget); |
+ |
+ GrFrameBufferObj *framebuffer = this->getFrameBuffer(); |
+ // A texture cannot be attached to the default framebuffer |
+ GrAlwaysAssert(framebuffer); |
+ |
+ // A textureID of 0 is allowed - it unbinds the currently bound texture |
+ GrTextureObj *texture = FIND(textureID, GrTextureObj, kTexture_ObjTypes); |
+ if (texture) { |
+ // The texture shouldn't be bound to a texture unit - this |
+ // could lead to a feedback loop |
+ GrAlwaysAssert(!texture->getBound()); |
+ } |
+ |
+ GrAlwaysAssert(0 == level); |
+ |
+ switch (attachment) { |
+ case GR_GL_COLOR_ATTACHMENT0: |
+ framebuffer->setColor(texture); |
+ break; |
+ case GR_GL_DEPTH_ATTACHMENT: |
+ framebuffer->setDepth(texture); |
+ break; |
+ case GR_GL_STENCIL_ATTACHMENT: |
+ framebuffer->setStencil(texture); |
+ break; |
+ default: |
+ GrAlwaysAssert(false); |
+ break; |
+ }; |
+ } |
GrGLuint createProgram() override { |
@@ -1229,8 +1229,28 @@ const char* DebugInterface::kExtensions[] = { |
nullptr, // signifies the end of the array. |
}; |
-} // anonymous namespace |
+class DebugGLContext : public sk_gpu_test::GLContext { |
+public: |
+ DebugGLContext() { |
+ this->init(new DebugInterface()); |
+ } |
-//////////////////////////////////////////////////////////////////////////////// |
+ ~DebugGLContext() override { this->teardown(); } |
-const GrGLInterface* GrGLCreateDebugInterface() { return new DebugInterface; } |
+private: |
+ void onPlatformMakeCurrent() const override {} |
+ void onPlatformSwapBuffers() const override {} |
+ GrGLFuncPtr onPlatformGetProcAddress(const char*) const override { return nullptr; } |
+}; |
+} // anonymous namespace |
+ |
+namespace sk_gpu_test { |
+GLContext* CreateDebugGLContext() { |
+ GLContext* ctx = new DebugGLContext(); |
+ if (ctx->isValid()) { |
+ return ctx; |
+ } |
+ delete ctx; |
+ return nullptr; |
+} |
+} |