diff options
author | jvanverth <jvanverth@google.com> | 2015-07-13 07:19:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-13 07:19:57 -0700 |
commit | 672bb7fc6640e3fc68107354ed4ae45a2a1e2d29 (patch) | |
tree | bc9247fd24909a5dd3c38e2114ba1628126da130 | |
parent | ab9cb427f45cdd51a5f8f6df9c19e955e555fc13 (diff) |
Remove GL-specific code from GMs and tests
TBR=bsalomon@google.com
Review URL: https://codereview.chromium.org/1232173002
-rw-r--r-- | bench/GLBench.cpp | 10 | ||||
-rw-r--r-- | gm/imagefromyuvtextures.cpp | 59 | ||||
-rw-r--r-- | src/gpu/GrGpu.h | 8 | ||||
-rw-r--r-- | src/gpu/GrTest.cpp | 10 | ||||
-rw-r--r-- | src/gpu/GrTest.h | 8 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 40 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.h | 7 | ||||
-rw-r--r-- | tests/ResourceCacheTest.cpp | 33 | ||||
-rw-r--r-- | tests/SurfaceTest.cpp | 34 |
9 files changed, 95 insertions, 114 deletions
diff --git a/bench/GLBench.cpp b/bench/GLBench.cpp index b3bec74f77..0252c26b37 100644 --- a/bench/GLBench.cpp +++ b/bench/GLBench.cpp @@ -17,15 +17,13 @@ const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) { return NULL; } GrContext* context = canvas->getGrContext(); - - GrTestTarget tt; - context->getTestTarget(&tt); - if (!tt.target()) { - SkDebugf("Couldn't get Gr test target."); + GrGpu* gpu = context->getGpu(); + if (!gpu) { + SkDebugf("Couldn't get Gr gpu."); return NULL; } - const GrGLContext* ctx = tt.glContext(); + const GrGLContext* ctx = gpu->glContextForTesting(); if (!ctx) { SkDebugf("Couldn't get an interface\n"); return NULL; diff --git a/gm/imagefromyuvtextures.cpp b/gm/imagefromyuvtextures.cpp index b39a4dceab..dbed06fa21 100644 --- a/gm/imagefromyuvtextures.cpp +++ b/gm/imagefromyuvtextures.cpp @@ -13,8 +13,6 @@ #if SK_SUPPORT_GPU #include "GrContext.h" -#include "gl/GrGLInterface.h" -#include "gl/GrGLUtil.h" #include "GrTest.h" #include "SkBitmap.h" #include "SkGradientShader.h" @@ -96,54 +94,32 @@ protected: fRGBImage.reset(SkImage::NewRasterCopy(rgbBmp.info(), rgbColors, rgbBmp.rowBytes())); } - void createYUVTextures(GrContext* context, GrGLuint yuvIDs[3]) { - GrTestTarget tt; - context->getTestTarget(&tt); - if (!tt.target()) { - SkDEBUGFAIL("Couldn't get Gr test target."); + void createYUVTextures(GrContext* context, GrBackendObject yuvIDs[3]) { + const GrGpu* gpu = context->getGpu(); + if (!gpu) { return; } - // We currently hav only implemented the texture uploads for GL. - const GrGLInterface* gl = tt.glContext()->interface(); - if (!gl) { - return; - } - - GR_GL_CALL(gl, GenTextures(3, yuvIDs)); - GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0)); - GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); for (int i = 0; i < 3; ++i) { - GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, yuvIDs[i])); - GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, - GR_GL_NEAREST)); - GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, - GR_GL_NEAREST)); - GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, - GR_GL_CLAMP_TO_EDGE)); - GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, - GR_GL_CLAMP_TO_EDGE)); SkASSERT(fYUVBmps[i].width() == SkToInt(fYUVBmps[i].rowBytes())); - GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RED, fYUVBmps[i].width(), - fYUVBmps[i].height(), 0, GR_GL_RED, GR_GL_UNSIGNED_BYTE, - fYUVBmps[i].getPixels())); + yuvIDs[i] = gpu->createBackendTexture(fYUVBmps[i].getPixels(), + fYUVBmps[i].width(), fYUVBmps[i].height(), + kAlpha_8_GrPixelConfig); } context->resetContext(); } - void deleteYUVTextures(GrContext* context, const GrGLuint yuvIDs[3]) { - GrTestTarget tt; - context->getTestTarget(&tt); - if (!tt.target()) { - SkDEBUGFAIL("Couldn't get Gr test target."); + void deleteYUVTextures(GrContext* context, const GrBackendObject yuvIDs[3]) { + + const GrGpu* gpu = context->getGpu(); + if (!gpu) { return; } - const GrGLInterface* gl = tt.glContext()->interface(); - if (!gl) { - return; + for (int i = 0; i < 3; ++i) { + gpu->deleteBackendTexture(yuvIDs[i]); } - GR_GL_CALL(gl, DeleteTextures(3, yuvIDs)); + context->resetContext(); } @@ -155,16 +131,11 @@ protected: return; } - GrGLuint yuvIDs[3]; + GrBackendObject yuvIDs[3]; this->createYUVTextures(context, yuvIDs); static const SkScalar kPad = 10.f; - GrBackendObject backendTextureObjects[] = { - static_cast<GrBackendObject>(yuvIDs[0]), - static_cast<GrBackendObject>(yuvIDs[1]), - static_cast<GrBackendObject>(yuvIDs[2]) - }; SkISize sizes[] = { { fYUVBmps[0].width(), fYUVBmps[0].height()}, { fYUVBmps[1].width(), fYUVBmps[1].height()}, @@ -175,7 +146,7 @@ protected: for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) { images.push_back(SkImage::NewFromYUVTexturesCopy(context, static_cast<SkYUVColorSpace>(space), - backendTextureObjects, sizes, + yuvIDs, sizes, kTopLeft_GrSurfaceOrigin)); } this->deleteYUVTextures(context, yuvIDs); diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index 8d449b7606..0ce6bea4e6 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -362,10 +362,16 @@ public: void saveActiveTraceMarkers(); void restoreActiveTraceMarkers(); + // creation and deletion of raw texture for testing + virtual GrBackendObject createBackendTexture(void* pixels, int w, int h, + GrPixelConfig config) const = 0; + virtual bool isBackendTexture(GrBackendObject id) const = 0; + virtual void deleteBackendTexture(GrBackendObject id) const = 0; + // Given a rt, find or create a stencil buffer and attach it bool attachStencilAttachmentToRenderTarget(GrRenderTarget* target); - // This is only to be used in tests. + // This is only to be used in GL-specific tests. virtual const GrGLContext* glContextForTesting() const { return NULL; } protected: diff --git a/src/gpu/GrTest.cpp b/src/gpu/GrTest.cpp index 3e1ef6c3d9..5a3c014413 100644 --- a/src/gpu/GrTest.cpp +++ b/src/gpu/GrTest.cpp @@ -13,12 +13,11 @@ #include "GrResourceCache.h" #include "SkString.h" -void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target, const GrGLContext* gl) { +void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target) { SkASSERT(!fContext); fContext.reset(SkRef(ctx)); fDrawTarget.reset(SkRef(target)); - fGLContext.reset(SkRef(gl)); } void GrContext::getTestTarget(GrTestTarget* tar) { @@ -27,7 +26,7 @@ void GrContext::getTestTarget(GrTestTarget* tar) { // then disconnects. This would help prevent test writers from mixing using the returned // GrDrawTarget and regular drawing. We could also assert or fail in GrContext drawing methods // until ~GrTestTarget(). - tar->init(this, fDrawingMgr.fDrawTarget, fGpu->glContextForTesting()); + tar->init(this, fDrawingMgr.fDrawTarget); } /////////////////////////////////////////////////////////////////////////////// @@ -236,6 +235,11 @@ private: void didRemoveGpuTraceMarker() override {} + GrBackendObject createBackendTexture(void* pixels, int w, int h, + GrPixelConfig config) const override { return 0; } + bool isBackendTexture(GrBackendObject id) const override { return false; } + void deleteBackendTexture(GrBackendObject id) const override {} + typedef GrGpu INHERITED; }; diff --git a/src/gpu/GrTest.h b/src/gpu/GrTest.h index 7e2ffed540..7b0d564c77 100644 --- a/src/gpu/GrTest.h +++ b/src/gpu/GrTest.h @@ -18,19 +18,15 @@ GrContext. In the future this object may provide some guards to prevent this. */ class GrTestTarget { public: - GrTestTarget() : fGLContext(NULL) {}; + GrTestTarget() {}; - void init(GrContext*, GrDrawTarget*, const GrGLContext*); + void init(GrContext*, GrDrawTarget*); GrDrawTarget* target() { return fDrawTarget.get(); } - /** Returns a GrGLContext if the GrContext is backed by OpenGL. */ - const GrGLContext* glContext() { return fGLContext; } - private: SkAutoTUnref<GrDrawTarget> fDrawTarget; SkAutoTUnref<GrContext> fContext; - SkAutoTUnref<const GrGLContext> fGLContext; }; #endif diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 626a72f936..e185ef01a5 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -2379,7 +2379,7 @@ bool GrGLGpu::configToGLFormats(GrPixelConfig config, bool getSizedInternalFormat, GrGLenum* internalFormat, GrGLenum* externalFormat, - GrGLenum* externalType) { + GrGLenum* externalType) const { GrGLenum dontCare; if (NULL == internalFormat) { internalFormat = &dontCare; @@ -3067,6 +3067,44 @@ void GrGLGpu::didRemoveGpuTraceMarker() { } } +GrBackendObject GrGLGpu::createBackendTexture(void* pixels, int w, int h, + GrPixelConfig config) const { + GrGLuint texID; + GL_CALL(GenTextures(1, &texID)); + GL_CALL(ActiveTexture(GR_GL_TEXTURE0)); + GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); + GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texID)); + GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, GR_GL_NEAREST)); + GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST)); + GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, GR_GL_CLAMP_TO_EDGE)); + GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_EDGE)); + + GrGLenum internalFormat = 0x0; // suppress warning + GrGLenum externalFormat = 0x0; // suppress warning + GrGLenum externalType = 0x0; // suppress warning + + this->configToGLFormats(config, false, &internalFormat, &externalFormat, &externalType); + + GL_CALL(TexImage2D(GR_GL_TEXTURE_2D, 0, internalFormat, w, h, 0, externalFormat, + externalType, pixels)); + + return texID; +} + +bool GrGLGpu::isBackendTexture(GrBackendObject id) const { + GrGLuint texID = (GrGLuint)id; + + GrGLboolean result; + GL_CALL_RET(result, IsTexture(texID)); + + return (GR_GL_TRUE == result); +} + +void GrGLGpu::deleteBackendTexture(GrBackendObject id) const { + GrGLuint texID = (GrGLuint)id; + GL_CALL(DeleteTextures(1, &texID)); +} + /////////////////////////////////////////////////////////////////////////////// GrGLAttribArrayState* GrGLGpu::HWGeometryState::bindArrayAndBuffersToDraw( GrGLGpu* gpu, diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index e5cd7a9a9d..368bda1797 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -112,6 +112,11 @@ public: return &this->glContext(); } + GrBackendObject createBackendTexture(void* pixels, int w, int h, + GrPixelConfig config) const override; + bool isBackendTexture(GrBackendObject id) const override; + void deleteBackendTexture(GrBackendObject id) const override; + private: GrGLGpu(GrGLContext* ctx, GrContext* context); @@ -265,7 +270,7 @@ private: bool getSizedInternal, GrGLenum* internalFormat, GrGLenum* externalFormat, - GrGLenum* externalType); + GrGLenum* externalType) const; // helper for onCreateTexture and writeTexturePixels bool uploadTexData(const GrSurfaceDesc& desc, bool isNewTexture, diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 07cd65518e..a870a084ec 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -12,7 +12,6 @@ #include "GrContext.h" #include "GrContextFactory.h" -#include "gl/GrGLInterface.h" #include "GrGpu.h" #include "GrGpuResourceCacheAccess.h" #include "GrGpuResourcePriv.h" @@ -25,8 +24,6 @@ #include "SkMessageBus.h" #include "SkSurface.h" #include "Test.h" -#include "../src/gpu/gl/GrGLDefines.h" -#include "../src/gpu/gl/GrGLUtil.h" static const int gWidth = 640; static const int gHeight = 480; @@ -178,26 +175,18 @@ static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex } static void test_wrapped_resources(skiatest::Reporter* reporter, GrContext* context) { - GrTestTarget tt; - context->getTestTarget(&tt); - - const GrGLInterface* gl = tt.glContext()->interface(); - if (!gl) { + const GrGpu* gpu = context->getGpu(); + if (!gpu) { return; } - GrGLuint texIDs[2]; + GrBackendObject texIDs[2]; static const int kW = 100; static const int kH = 100; - GR_GL_CALL(gl, GenTextures(2, texIDs)); - GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0)); - GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); - GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texIDs[0])); - GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, kW, kH, 0, GR_GL_RGBA, - GR_GL_UNSIGNED_BYTE, NULL)); - GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texIDs[1])); - GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, kW, kH, 0, GR_GL_RGBA, - GR_GL_UNSIGNED_BYTE, NULL)); + + texIDs[0] = gpu->createBackendTexture(NULL, kW, kH, kRGBA_8888_GrPixelConfig); + texIDs[1] = gpu->createBackendTexture(NULL, kW, kH, kRGBA_8888_GrPixelConfig); + context->resetContext(); GrBackendTextureDesc desc; @@ -223,15 +212,13 @@ static void test_wrapped_resources(skiatest::Reporter* reporter, GrContext* cont context->flush(); - GrGLboolean borrowedIsAlive; - GrGLboolean adoptedIsAlive; - GR_GL_CALL_RET(gl, borrowedIsAlive, IsTexture(texIDs[0])); - GR_GL_CALL_RET(gl, adoptedIsAlive, IsTexture(texIDs[1])); + bool borrowedIsAlive = gpu->isBackendTexture(texIDs[0]); + bool adoptedIsAlive = gpu->isBackendTexture(texIDs[1]); REPORTER_ASSERT(reporter, borrowedIsAlive); REPORTER_ASSERT(reporter, !adoptedIsAlive); - GR_GL_CALL(gl, GenTextures(1, &texIDs[0])); + gpu->deleteBackendTexture(texIDs[0]); context->resetContext(); } diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 57ad5e0ca8..7e1b3c90c5 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -18,8 +18,6 @@ #if SK_SUPPORT_GPU #include "GrContextFactory.h" #include "GrTest.h" -#include "gl/GrGLInterface.h" -#include "gl/GrGLUtil.h" #else class GrContextFactory; class GrContext; @@ -107,42 +105,20 @@ static void test_wrapped_texture_surface(skiatest::Reporter* reporter, GrContext return; } - GrTestTarget tt; - ctx->getTestTarget(&tt); - if (!tt.target()) { - SkDEBUGFAIL("Couldn't get Gr test target."); + const GrGpu* gpu = ctx->getGpu(); + if (!gpu) { return; } - // We currently have only implemented the texture uploads for GL. - const GrGLInterface* gl = tt.glContext()->interface(); - if (!gl) { - return; - } - - // Test the wrapped factory for SkSurface by creating a texture using GL and then wrap it in + // Test the wrapped factory for SkSurface by creating a backend texture and then wrap it in // a SkSurface. - GrGLuint texID; static const int kW = 100; static const int kH = 100; static const uint32_t kOrigColor = 0xFFAABBCC; SkAutoTArray<uint32_t> pixels(kW * kH); sk_memset32(pixels.get(), kOrigColor, kW * kH); - GR_GL_CALL(gl, GenTextures(1, &texID)); - GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0)); - GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); - GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texID)); - GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, - GR_GL_NEAREST)); - GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, - GR_GL_NEAREST)); - GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, - GR_GL_CLAMP_TO_EDGE)); - GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, - GR_GL_CLAMP_TO_EDGE)); - GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, kW, kH, 0, GR_GL_RGBA, - GR_GL_UNSIGNED_BYTE, - pixels.get())); + GrBackendObject texID = gpu->createBackendTexture(pixels.get(), kW, kH, + kRGBA_8888_GrPixelConfig); GrBackendTextureDesc wrappedDesc; wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; |