Remove GL-specific code from GMs and tests
TBR=bsalomon@google.com Review URL: https://codereview.chromium.org/1232173002
This commit is contained in:
parent
ab9cb427f4
commit
672bb7fc66
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user