Remove GL-specific code from GMs and tests

TBR=bsalomon@google.com

Review URL: https://codereview.chromium.org/1232173002
This commit is contained in:
jvanverth 2015-07-13 07:19:57 -07:00 committed by Commit bot
parent ab9cb427f4
commit 672bb7fc66
9 changed files with 95 additions and 114 deletions

View File

@ -17,15 +17,13 @@ const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) {
return NULL; return NULL;
} }
GrContext* context = canvas->getGrContext(); GrContext* context = canvas->getGrContext();
GrGpu* gpu = context->getGpu();
GrTestTarget tt; if (!gpu) {
context->getTestTarget(&tt); SkDebugf("Couldn't get Gr gpu.");
if (!tt.target()) {
SkDebugf("Couldn't get Gr test target.");
return NULL; return NULL;
} }
const GrGLContext* ctx = tt.glContext(); const GrGLContext* ctx = gpu->glContextForTesting();
if (!ctx) { if (!ctx) {
SkDebugf("Couldn't get an interface\n"); SkDebugf("Couldn't get an interface\n");
return NULL; return NULL;

View File

@ -13,8 +13,6 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "gl/GrGLInterface.h"
#include "gl/GrGLUtil.h"
#include "GrTest.h" #include "GrTest.h"
#include "SkBitmap.h" #include "SkBitmap.h"
#include "SkGradientShader.h" #include "SkGradientShader.h"
@ -96,54 +94,32 @@ protected:
fRGBImage.reset(SkImage::NewRasterCopy(rgbBmp.info(), rgbColors, rgbBmp.rowBytes())); fRGBImage.reset(SkImage::NewRasterCopy(rgbBmp.info(), rgbColors, rgbBmp.rowBytes()));
} }
void createYUVTextures(GrContext* context, GrGLuint yuvIDs[3]) { void createYUVTextures(GrContext* context, GrBackendObject yuvIDs[3]) {
GrTestTarget tt; const GrGpu* gpu = context->getGpu();
context->getTestTarget(&tt); if (!gpu) {
if (!tt.target()) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return; 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) { 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())); SkASSERT(fYUVBmps[i].width() == SkToInt(fYUVBmps[i].rowBytes()));
GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RED, fYUVBmps[i].width(), yuvIDs[i] = gpu->createBackendTexture(fYUVBmps[i].getPixels(),
fYUVBmps[i].height(), 0, GR_GL_RED, GR_GL_UNSIGNED_BYTE, fYUVBmps[i].width(), fYUVBmps[i].height(),
fYUVBmps[i].getPixels())); kAlpha_8_GrPixelConfig);
} }
context->resetContext(); context->resetContext();
} }
void deleteYUVTextures(GrContext* context, const GrGLuint yuvIDs[3]) { void deleteYUVTextures(GrContext* context, const GrBackendObject yuvIDs[3]) {
GrTestTarget tt;
context->getTestTarget(&tt); const GrGpu* gpu = context->getGpu();
if (!tt.target()) { if (!gpu) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return; return;
} }
const GrGLInterface* gl = tt.glContext()->interface(); for (int i = 0; i < 3; ++i) {
if (!gl) { gpu->deleteBackendTexture(yuvIDs[i]);
return;
} }
GR_GL_CALL(gl, DeleteTextures(3, yuvIDs));
context->resetContext(); context->resetContext();
} }
@ -155,16 +131,11 @@ protected:
return; return;
} }
GrGLuint yuvIDs[3]; GrBackendObject yuvIDs[3];
this->createYUVTextures(context, yuvIDs); this->createYUVTextures(context, yuvIDs);
static const SkScalar kPad = 10.f; 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[] = { SkISize sizes[] = {
{ fYUVBmps[0].width(), fYUVBmps[0].height()}, { fYUVBmps[0].width(), fYUVBmps[0].height()},
{ fYUVBmps[1].width(), fYUVBmps[1].height()}, { fYUVBmps[1].width(), fYUVBmps[1].height()},
@ -175,7 +146,7 @@ protected:
for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) { for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) {
images.push_back(SkImage::NewFromYUVTexturesCopy(context, images.push_back(SkImage::NewFromYUVTexturesCopy(context,
static_cast<SkYUVColorSpace>(space), static_cast<SkYUVColorSpace>(space),
backendTextureObjects, sizes, yuvIDs, sizes,
kTopLeft_GrSurfaceOrigin)); kTopLeft_GrSurfaceOrigin));
} }
this->deleteYUVTextures(context, yuvIDs); this->deleteYUVTextures(context, yuvIDs);

View File

@ -362,10 +362,16 @@ public:
void saveActiveTraceMarkers(); void saveActiveTraceMarkers();
void restoreActiveTraceMarkers(); 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 // Given a rt, find or create a stencil buffer and attach it
bool attachStencilAttachmentToRenderTarget(GrRenderTarget* target); 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; } virtual const GrGLContext* glContextForTesting() const { return NULL; }
protected: protected:

View File

@ -13,12 +13,11 @@
#include "GrResourceCache.h" #include "GrResourceCache.h"
#include "SkString.h" #include "SkString.h"
void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target, const GrGLContext* gl) { void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target) {
SkASSERT(!fContext); SkASSERT(!fContext);
fContext.reset(SkRef(ctx)); fContext.reset(SkRef(ctx));
fDrawTarget.reset(SkRef(target)); fDrawTarget.reset(SkRef(target));
fGLContext.reset(SkRef(gl));
} }
void GrContext::getTestTarget(GrTestTarget* tar) { 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 // 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 // GrDrawTarget and regular drawing. We could also assert or fail in GrContext drawing methods
// until ~GrTestTarget(). // until ~GrTestTarget().
tar->init(this, fDrawingMgr.fDrawTarget, fGpu->glContextForTesting()); tar->init(this, fDrawingMgr.fDrawTarget);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -236,6 +235,11 @@ private:
void didRemoveGpuTraceMarker() override {} 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; typedef GrGpu INHERITED;
}; };

View File

@ -18,19 +18,15 @@
GrContext. In the future this object may provide some guards to prevent this. */ GrContext. In the future this object may provide some guards to prevent this. */
class GrTestTarget { class GrTestTarget {
public: public:
GrTestTarget() : fGLContext(NULL) {}; GrTestTarget() {};
void init(GrContext*, GrDrawTarget*, const GrGLContext*); void init(GrContext*, GrDrawTarget*);
GrDrawTarget* target() { return fDrawTarget.get(); } GrDrawTarget* target() { return fDrawTarget.get(); }
/** Returns a GrGLContext if the GrContext is backed by OpenGL. */
const GrGLContext* glContext() { return fGLContext; }
private: private:
SkAutoTUnref<GrDrawTarget> fDrawTarget; SkAutoTUnref<GrDrawTarget> fDrawTarget;
SkAutoTUnref<GrContext> fContext; SkAutoTUnref<GrContext> fContext;
SkAutoTUnref<const GrGLContext> fGLContext;
}; };
#endif #endif

View File

@ -2379,7 +2379,7 @@ bool GrGLGpu::configToGLFormats(GrPixelConfig config,
bool getSizedInternalFormat, bool getSizedInternalFormat,
GrGLenum* internalFormat, GrGLenum* internalFormat,
GrGLenum* externalFormat, GrGLenum* externalFormat,
GrGLenum* externalType) { GrGLenum* externalType) const {
GrGLenum dontCare; GrGLenum dontCare;
if (NULL == internalFormat) { if (NULL == internalFormat) {
internalFormat = &dontCare; 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( GrGLAttribArrayState* GrGLGpu::HWGeometryState::bindArrayAndBuffersToDraw(
GrGLGpu* gpu, GrGLGpu* gpu,

View File

@ -112,6 +112,11 @@ public:
return &this->glContext(); 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: private:
GrGLGpu(GrGLContext* ctx, GrContext* context); GrGLGpu(GrGLContext* ctx, GrContext* context);
@ -265,7 +270,7 @@ private:
bool getSizedInternal, bool getSizedInternal,
GrGLenum* internalFormat, GrGLenum* internalFormat,
GrGLenum* externalFormat, GrGLenum* externalFormat,
GrGLenum* externalType); GrGLenum* externalType) const;
// helper for onCreateTexture and writeTexturePixels // helper for onCreateTexture and writeTexturePixels
bool uploadTexData(const GrSurfaceDesc& desc, bool uploadTexData(const GrSurfaceDesc& desc,
bool isNewTexture, bool isNewTexture,

View File

@ -12,7 +12,6 @@
#include "GrContext.h" #include "GrContext.h"
#include "GrContextFactory.h" #include "GrContextFactory.h"
#include "gl/GrGLInterface.h"
#include "GrGpu.h" #include "GrGpu.h"
#include "GrGpuResourceCacheAccess.h" #include "GrGpuResourceCacheAccess.h"
#include "GrGpuResourcePriv.h" #include "GrGpuResourcePriv.h"
@ -25,8 +24,6 @@
#include "SkMessageBus.h" #include "SkMessageBus.h"
#include "SkSurface.h" #include "SkSurface.h"
#include "Test.h" #include "Test.h"
#include "../src/gpu/gl/GrGLDefines.h"
#include "../src/gpu/gl/GrGLUtil.h"
static const int gWidth = 640; static const int gWidth = 640;
static const int gHeight = 480; 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) { static void test_wrapped_resources(skiatest::Reporter* reporter, GrContext* context) {
GrTestTarget tt; const GrGpu* gpu = context->getGpu();
context->getTestTarget(&tt); if (!gpu) {
const GrGLInterface* gl = tt.glContext()->interface();
if (!gl) {
return; return;
} }
GrGLuint texIDs[2]; GrBackendObject texIDs[2];
static const int kW = 100; static const int kW = 100;
static const int kH = 100; static const int kH = 100;
GR_GL_CALL(gl, GenTextures(2, texIDs));
GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0)); texIDs[0] = gpu->createBackendTexture(NULL, kW, kH, kRGBA_8888_GrPixelConfig);
GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); texIDs[1] = gpu->createBackendTexture(NULL, kW, kH, kRGBA_8888_GrPixelConfig);
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));
context->resetContext(); context->resetContext();
GrBackendTextureDesc desc; GrBackendTextureDesc desc;
@ -223,15 +212,13 @@ static void test_wrapped_resources(skiatest::Reporter* reporter, GrContext* cont
context->flush(); context->flush();
GrGLboolean borrowedIsAlive; bool borrowedIsAlive = gpu->isBackendTexture(texIDs[0]);
GrGLboolean adoptedIsAlive; bool adoptedIsAlive = gpu->isBackendTexture(texIDs[1]);
GR_GL_CALL_RET(gl, borrowedIsAlive, IsTexture(texIDs[0]));
GR_GL_CALL_RET(gl, adoptedIsAlive, IsTexture(texIDs[1]));
REPORTER_ASSERT(reporter, borrowedIsAlive); REPORTER_ASSERT(reporter, borrowedIsAlive);
REPORTER_ASSERT(reporter, !adoptedIsAlive); REPORTER_ASSERT(reporter, !adoptedIsAlive);
GR_GL_CALL(gl, GenTextures(1, &texIDs[0])); gpu->deleteBackendTexture(texIDs[0]);
context->resetContext(); context->resetContext();
} }

View File

@ -18,8 +18,6 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContextFactory.h" #include "GrContextFactory.h"
#include "GrTest.h" #include "GrTest.h"
#include "gl/GrGLInterface.h"
#include "gl/GrGLUtil.h"
#else #else
class GrContextFactory; class GrContextFactory;
class GrContext; class GrContext;
@ -107,42 +105,20 @@ static void test_wrapped_texture_surface(skiatest::Reporter* reporter, GrContext
return; return;
} }
GrTestTarget tt; const GrGpu* gpu = ctx->getGpu();
ctx->getTestTarget(&tt); if (!gpu) {
if (!tt.target()) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return; return;
} }
// We currently have only implemented the texture uploads for GL. // Test the wrapped factory for SkSurface by creating a backend texture and then wrap it in
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
// a SkSurface. // a SkSurface.
GrGLuint texID;
static const int kW = 100; static const int kW = 100;
static const int kH = 100; static const int kH = 100;
static const uint32_t kOrigColor = 0xFFAABBCC; static const uint32_t kOrigColor = 0xFFAABBCC;
SkAutoTArray<uint32_t> pixels(kW * kH); SkAutoTArray<uint32_t> pixels(kW * kH);
sk_memset32(pixels.get(), kOrigColor, kW * kH); sk_memset32(pixels.get(), kOrigColor, kW * kH);
GR_GL_CALL(gl, GenTextures(1, &texID)); GrBackendObject texID = gpu->createBackendTexture(pixels.get(), kW, kH,
GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0)); kRGBA_8888_GrPixelConfig);
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()));
GrBackendTextureDesc wrappedDesc; GrBackendTextureDesc wrappedDesc;
wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig;