aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-10-29 12:41:57 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-29 12:41:57 -0700
commitb15b4c1ce006319acf764a25ee4a6b73283654f8 (patch)
tree5c83c5405698cf097cf70714dc112e4423cad53c
parent9c30ea4c8654cc251ce243df4df97e30dab23ebb (diff)
Separate out GrSurfaceConfig's fields from other structs used to create GrGL* subclasses of GrSurface.
-rw-r--r--src/gpu/gl/GrGLRenderTarget.cpp55
-rw-r--r--src/gpu/gl/GrGLRenderTarget.h19
-rw-r--r--src/gpu/gl/GrGLTexture.cpp35
-rw-r--r--src/gpu/gl/GrGLTexture.h13
-rw-r--r--src/gpu/gl/GrGpuGL.cpp294
-rw-r--r--src/gpu/gl/GrGpuGL.h8
6 files changed, 173 insertions, 251 deletions
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index bcf6d711e5..0e8bd05bc7 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -13,70 +13,43 @@
#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
-void GrGLRenderTarget::init(const Desc& desc,
+void GrGLRenderTarget::init(const GrSurfaceDesc& desc,
+ const IDDesc& idDesc,
const GrGLIRect& viewport,
GrGLTexID* texID) {
- fRTFBOID = desc.fRTFBOID;
- fTexFBOID = desc.fTexFBOID;
- fMSColorRenderbufferID = desc.fMSColorRenderbufferID;
+ fRTFBOID = idDesc.fRTFBOID;
+ fTexFBOID = idDesc.fTexFBOID;
+ fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID;
fViewport = viewport;
fTexIDObj.reset(SkSafeRef(texID));
this->registerWithCache();
}
-namespace {
-GrSurfaceDesc MakeDesc(GrSurfaceFlags flags,
- int width, int height,
- GrPixelConfig config, int sampleCnt,
- GrSurfaceOrigin origin) {
- GrSurfaceDesc temp;
- temp.fFlags = flags;
- temp.fWidth = width;
- temp.fHeight = height;
- temp.fConfig = config;
- temp.fSampleCnt = sampleCnt;
- temp.fOrigin = origin;
- return temp;
-}
-
-};
-
GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
- const Desc& desc,
+ const IDDesc& idDesc,
const GrGLIRect& viewport,
GrGLTexID* texID,
GrGLTexture* texture)
- : INHERITED(gpu,
- desc.fIsWrapped,
- texture,
- MakeDesc(kNone_GrSurfaceFlags,
- viewport.fWidth, viewport.fHeight,
- desc.fConfig, desc.fSampleCnt,
- desc.fOrigin)) {
+ : INHERITED(gpu, idDesc.fIsWrapped, texture, texture->desc()) {
SkASSERT(texID);
SkASSERT(texture);
// FBO 0 can't also be a texture, right?
- SkASSERT(0 != desc.fRTFBOID);
- SkASSERT(0 != desc.fTexFBOID);
+ SkASSERT(0 != idDesc.fRTFBOID);
+ SkASSERT(0 != idDesc.fTexFBOID);
// we assume this is true, TODO: get rid of viewport as a param.
SkASSERT(viewport.fWidth == texture->width());
SkASSERT(viewport.fHeight == texture->height());
- this->init(desc, viewport, texID);
+ this->init(texture->desc(), idDesc, viewport, texID);
}
GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
- const Desc& desc,
+ const GrSurfaceDesc& desc,
+ const IDDesc& idDesc,
const GrGLIRect& viewport)
- : INHERITED(gpu,
- desc.fIsWrapped,
- NULL,
- MakeDesc(kNone_GrSurfaceFlags,
- viewport.fWidth, viewport.fHeight,
- desc.fConfig, desc.fSampleCnt,
- desc.fOrigin)) {
- this->init(desc, viewport, NULL);
+ : INHERITED(gpu, idDesc.fIsWrapped, NULL, desc) {
+ this->init(desc, idDesc, viewport, NULL);
}
void GrGLRenderTarget::onRelease() {
diff --git a/src/gpu/gl/GrGLRenderTarget.h b/src/gpu/gl/GrGLRenderTarget.h
index de9f4c1aa0..116862bd0b 100644
--- a/src/gpu/gl/GrGLRenderTarget.h
+++ b/src/gpu/gl/GrGLRenderTarget.h
@@ -24,28 +24,19 @@ public:
// Gr doesn't know how to resolve it.
enum { kUnresolvableFBOID = 0 };
- struct Desc {
+ struct IDDesc {
GrGLuint fRTFBOID;
GrGLuint fTexFBOID;
GrGLuint fMSColorRenderbufferID;
bool fIsWrapped;
- GrPixelConfig fConfig;
- int fSampleCnt;
- GrSurfaceOrigin fOrigin;
- bool fCheckAllocation;
};
// creates a GrGLRenderTarget associated with a texture
- GrGLRenderTarget(GrGpuGL* gpu,
- const Desc& desc,
- const GrGLIRect& viewport,
- GrGLTexID* texID,
- GrGLTexture* texture);
+ GrGLRenderTarget(GrGpuGL*, const IDDesc&, const GrGLIRect& viewport,
+ GrGLTexID*, GrGLTexture*);
// creates an independent GrGLRenderTarget
- GrGLRenderTarget(GrGpuGL* gpu,
- const Desc& desc,
- const GrGLIRect& viewport);
+ GrGLRenderTarget(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&, const GrGLIRect& viewport);
virtual ~GrGLRenderTarget() { this->release(); }
@@ -99,7 +90,7 @@ private:
// non-NULL if this RT was created by Gr with an associated GrGLTexture.
SkAutoTUnref<GrGLTexID> fTexIDObj;
- void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID);
+ void init(const GrSurfaceDesc&, const IDDesc&, const GrGLIRect& viewport, GrGLTexID*);
typedef GrRenderTarget INHERITED;
};
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index 202fc426ba..8cf574ba15 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -13,40 +13,41 @@
#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
void GrGLTexture::init(GrGpuGL* gpu,
- const Desc& textureDesc,
- const GrGLRenderTarget::Desc* rtDesc) {
+ const GrSurfaceDesc& desc,
+ const IDDesc& idDesc,
+ const GrGLRenderTarget::IDDesc* rtIDDesc) {
- SkASSERT(0 != textureDesc.fTextureID);
+ SkASSERT(0 != idDesc.fTextureID);
fTexParams.invalidate();
fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
fTexIDObj.reset(SkNEW_ARGS(GrGLTexID, (GPUGL->glInterface(),
- textureDesc.fTextureID,
- textureDesc.fIsWrapped)));
+ idDesc.fTextureID,
+ idDesc.fIsWrapped)));
- if (rtDesc) {
+ if (rtIDDesc) {
GrGLIRect vp;
vp.fLeft = 0;
- vp.fWidth = textureDesc.fWidth;
+ vp.fWidth = desc.fWidth;
vp.fBottom = 0;
- vp.fHeight = textureDesc.fHeight;
+ vp.fHeight = desc.fHeight;
- fRenderTarget.reset(SkNEW_ARGS(GrGLRenderTarget, (gpu, *rtDesc, vp, fTexIDObj, this)));
+ fRenderTarget.reset(SkNEW_ARGS(GrGLRenderTarget, (gpu, *rtIDDesc, vp, fTexIDObj, this)));
}
this->registerWithCache();
}
-GrGLTexture::GrGLTexture(GrGpuGL* gpu,
- const Desc& textureDesc)
- : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc) {
- this->init(gpu, textureDesc, NULL);
+GrGLTexture::GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
+ : INHERITED(gpu, idDesc.fIsWrapped, desc) {
+ this->init(gpu, desc, idDesc, NULL);
}
GrGLTexture::GrGLTexture(GrGpuGL* gpu,
- const Desc& textureDesc,
- const GrGLRenderTarget::Desc& rtDesc)
- : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc) {
- this->init(gpu, textureDesc, &rtDesc);
+ const GrSurfaceDesc& desc,
+ const IDDesc& idDesc,
+ const GrGLRenderTarget::IDDesc& rtIDDesc)
+ : INHERITED(gpu, idDesc.fIsWrapped, desc) {
+ this->init(gpu, desc, idDesc, &rtIDDesc);
}
void GrGLTexture::onRelease() {
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index 4f107aa654..11d63531cf 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -57,19 +57,16 @@ public:
void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
};
- struct Desc : public GrSurfaceDesc {
+ struct IDDesc {
GrGLuint fTextureID;
bool fIsWrapped;
};
// creates a texture that is also an RT
- GrGLTexture(GrGpuGL* gpu,
- const Desc& textureDesc,
- const GrGLRenderTarget::Desc& rtDesc);
+ GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc&, const IDDesc&, const GrGLRenderTarget::IDDesc&);
// creates a non-RT texture
- GrGLTexture(GrGpuGL* gpu,
- const Desc& textureDesc);
+ GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc&, const IDDesc&);
virtual ~GrGLTexture() { this->release(); }
@@ -101,9 +98,7 @@ private:
GrGpu::ResetTimestamp fTexParamsTimestamp;
SkAutoTUnref<GrGLTexID> fTexIDObj;
- void init(GrGpuGL* gpu,
- const Desc& textureDesc,
- const GrGLRenderTarget::Desc* rtDesc);
+ void init(GrGpuGL* gpu, const GrSurfaceDesc&, const IDDesc&, const GrGLRenderTarget::IDDesc*);
typedef GrTexture INHERITED;
};
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index f79f90ee4f..9c0860a2d4 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -374,45 +374,38 @@ GrTexture* GrGpuGL::onWrapBackendTexture(const GrBackendTextureDesc& desc) {
return NULL;
}
- GrGLTexture::Desc glTexDesc;
+ GrGLTexture::IDDesc idDesc;
+ GrSurfaceDesc surfDesc;
+
+ idDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle);
+ idDesc.fIsWrapped = true;
+
// next line relies on GrBackendTextureDesc's flags matching GrTexture's
- glTexDesc.fFlags = (GrSurfaceFlags) desc.fFlags;
- glTexDesc.fWidth = desc.fWidth;
- glTexDesc.fHeight = desc.fHeight;
- glTexDesc.fConfig = desc.fConfig;
- glTexDesc.fSampleCnt = desc.fSampleCnt;
- glTexDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle);
- glTexDesc.fIsWrapped = true;
+ surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags;
+ surfDesc.fWidth = desc.fWidth;
+ surfDesc.fHeight = desc.fHeight;
+ surfDesc.fConfig = desc.fConfig;
+ surfDesc.fSampleCnt = desc.fSampleCnt;
bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag);
// FIXME: this should be calling resolve_origin(), but Chrome code is currently
// assuming the old behaviour, which is that backend textures are always
// BottomLeft, even for non-RT's. Once Chrome is fixed, change this to:
// glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
if (kDefault_GrSurfaceOrigin == desc.fOrigin) {
- glTexDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
+ surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
} else {
- glTexDesc.fOrigin = desc.fOrigin;
+ surfDesc.fOrigin = desc.fOrigin;
}
GrGLTexture* texture = NULL;
if (renderTarget) {
- GrGLRenderTarget::Desc glRTDesc;
- glRTDesc.fRTFBOID = 0;
- glRTDesc.fTexFBOID = 0;
- glRTDesc.fMSColorRenderbufferID = 0;
- glRTDesc.fConfig = desc.fConfig;
- glRTDesc.fSampleCnt = desc.fSampleCnt;
- glRTDesc.fOrigin = glTexDesc.fOrigin;
- glRTDesc.fCheckAllocation = false;
- if (!this->createRenderTargetObjects(glTexDesc.fWidth,
- glTexDesc.fHeight,
- glTexDesc.fTextureID,
- &glRTDesc)) {
+ GrGLRenderTarget::IDDesc rtIDDesc;
+ if (!this->createRenderTargetObjects(surfDesc, idDesc.fTextureID, &rtIDDesc)) {
return NULL;
}
- texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc));
+ texture = SkNEW_ARGS(GrGLTexture, (this, surfDesc, idDesc, rtIDDesc));
} else {
- texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc));
+ texture = SkNEW_ARGS(GrGLTexture, (this, surfDesc, idDesc));
}
if (NULL == texture) {
return NULL;
@@ -421,31 +414,33 @@ GrTexture* GrGpuGL::onWrapBackendTexture(const GrBackendTextureDesc& desc) {
return texture;
}
-GrRenderTarget* GrGpuGL::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) {
- GrGLRenderTarget::Desc glDesc;
- glDesc.fConfig = desc.fConfig;
- glDesc.fRTFBOID = static_cast<GrGLuint>(desc.fRenderTargetHandle);
- glDesc.fMSColorRenderbufferID = 0;
- glDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
- glDesc.fSampleCnt = desc.fSampleCnt;
- glDesc.fIsWrapped = true;
- glDesc.fCheckAllocation = false;
-
- glDesc.fOrigin = resolve_origin(desc.fOrigin, true);
+GrRenderTarget* GrGpuGL::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc) {
+ GrGLRenderTarget::IDDesc idDesc;
+ idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle);
+ idDesc.fMSColorRenderbufferID = 0;
+ idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
+
+ GrSurfaceDesc desc;
+ desc.fConfig = wrapDesc.fConfig;
+ desc.fFlags = kCheckAllocation_GrSurfaceFlag;
+ desc.fWidth = wrapDesc.fWidth;
+ desc.fHeight = wrapDesc.fHeight;
+ desc.fSampleCnt = wrapDesc.fSampleCnt;
+ desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true);
+
GrGLIRect viewport;
viewport.fLeft = 0;
viewport.fBottom = 0;
viewport.fWidth = desc.fWidth;
viewport.fHeight = desc.fHeight;
- GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget,
- (this, glDesc, viewport));
- if (desc.fStencilBits) {
+ GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget, (this, desc, idDesc, viewport));
+ if (wrapDesc.fStencilBits) {
GrGLStencilBuffer::Format format;
format.fInternalFormat = GrGLStencilBuffer::kUnknownInternalFormat;
format.fPacked = false;
- format.fStencilBits = desc.fStencilBits;
- format.fTotalBits = desc.fStencilBits;
+ format.fStencilBits = wrapDesc.fStencilBits;
+ format.fTotalBits = wrapDesc.fStencilBits;
static const bool kIsSBWrapped = false;
GrGLStencilBuffer* sb = SkNEW_ARGS(GrGLStencilBuffer,
(this,
@@ -474,25 +469,16 @@ bool GrGpuGL::onWriteTexturePixels(GrTexture* texture,
this->setScratchTextureUnit();
GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID()));
- GrGLTexture::Desc desc;
- desc.fFlags = glTex->desc().fFlags;
- desc.fWidth = glTex->width();
- desc.fHeight = glTex->height();
- desc.fConfig = glTex->config();
- desc.fSampleCnt = glTex->desc().fSampleCnt;
- desc.fTextureID = glTex->textureID();
- desc.fOrigin = glTex->origin();
bool success = false;
- if (GrPixelConfigIsCompressed(desc.fConfig)) {
+ if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) {
// We check that config == desc.fConfig in GrGpuGL::canWriteTexturePixels()
- SkASSERT(config == desc.fConfig);
- success = this->uploadCompressedTexData(desc, buffer, false,
- left, top, width, height);
+ SkASSERT(config == glTex->desc().fConfig);
+ success = this->uploadCompressedTexData(glTex->desc(), buffer, false, left, top, width,
+ height);
} else {
- success = this->uploadTexData(desc, false,
- left, top, width, height,
- config, buffer, rowBytes);
+ success = this->uploadTexData(glTex->desc(), false, left, top, width, height, config,
+ buffer, rowBytes);
}
if (success) {
@@ -503,13 +489,12 @@ bool GrGpuGL::onWriteTexturePixels(GrTexture* texture,
return false;
}
-namespace {
-bool adjust_pixel_ops_params(int surfaceWidth,
- int surfaceHeight,
- size_t bpp,
- int* left, int* top, int* width, int* height,
- const void** data,
- size_t* rowBytes) {
+static bool adjust_pixel_ops_params(int surfaceWidth,
+ int surfaceHeight,
+ size_t bpp,
+ int* left, int* top, int* width, int* height,
+ const void** data,
+ size_t* rowBytes) {
if (!*rowBytes) {
*rowBytes = *width * bpp;
}
@@ -530,7 +515,8 @@ bool adjust_pixel_ops_params(int surfaceWidth,
return true;
}
-GrGLenum check_alloc_error(const GrSurfaceDesc& desc, const GrGLInterface* interface) {
+static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc,
+ const GrGLInterface* interface) {
if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) {
return GR_GL_GET_ERROR(interface);
} else {
@@ -538,9 +524,7 @@ GrGLenum check_alloc_error(const GrSurfaceDesc& desc, const GrGLInterface* inter
}
}
-}
-
-bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
+bool GrGpuGL::uploadTexData(const GrSurfaceDesc& desc,
bool isNewTexture,
int left, int top, int width, int height,
GrPixelConfig dataConfig,
@@ -715,7 +699,7 @@ bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
// create a CompressedTexData struct that takes a desc/ptr and figures out
// the proper upload semantics. Then users can construct this function how they
// see fit if they want to go against the "standard" way to do it.
-bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc,
+bool GrGpuGL::uploadCompressedTexData(const GrSurfaceDesc& desc,
const void* data,
bool isNewTexture,
int left, int top, int width, int height) {
@@ -821,24 +805,23 @@ static bool renderbuffer_storage_msaa(GrGLContext& ctx,
return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));;
}
-bool GrGpuGL::createRenderTargetObjects(int width, int height,
- GrGLuint texID,
- GrGLRenderTarget::Desc* desc) {
- desc->fMSColorRenderbufferID = 0;
- desc->fRTFBOID = 0;
- desc->fTexFBOID = 0;
- desc->fIsWrapped = false;
+bool GrGpuGL::createRenderTargetObjects(const GrSurfaceDesc& desc, GrGLuint texID,
+ GrGLRenderTarget::IDDesc* idDesc) {
+ idDesc->fMSColorRenderbufferID = 0;
+ idDesc->fRTFBOID = 0;
+ idDesc->fTexFBOID = 0;
+ idDesc->fIsWrapped = false;
GrGLenum status;
GrGLenum msColorFormat = 0; // suppress warning
- if (desc->fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType()) {
+ if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType()) {
goto FAILED;
}
- GL_CALL(GenFramebuffers(1, &desc->fTexFBOID));
- if (!desc->fTexFBOID) {
+ GL_CALL(GenFramebuffers(1, &idDesc->fTexFBOID));
+ if (!idDesc->fTexFBOID) {
goto FAILED;
}
@@ -847,12 +830,12 @@ bool GrGpuGL::createRenderTargetObjects(int width, int height,
// the texture bound to the other. The exception is the IMG multisample extension. With this
// extension the texture is multisampled when rendered to and then auto-resolves it when it is
// rendered from.
- if (desc->fSampleCnt > 0 && this->glCaps().usesMSAARenderBuffers()) {
- GL_CALL(GenFramebuffers(1, &desc->fRTFBOID));
- GL_CALL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID));
- if (!desc->fRTFBOID ||
- !desc->fMSColorRenderbufferID ||
- !this->configToGLFormats(desc->fConfig,
+ if (desc.fSampleCnt > 0 && this->glCaps().usesMSAARenderBuffers()) {
+ GL_CALL(GenFramebuffers(1, &idDesc->fRTFBOID));
+ GL_CALL(GenRenderbuffers(1, &idDesc->fMSColorRenderbufferID));
+ if (!idDesc->fRTFBOID ||
+ !idDesc->fMSColorRenderbufferID ||
+ !this->configToGLFormats(desc.fConfig,
// ES2 and ES3 require sized internal formats for rb storage.
kGLES_GrGLStandard == this->glStandard(),
&msColorFormat,
@@ -861,70 +844,69 @@ bool GrGpuGL::createRenderTargetObjects(int width, int height,
goto FAILED;
}
} else {
- desc->fRTFBOID = desc->fTexFBOID;
+ idDesc->fRTFBOID = idDesc->fTexFBOID;
}
// below here we may bind the FBO
fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
- if (desc->fRTFBOID != desc->fTexFBOID) {
- SkASSERT(desc->fSampleCnt > 0);
- GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER,
- desc->fMSColorRenderbufferID));
+ if (idDesc->fRTFBOID != idDesc->fTexFBOID) {
+ SkASSERT(desc.fSampleCnt > 0);
+ GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbufferID));
if (!renderbuffer_storage_msaa(fGLContext,
- desc->fSampleCnt,
+ desc.fSampleCnt,
msColorFormat,
- width, height)) {
+ desc.fWidth, desc.fHeight)) {
goto FAILED;
}
fGPUStats.incRenderTargetBinds();
- GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID));
+ GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fRTFBOID));
GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_RENDERBUFFER,
- desc->fMSColorRenderbufferID));
- if (desc->fCheckAllocation ||
- !this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) {
+ idDesc->fMSColorRenderbufferID));
+ if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) ||
+ !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) {
GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
goto FAILED;
}
- fGLContext.caps()->markConfigAsValidColorAttachment(desc->fConfig);
+ fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig);
}
}
fGPUStats.incRenderTargetBinds();
- GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID));
+ GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fTexFBOID));
- if (this->glCaps().usesImplicitMSAAResolve() && desc->fSampleCnt > 0) {
+ if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) {
GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_TEXTURE_2D,
- texID, 0, desc->fSampleCnt));
+ texID, 0, desc.fSampleCnt));
} else {
GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_TEXTURE_2D,
texID, 0));
}
- if (desc->fCheckAllocation ||
- !this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) {
+ if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) ||
+ !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) {
GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
goto FAILED;
}
- fGLContext.caps()->markConfigAsValidColorAttachment(desc->fConfig);
+ fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig);
}
return true;
FAILED:
- if (desc->fMSColorRenderbufferID) {
- GL_CALL(DeleteRenderbuffers(1, &desc->fMSColorRenderbufferID));
+ if (idDesc->fMSColorRenderbufferID) {
+ GL_CALL(DeleteRenderbuffers(1, &idDesc->fMSColorRenderbufferID));
}
- if (desc->fRTFBOID != desc->fTexFBOID) {
- GL_CALL(DeleteFramebuffers(1, &desc->fRTFBOID));
+ if (idDesc->fRTFBOID != idDesc->fTexFBOID) {
+ GL_CALL(DeleteFramebuffers(1, &idDesc->fRTFBOID));
}
- if (desc->fTexFBOID) {
- GL_CALL(DeleteFramebuffers(1, &desc->fTexFBOID));
+ if (idDesc->fTexFBOID) {
+ GL_CALL(DeleteFramebuffers(1, &idDesc->fTexFBOID));
}
return false;
}
@@ -941,12 +923,12 @@ static size_t as_size_t(int x) {
}
#endif
-GrTexture* GrGpuGL::onCreateTexture(const GrSurfaceDesc& desc,
+GrTexture* GrGpuGL::onCreateTexture(const GrSurfaceDesc& origDesc,
const void* srcData,
size_t rowBytes) {
- GrGLTexture::Desc glTexDesc;
- GrGLRenderTarget::Desc glRTDesc;
+ GrSurfaceDesc desc = origDesc;
+ GrGLRenderTarget::IDDesc rtIDDesc;
// Attempt to catch un- or wrongly initialized sample counts;
SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
@@ -955,54 +937,45 @@ GrTexture* GrGpuGL::onCreateTexture(const GrSurfaceDesc& desc,
//GrPrintf("MSAA RT requested but not supported on this platform.");
return return_null_texture();
}
- // If the sample count exceeds the max then we clamp it.
- glTexDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
-
- glTexDesc.fFlags = desc.fFlags;
- glTexDesc.fWidth = desc.fWidth;
- glTexDesc.fHeight = desc.fHeight;
- glTexDesc.fConfig = desc.fConfig;
- glTexDesc.fIsWrapped = false;
-
- glRTDesc.fMSColorRenderbufferID = 0;
- glRTDesc.fRTFBOID = 0;
- glRTDesc.fTexFBOID = 0;
- glRTDesc.fIsWrapped = false;
- glRTDesc.fConfig = glTexDesc.fConfig;
- glRTDesc.fCheckAllocation = SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag);
bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
- glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
- glRTDesc.fOrigin = glTexDesc.fOrigin;
+ // If the sample count exceeds the max then we clamp it.
+ desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
+ desc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
+
+ rtIDDesc.fMSColorRenderbufferID = 0;
+ rtIDDesc.fRTFBOID = 0;
+ rtIDDesc.fTexFBOID = 0;
+ rtIDDesc.fIsWrapped = false;
- glRTDesc.fSampleCnt = glTexDesc.fSampleCnt;
- if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() &&
- desc.fSampleCnt) {
+ if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleCnt) {
//GrPrintf("MSAA RT requested but not supported on this platform.");
return return_null_texture();
}
if (renderTarget) {
int maxRTSize = this->caps()->maxRenderTargetSize();
- if (glTexDesc.fWidth > maxRTSize || glTexDesc.fHeight > maxRTSize) {
+ if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
return return_null_texture();
}
} else {
int maxSize = this->caps()->maxTextureSize();
- if (glTexDesc.fWidth > maxSize || glTexDesc.fHeight > maxSize) {
+ if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
return return_null_texture();
}
}
- GL_CALL(GenTextures(1, &glTexDesc.fTextureID));
+ GrGLTexture::IDDesc idDesc;
+ GL_CALL(GenTextures(1, &idDesc.fTextureID));
+ idDesc.fIsWrapped = false;
- if (!glTexDesc.fTextureID) {
+ if (!idDesc.fTextureID) {
return return_null_texture();
}
this->setScratchTextureUnit();
- GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID));
+ GL_CALL(BindTexture(GR_GL_TEXTURE_2D, idDesc.fTextureID));
if (renderTarget && this->glCaps().textureUsageSupport()) {
// provides a hint about how this texture will be used
@@ -1033,10 +1006,10 @@ GrTexture* GrGpuGL::onCreateTexture(const GrSurfaceDesc& desc,
GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
GR_GL_TEXTURE_WRAP_T,
initialTexParams.fWrapT));
- if (!this->uploadTexData(glTexDesc, true, 0, 0,
- glTexDesc.fWidth, glTexDesc.fHeight,
+ if (!this->uploadTexData(desc, true, 0, 0,
+ desc.fWidth, desc.fHeight,
desc.fConfig, srcData, rowBytes)) {
- GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID));
+ GL_CALL(DeleteTextures(1, &idDesc.fTextureID));
return return_null_texture();
}
@@ -1045,16 +1018,13 @@ GrTexture* GrGpuGL::onCreateTexture(const GrSurfaceDesc& desc,
// unbind the texture from the texture unit before binding it to the frame buffer
GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0));
- if (!this->createRenderTargetObjects(glTexDesc.fWidth,
- glTexDesc.fHeight,
- glTexDesc.fTextureID,
- &glRTDesc)) {
- GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID));
+ if (!this->createRenderTargetObjects(desc, idDesc.fTextureID, &rtIDDesc)) {
+ GL_CALL(DeleteTextures(1, &idDesc.fTextureID));
return return_null_texture();
}
- tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc));
+ tex = SkNEW_ARGS(GrGLTexture, (this, desc, idDesc, rtIDDesc));
} else {
- tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc));
+ tex = SkNEW_ARGS(GrGLTexture, (this, desc, idDesc));
}
tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
#ifdef TRACE_TEXTURE_CREATION
@@ -1064,41 +1034,35 @@ GrTexture* GrGpuGL::onCreateTexture(const GrSurfaceDesc& desc,
return tex;
}
-GrTexture* GrGpuGL::onCreateCompressedTexture(const GrSurfaceDesc& desc,
- const void* srcData) {
+GrTexture* GrGpuGL::onCreateCompressedTexture(const GrSurfaceDesc& origDesc, const void* srcData) {
- if(SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) {
+ if(SkToBool(origDesc.fFlags & kRenderTarget_GrSurfaceFlag) || origDesc.fSampleCnt > 0) {
return return_null_texture();
}
// Make sure that we're not flipping Y.
- GrSurfaceOrigin texOrigin = resolve_origin(desc.fOrigin, false);
+ GrSurfaceOrigin texOrigin = resolve_origin(origDesc.fOrigin, false);
if (kBottomLeft_GrSurfaceOrigin == texOrigin) {
return return_null_texture();
}
-
- GrGLTexture::Desc glTexDesc;
-
- glTexDesc.fFlags = desc.fFlags;
- glTexDesc.fWidth = desc.fWidth;
- glTexDesc.fHeight = desc.fHeight;
- glTexDesc.fConfig = desc.fConfig;
- glTexDesc.fIsWrapped = false;
- glTexDesc.fOrigin = texOrigin;
+ GrSurfaceDesc desc = origDesc;
+ desc.fOrigin = texOrigin;
int maxSize = this->caps()->maxTextureSize();
- if (glTexDesc.fWidth > maxSize || glTexDesc.fHeight > maxSize) {
+ if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
return return_null_texture();
}
- GL_CALL(GenTextures(1, &glTexDesc.fTextureID));
+ GrGLTexture::IDDesc idDesc;
+ GL_CALL(GenTextures(1, &idDesc.fTextureID));
+ idDesc.fIsWrapped = false;
- if (!glTexDesc.fTextureID) {
+ if (!idDesc.fTextureID) {
return return_null_texture();
}
this->setScratchTextureUnit();
- GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID));
+ GL_CALL(BindTexture(GR_GL_TEXTURE_2D, idDesc.fTextureID));
// Some drivers like to know filter/wrap before seeing glTexImage2D. Some
// drivers have a bug where an FBO won't be complete if it includes a
@@ -1123,13 +1087,13 @@ GrTexture* GrGpuGL::onCreateCompressedTexture(const GrSurfaceDesc& desc,
GR_GL_TEXTURE_WRAP_T,
initialTexParams.fWrapT));
- if (!this->uploadCompressedTexData(glTexDesc, srcData)) {
- GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID));
+ if (!this->uploadCompressedTexData(desc, srcData)) {
+ GL_CALL(DeleteTextures(1, &idDesc.fTextureID));
return return_null_texture();
}
GrGLTexture* tex;
- tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc));
+ tex = SkNEW_ARGS(GrGLTexture, (this, desc, idDesc));
tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
#ifdef TRACE_TEXTURE_CREATION
GrPrintf("--- new compressed texture [%d] size=(%d %d) config=%d\n",
diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h
index 568ce96f31..1a03c130c6 100644
--- a/src/gpu/gl/GrGpuGL.h
+++ b/src/gpu/gl/GrGpuGL.h
@@ -258,7 +258,7 @@ private:
GrGLenum* externalFormat,
GrGLenum* externalType);
// helper for onCreateTexture and writeTexturePixels
- bool uploadTexData(const GrGLTexture::Desc& desc,
+ bool uploadTexData(const GrSurfaceDesc& desc,
bool isNewTexture,
int left, int top, int width, int height,
GrPixelConfig dataConfig,
@@ -271,15 +271,13 @@ private:
// whenever a new texture needs to be created. Otherwise, we assume that
// the texture is already in GPU memory and that it's going to be updated
// with new data.
- bool uploadCompressedTexData(const GrGLTexture::Desc& desc,
+ bool uploadCompressedTexData(const GrSurfaceDesc& desc,
const void* data,
bool isNewTexture = true,
int left = 0, int top = 0,
int width = -1, int height = -1);
- bool createRenderTargetObjects(int width, int height,
- GrGLuint texID,
- GrGLRenderTarget::Desc* desc);
+ bool createRenderTargetObjects(const GrSurfaceDesc&, GrGLuint texID, GrGLRenderTarget::IDDesc*);
GrGLuint bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport);