move render target decls / defs to their own headers / srcs
Review URL: http://codereview.appspot.com/4806058/ git-svn-id: http://skia.googlecode.com/svn/trunk@1995 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
3448e9e134
commit
aa5b6730f2
@ -11,13 +11,14 @@
|
||||
#ifndef GrDrawTarget_DEFINED
|
||||
#define GrDrawTarget_DEFINED
|
||||
|
||||
#include "GrMatrix.h"
|
||||
#include "GrColor.h"
|
||||
#include "GrRefCnt.h"
|
||||
#include "GrSamplerState.h"
|
||||
#include "GrClip.h"
|
||||
#include "GrTexture.h"
|
||||
#include "GrColor.h"
|
||||
#include "GrMatrix.h"
|
||||
#include "GrRefCnt.h"
|
||||
#include "GrRenderTarget.h"
|
||||
#include "GrSamplerState.h"
|
||||
#include "GrStencil.h"
|
||||
#include "GrTexture.h"
|
||||
|
||||
#include "SkXfermode.h"
|
||||
|
||||
|
190
gpu/include/GrRenderTarget.h
Normal file
190
gpu/include/GrRenderTarget.h
Normal file
@ -0,0 +1,190 @@
|
||||
/*
|
||||
Copyright 2011 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GrRenderTarget_DEFINED
|
||||
#define GrRenderTarget_DEFINED
|
||||
|
||||
#include "GrClip.h"
|
||||
#include "GrRect.h"
|
||||
#include "GrResource.h"
|
||||
|
||||
class GrTexture;
|
||||
|
||||
/**
|
||||
* GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
|
||||
* A context's render target is set by setRenderTarget(). Render targets are
|
||||
* created by a createTexture with the kRenderTarget_TextureFlag flag.
|
||||
* Additionally, GrContext provides methods for creating GrRenderTargets
|
||||
* that wrap externally created render targets.
|
||||
*/
|
||||
class GrRenderTarget : public GrResource {
|
||||
|
||||
public:
|
||||
/**
|
||||
* @return the width of the rendertarget
|
||||
*/
|
||||
int width() const { return fWidth; }
|
||||
/**
|
||||
* @return the height of the rendertarget
|
||||
*/
|
||||
int height() const { return fHeight; }
|
||||
|
||||
/**
|
||||
* @return the pixel config. Can be kUnknown_GrPixelConfig
|
||||
* if client asked us to render to a target that has a pixel
|
||||
* config that isn't equivalent with one of our configs.
|
||||
*/
|
||||
int config() const { return fConfig; }
|
||||
|
||||
/**
|
||||
* @return the number of stencil bits in the rendertarget
|
||||
*/
|
||||
int stencilBits() const { return fStencilBits; }
|
||||
|
||||
/**
|
||||
* @return the texture associated with the rendertarget, may be NULL.
|
||||
*/
|
||||
GrTexture* asTexture() {return fTexture;}
|
||||
|
||||
/**
|
||||
* If this RT is multisampled, this is the multisample buffer
|
||||
* @return the 3D API's handle to this object (e.g. FBO ID in OpenGL)
|
||||
*/
|
||||
virtual intptr_t getRenderTargetHandle() const = 0;
|
||||
|
||||
/**
|
||||
* If this RT is multisampled, this is the buffer it is resolved to.
|
||||
* Otherwise, same as getRenderTargetHandle().
|
||||
* (In GL a separate FBO ID is used for the msaa and resolved buffers)
|
||||
* @return the 3D API's handle to this object (e.g. FBO ID in OpenGL)
|
||||
*/
|
||||
virtual intptr_t getRenderTargetResolvedHandle() const = 0;
|
||||
|
||||
/**
|
||||
* @return true if the render target is multisampled, false otherwise
|
||||
*/
|
||||
bool isMultisampled() { return fIsMultisampled; }
|
||||
|
||||
/**
|
||||
* Call to indicate the multisample contents were modified such that the
|
||||
* render target needs to be resolved before it can be used as texture. Gr
|
||||
* tracks this for its own drawing and thus this only needs to be called
|
||||
* when the render target has been modified outside of Gr. Only meaningful
|
||||
* for Gr-created RT/Textures and Platform RT/Textures created with the
|
||||
* kGrCanResolve flag.
|
||||
* @param rect a rect bounding the area needing resolve. NULL indicates
|
||||
* the whole RT needs resolving.
|
||||
*/
|
||||
void flagAsNeedingResolve(const GrIRect* rect = NULL);
|
||||
|
||||
/**
|
||||
* Call to override the region that needs to be resolved.
|
||||
*/
|
||||
void overrideResolveRect(const GrIRect rect);
|
||||
|
||||
/**
|
||||
* Call to indicate that GrRenderTarget was externally resolved. This may
|
||||
* allow Gr to skip a redundant resolve step.
|
||||
*/
|
||||
void flagAsResolved() { fResolveRect.setLargestInverted(); }
|
||||
|
||||
/**
|
||||
* @return true if the GrRenderTarget requires MSAA resolving
|
||||
*/
|
||||
bool needsResolve() const { return !fResolveRect.isEmpty(); }
|
||||
|
||||
/**
|
||||
* Returns a rect bounding the region needing resolving.
|
||||
*/
|
||||
const GrIRect& getResolveRect() const { return fResolveRect; }
|
||||
|
||||
// GrResource overrides
|
||||
virtual size_t sizeInBytes() const;
|
||||
|
||||
/**
|
||||
* Reads a rectangle of pixels from the render target.
|
||||
* @param left left edge of the rectangle to read (inclusive)
|
||||
* @param top top edge of the rectangle to read (inclusive)
|
||||
* @param width width of rectangle to read in pixels.
|
||||
* @param height height of rectangle to read in pixels.
|
||||
* @param config the pixel config of the destination buffer
|
||||
* @param buffer memory to read the rectangle into.
|
||||
*
|
||||
* @return true if the read succeeded, false if not. The read can fail
|
||||
* because of a unsupported pixel config.
|
||||
*/
|
||||
bool readPixels(int left, int top, int width, int height,
|
||||
GrPixelConfig config, void* buffer);
|
||||
|
||||
// a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
|
||||
// 0 in GL), or be unresolvable because the client didn't give us the
|
||||
// resolve destination.
|
||||
enum ResolveType {
|
||||
kCanResolve_ResolveType,
|
||||
kAutoResolves_ResolveType,
|
||||
kCantResolve_ResolveType,
|
||||
};
|
||||
virtual ResolveType getResolveType() const = 0;
|
||||
|
||||
protected:
|
||||
GrRenderTarget(GrGpu* gpu,
|
||||
GrTexture* texture,
|
||||
int width,
|
||||
int height,
|
||||
GrPixelConfig config,
|
||||
int stencilBits,
|
||||
bool isMultisampled)
|
||||
: INHERITED(gpu)
|
||||
, fTexture(texture)
|
||||
, fWidth(width)
|
||||
, fHeight(height)
|
||||
, fConfig(config)
|
||||
, fStencilBits(stencilBits)
|
||||
, fIsMultisampled(isMultisampled)
|
||||
{
|
||||
fResolveRect.setLargestInverted();
|
||||
}
|
||||
|
||||
friend class GrTexture;
|
||||
// When a texture unrefs an owned rendertarget this func
|
||||
// removes the back pointer. This could be done called from
|
||||
// texture's destructor but would have to be done in derived
|
||||
// class. By the time of texture base destructor it has already
|
||||
// lost its pointer to the rt.
|
||||
void onTextureReleaseRenderTarget() {
|
||||
GrAssert(NULL != fTexture);
|
||||
fTexture = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
GrTexture* fTexture; // not ref'ed
|
||||
int fWidth;
|
||||
int fHeight;
|
||||
GrPixelConfig fConfig;
|
||||
int fStencilBits;
|
||||
bool fIsMultisampled;
|
||||
GrIRect fResolveRect;
|
||||
|
||||
// GrGpu keeps a cached clip in the render target to avoid redundantly
|
||||
// rendering the clip into the same stencil buffer.
|
||||
friend class GrGpu;
|
||||
GrClip fLastStencilClip;
|
||||
|
||||
typedef GrResource INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
@ -11,174 +11,9 @@
|
||||
#ifndef GrTexture_DEFINED
|
||||
#define GrTexture_DEFINED
|
||||
|
||||
#include "GrRefCnt.h"
|
||||
#include "GrClip.h"
|
||||
#include "GrResource.h"
|
||||
|
||||
class GrTexture;
|
||||
|
||||
/**
|
||||
* GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
|
||||
* A context's render target is set by setRenderTarget(). Render targets are
|
||||
* created by a createTexture with the kRenderTarget_TextureFlag flag.
|
||||
* Additionally, GrContext provides methods for creating GrRenderTargets
|
||||
* that wrap externally created render targets.
|
||||
*/
|
||||
class GrRenderTarget : public GrResource {
|
||||
|
||||
public:
|
||||
/**
|
||||
* @return the width of the rendertarget
|
||||
*/
|
||||
int width() const { return fWidth; }
|
||||
/**
|
||||
* @return the height of the rendertarget
|
||||
*/
|
||||
int height() const { return fHeight; }
|
||||
|
||||
/**
|
||||
* @return the pixel config. Can be kUnknown_GrPixelConfig
|
||||
* if client asked us to render to a target that has a pixel
|
||||
* config that isn't equivalent with one of our configs.
|
||||
*/
|
||||
int config() const { return fConfig; }
|
||||
|
||||
/**
|
||||
* @return the number of stencil bits in the rendertarget
|
||||
*/
|
||||
int stencilBits() const { return fStencilBits; }
|
||||
|
||||
/**
|
||||
* @return the texture associated with the rendertarget, may be NULL.
|
||||
*/
|
||||
GrTexture* asTexture() {return fTexture;}
|
||||
|
||||
/**
|
||||
* If this RT is multisampled, this is the multisample buffer
|
||||
* @return the 3D API's handle to this object (e.g. FBO ID in OpenGL)
|
||||
*/
|
||||
virtual intptr_t getRenderTargetHandle() const = 0;
|
||||
|
||||
/**
|
||||
* If this RT is multisampled, this is the buffer it is resolved to.
|
||||
* Otherwise, same as getRenderTargetHandle().
|
||||
* (In GL a separate FBO ID is used for the msaa and resolved buffers)
|
||||
* @return the 3D API's handle to this object (e.g. FBO ID in OpenGL)
|
||||
*/
|
||||
virtual intptr_t getRenderTargetResolvedHandle() const = 0;
|
||||
|
||||
/**
|
||||
* @return true if the render target is multisampled, false otherwise
|
||||
*/
|
||||
bool isMultisampled() { return fIsMultisampled; }
|
||||
|
||||
/**
|
||||
* Call to indicate the multisample contents were modified such that the
|
||||
* render target needs to be resolved before it can be used as texture. Gr
|
||||
* tracks this for its own drawing and thus this only needs to be called
|
||||
* when the render target has been modified outside of Gr. Only meaningful
|
||||
* for Gr-created RT/Textures and Platform RT/Textures created with the
|
||||
* kGrCanResolve flag.
|
||||
* @param rect a rect bounding the area needing resolve. NULL indicates
|
||||
* the whole RT needs resolving.
|
||||
*/
|
||||
void flagAsNeedingResolve(const GrIRect* rect = NULL);
|
||||
|
||||
/**
|
||||
* Call to override the region that needs to be resolved.
|
||||
*/
|
||||
void overrideResolveRect(const GrIRect rect);
|
||||
|
||||
/**
|
||||
* Call to indicate that GrRenderTarget was externally resolved. This may
|
||||
* allow Gr to skip a redundant resolve step.
|
||||
*/
|
||||
void flagAsResolved() { fResolveRect.setLargestInverted(); }
|
||||
|
||||
/**
|
||||
* @return true if the GrRenderTarget requires MSAA resolving
|
||||
*/
|
||||
bool needsResolve() const { return !fResolveRect.isEmpty(); }
|
||||
|
||||
/**
|
||||
* Returns a rect bounding the region needing resolving.
|
||||
*/
|
||||
const GrIRect& getResolveRect() const { return fResolveRect; }
|
||||
|
||||
// GrResource overrides
|
||||
virtual size_t sizeInBytes() const;
|
||||
|
||||
/**
|
||||
* Reads a rectangle of pixels from the render target.
|
||||
* @param left left edge of the rectangle to read (inclusive)
|
||||
* @param top top edge of the rectangle to read (inclusive)
|
||||
* @param width width of rectangle to read in pixels.
|
||||
* @param height height of rectangle to read in pixels.
|
||||
* @param config the pixel config of the destination buffer
|
||||
* @param buffer memory to read the rectangle into.
|
||||
*
|
||||
* @return true if the read succeeded, false if not. The read can fail
|
||||
* because of a unsupported pixel config.
|
||||
*/
|
||||
bool readPixels(int left, int top, int width, int height,
|
||||
GrPixelConfig config, void* buffer);
|
||||
|
||||
// a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
|
||||
// 0 in GL), or be unresolvable because the client didn't give us the
|
||||
// resolve destination.
|
||||
enum ResolveType {
|
||||
kCanResolve_ResolveType,
|
||||
kAutoResolves_ResolveType,
|
||||
kCantResolve_ResolveType,
|
||||
};
|
||||
virtual ResolveType getResolveType() const = 0;
|
||||
|
||||
protected:
|
||||
GrRenderTarget(GrGpu* gpu,
|
||||
GrTexture* texture,
|
||||
int width,
|
||||
int height,
|
||||
GrPixelConfig config,
|
||||
int stencilBits,
|
||||
bool isMultisampled)
|
||||
: INHERITED(gpu)
|
||||
, fTexture(texture)
|
||||
, fWidth(width)
|
||||
, fHeight(height)
|
||||
, fConfig(config)
|
||||
, fStencilBits(stencilBits)
|
||||
, fIsMultisampled(isMultisampled)
|
||||
{
|
||||
fResolveRect.setLargestInverted();
|
||||
}
|
||||
|
||||
friend class GrTexture;
|
||||
// When a texture unrefs an owned rendertarget this func
|
||||
// removes the back pointer. This could be done called from
|
||||
// texture's destructor but would have to be done in derived
|
||||
// class. By the time of texture base destructor it has already
|
||||
// lost its pointer to the rt.
|
||||
void onTextureReleaseRenderTarget() {
|
||||
GrAssert(NULL != fTexture);
|
||||
fTexture = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
GrTexture* fTexture; // not ref'ed
|
||||
int fWidth;
|
||||
int fHeight;
|
||||
GrPixelConfig fConfig;
|
||||
int fStencilBits;
|
||||
bool fIsMultisampled;
|
||||
GrIRect fResolveRect;
|
||||
|
||||
// GrGpu keeps a cached clip in the render target to avoid redundantly
|
||||
// rendering the clip into the same stencil buffer.
|
||||
friend class GrGpu;
|
||||
GrClip fLastStencilClip;
|
||||
|
||||
typedef GrResource INHERITED;
|
||||
};
|
||||
class GrRenderTarget;
|
||||
|
||||
class GrTexture : public GrResource {
|
||||
|
||||
@ -266,14 +101,7 @@ public:
|
||||
* texture. Afterwards asRenderTarget() will return NULL. The
|
||||
* GrRenderTarget survives the release if another ref is held on it.
|
||||
*/
|
||||
void releaseRenderTarget() {
|
||||
if (NULL != fRenderTarget) {
|
||||
GrAssert(fRenderTarget->asTexture() == this);
|
||||
fRenderTarget->onTextureReleaseRenderTarget();
|
||||
fRenderTarget->unref();
|
||||
fRenderTarget = NULL;
|
||||
}
|
||||
}
|
||||
void releaseRenderTarget();
|
||||
|
||||
/**
|
||||
* Return the native ID or handle to the texture, depending on the
|
||||
@ -310,14 +138,10 @@ protected:
|
||||
|
||||
// GrResource overrides
|
||||
virtual void onRelease() {
|
||||
releaseRenderTarget();
|
||||
this->releaseRenderTarget();
|
||||
}
|
||||
|
||||
virtual void onAbandon() {
|
||||
if (NULL != fRenderTarget) {
|
||||
fRenderTarget->abandon();
|
||||
}
|
||||
}
|
||||
virtual void onAbandon();
|
||||
|
||||
private:
|
||||
int fWidth;
|
||||
|
71
gpu/src/GrGLRenderTarget.cpp
Normal file
71
gpu/src/GrGLRenderTarget.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#include "GrGLRenderTarget.h"
|
||||
|
||||
#include "GrGpuGL.h"
|
||||
|
||||
#define GPUGL static_cast<GrGpuGL*>(getGpu())
|
||||
|
||||
GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
|
||||
const GLRenderTargetIDs& ids,
|
||||
GrGLTexID* texID,
|
||||
GrPixelConfig config,
|
||||
GrGLuint stencilBits,
|
||||
bool isMultisampled,
|
||||
const GrGLIRect& viewport,
|
||||
GrGLTexture* texture)
|
||||
: INHERITED(gpu, texture, viewport.fWidth,
|
||||
viewport.fHeight, config,
|
||||
stencilBits, isMultisampled) {
|
||||
fRTFBOID = ids.fRTFBOID;
|
||||
fTexFBOID = ids.fTexFBOID;
|
||||
fStencilRenderbufferID = ids.fStencilRenderbufferID;
|
||||
fMSColorRenderbufferID = ids.fMSColorRenderbufferID;
|
||||
fViewport = viewport;
|
||||
fOwnIDs = ids.fOwnIDs;
|
||||
fTexIDObj = texID;
|
||||
GrSafeRef(fTexIDObj);
|
||||
}
|
||||
|
||||
void GrGLRenderTarget::onRelease() {
|
||||
GPUGL->notifyRenderTargetDelete(this);
|
||||
if (fOwnIDs) {
|
||||
if (fTexFBOID) {
|
||||
GR_GL(DeleteFramebuffers(1, &fTexFBOID));
|
||||
}
|
||||
if (fRTFBOID && fRTFBOID != fTexFBOID) {
|
||||
GR_GL(DeleteFramebuffers(1, &fRTFBOID));
|
||||
}
|
||||
if (fStencilRenderbufferID) {
|
||||
GR_GL(DeleteRenderbuffers(1, &fStencilRenderbufferID));
|
||||
}
|
||||
if (fMSColorRenderbufferID) {
|
||||
GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
|
||||
}
|
||||
}
|
||||
fRTFBOID = 0;
|
||||
fTexFBOID = 0;
|
||||
fStencilRenderbufferID = 0;
|
||||
fMSColorRenderbufferID = 0;
|
||||
GrSafeUnref(fTexIDObj);
|
||||
fTexIDObj = NULL;
|
||||
}
|
||||
|
||||
void GrGLRenderTarget::onAbandon() {
|
||||
fRTFBOID = 0;
|
||||
fTexFBOID = 0;
|
||||
fStencilRenderbufferID = 0;
|
||||
fMSColorRenderbufferID = 0;
|
||||
if (NULL != fTexIDObj) {
|
||||
fTexIDObj->abandon();
|
||||
fTexIDObj = NULL;
|
||||
}
|
||||
}
|
||||
|
103
gpu/src/GrGLRenderTarget.h
Normal file
103
gpu/src/GrGLRenderTarget.h
Normal file
@ -0,0 +1,103 @@
|
||||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GrGLRenderTarget_DEFINED
|
||||
#define GrGLRenderTarget_DEFINED
|
||||
|
||||
#include "GrGLIRect.h"
|
||||
#include "GrRenderTarget.h"
|
||||
#include "GrScalar.h"
|
||||
|
||||
class GrGpuGL;
|
||||
class GrGLTexture;
|
||||
class GrGLTexID;
|
||||
|
||||
class GrGLRenderTarget : public GrRenderTarget {
|
||||
|
||||
public:
|
||||
// set fTexFBOID to this value to indicate that it is multisampled but
|
||||
// Gr doesn't know how to resolve it.
|
||||
enum { kUnresolvableFBOID = 0 };
|
||||
|
||||
struct GLRenderTargetIDs {
|
||||
GrGLuint fRTFBOID;
|
||||
GrGLuint fTexFBOID;
|
||||
GrGLuint fStencilRenderbufferID;
|
||||
GrGLuint fMSColorRenderbufferID;
|
||||
bool fOwnIDs;
|
||||
void reset() { memset(this, 0, sizeof(GLRenderTargetIDs)); }
|
||||
};
|
||||
|
||||
GrGLRenderTarget(GrGpuGL* gpu,
|
||||
const GLRenderTargetIDs& ids,
|
||||
GrGLTexID* texID,
|
||||
GrPixelConfig config,
|
||||
GrGLuint stencilBits,
|
||||
bool isMultisampled,
|
||||
const GrGLIRect& fViewport,
|
||||
GrGLTexture* texture);
|
||||
|
||||
virtual ~GrGLRenderTarget() { this->release(); }
|
||||
|
||||
void setViewport(const GrGLIRect& rect) { fViewport = rect; }
|
||||
const GrGLIRect& getViewport() const { return fViewport; }
|
||||
|
||||
// The following two functions return the same ID when a
|
||||
// texture-rendertarget is multisampled, and different IDs when
|
||||
// it is.
|
||||
// FBO ID used to render into
|
||||
GrGLuint renderFBOID() const { return fRTFBOID; }
|
||||
// FBO ID that has texture ID attached.
|
||||
GrGLuint textureFBOID() const { return fTexFBOID; }
|
||||
|
||||
// override of GrRenderTarget
|
||||
virtual intptr_t getRenderTargetHandle() const {
|
||||
return this->renderFBOID();
|
||||
}
|
||||
virtual intptr_t getRenderTargetResolvedHandle() const {
|
||||
return this->textureFBOID();
|
||||
}
|
||||
virtual ResolveType getResolveType() const {
|
||||
if (fRTFBOID == fTexFBOID) {
|
||||
// catches FBO 0 and non MSAA case
|
||||
return kAutoResolves_ResolveType;
|
||||
} else if (kUnresolvableFBOID == fTexFBOID) {
|
||||
return kCantResolve_ResolveType;
|
||||
} else {
|
||||
return kCanResolve_ResolveType;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
// override of GrResource
|
||||
virtual void onAbandon();
|
||||
virtual void onRelease();
|
||||
|
||||
private:
|
||||
GrGLuint fRTFBOID;
|
||||
GrGLuint fTexFBOID;
|
||||
GrGLuint fStencilRenderbufferID;
|
||||
GrGLuint fMSColorRenderbufferID;
|
||||
|
||||
// Should this object delete IDs when it is destroyed or does someone
|
||||
// else own them.
|
||||
bool fOwnIDs;
|
||||
|
||||
// when we switch to this rendertarget we want to set the viewport to
|
||||
// only render to to content area (as opposed to the whole allocation) and
|
||||
// we want the rendering to be at top left (GL has origin in bottom left)
|
||||
GrGLIRect fViewport;
|
||||
|
||||
// non-NULL if this RT was created by Gr with an associated GrGLTexture.
|
||||
GrGLTexID* fTexIDObj;
|
||||
|
||||
typedef GrRenderTarget INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
@ -7,71 +7,12 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "GrGLTexture.h"
|
||||
|
||||
#include "GrGpuGL.h"
|
||||
|
||||
#define GPUGL static_cast<GrGpuGL*>(getGpu())
|
||||
|
||||
GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
|
||||
const GLRenderTargetIDs& ids,
|
||||
GrGLTexID* texID,
|
||||
GrPixelConfig config,
|
||||
GrGLuint stencilBits,
|
||||
bool isMultisampled,
|
||||
const GrGLIRect& viewport,
|
||||
GrGLTexture* texture)
|
||||
: INHERITED(gpu, texture, viewport.fWidth,
|
||||
viewport.fHeight, config,
|
||||
stencilBits, isMultisampled) {
|
||||
fRTFBOID = ids.fRTFBOID;
|
||||
fTexFBOID = ids.fTexFBOID;
|
||||
fStencilRenderbufferID = ids.fStencilRenderbufferID;
|
||||
fMSColorRenderbufferID = ids.fMSColorRenderbufferID;
|
||||
fViewport = viewport;
|
||||
fOwnIDs = ids.fOwnIDs;
|
||||
fTexIDObj = texID;
|
||||
GrSafeRef(fTexIDObj);
|
||||
}
|
||||
|
||||
void GrGLRenderTarget::onRelease() {
|
||||
GPUGL->notifyRenderTargetDelete(this);
|
||||
if (fOwnIDs) {
|
||||
if (fTexFBOID) {
|
||||
GR_GL(DeleteFramebuffers(1, &fTexFBOID));
|
||||
}
|
||||
if (fRTFBOID && fRTFBOID != fTexFBOID) {
|
||||
GR_GL(DeleteFramebuffers(1, &fRTFBOID));
|
||||
}
|
||||
if (fStencilRenderbufferID) {
|
||||
GR_GL(DeleteRenderbuffers(1, &fStencilRenderbufferID));
|
||||
}
|
||||
if (fMSColorRenderbufferID) {
|
||||
GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
|
||||
}
|
||||
}
|
||||
fRTFBOID = 0;
|
||||
fTexFBOID = 0;
|
||||
fStencilRenderbufferID = 0;
|
||||
fMSColorRenderbufferID = 0;
|
||||
GrSafeUnref(fTexIDObj);
|
||||
fTexIDObj = NULL;
|
||||
}
|
||||
|
||||
void GrGLRenderTarget::onAbandon() {
|
||||
fRTFBOID = 0;
|
||||
fTexFBOID = 0;
|
||||
fStencilRenderbufferID = 0;
|
||||
fMSColorRenderbufferID = 0;
|
||||
if (NULL != fTexIDObj) {
|
||||
fTexIDObj->abandon();
|
||||
fTexIDObj = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const GrGLenum* GrGLTexture::WrapMode2GLWrap() {
|
||||
static const GrGLenum mirrorRepeatModes[] = {
|
||||
GR_GL_CLAMP_TO_EDGE,
|
||||
|
@ -10,12 +10,9 @@
|
||||
#ifndef GrGLTexture_DEFINED
|
||||
#define GrGLTexture_DEFINED
|
||||
|
||||
#include "GrTexture.h"
|
||||
#include "GrGLRenderTarget.h"
|
||||
#include "GrScalar.h"
|
||||
#include "GrGLIRect.h"
|
||||
|
||||
class GrGpuGL;
|
||||
class GrGLTexture;
|
||||
#include "GrTexture.h"
|
||||
|
||||
/**
|
||||
* A ref counted tex id that deletes the texture in its destructor.
|
||||
@ -41,89 +38,6 @@ private:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class GrGLRenderTarget : public GrRenderTarget {
|
||||
|
||||
public:
|
||||
// set fTexFBOID to this value to indicate that it is multisampled but
|
||||
// Gr doesn't know how to resolve it.
|
||||
enum { kUnresolvableFBOID = 0 };
|
||||
|
||||
struct GLRenderTargetIDs {
|
||||
GrGLuint fRTFBOID;
|
||||
GrGLuint fTexFBOID;
|
||||
GrGLuint fStencilRenderbufferID;
|
||||
GrGLuint fMSColorRenderbufferID;
|
||||
bool fOwnIDs;
|
||||
void reset() { memset(this, 0, sizeof(GLRenderTargetIDs)); }
|
||||
};
|
||||
|
||||
GrGLRenderTarget(GrGpuGL* gpu,
|
||||
const GLRenderTargetIDs& ids,
|
||||
GrGLTexID* texID,
|
||||
GrPixelConfig config,
|
||||
GrGLuint stencilBits,
|
||||
bool isMultisampled,
|
||||
const GrGLIRect& fViewport,
|
||||
GrGLTexture* texture);
|
||||
|
||||
virtual ~GrGLRenderTarget() { this->release(); }
|
||||
|
||||
void setViewport(const GrGLIRect& rect) { fViewport = rect; }
|
||||
const GrGLIRect& getViewport() const { return fViewport; }
|
||||
|
||||
// The following two functions return the same ID when a
|
||||
// texture-rendertarget is multisampled, and different IDs when
|
||||
// it is.
|
||||
// FBO ID used to render into
|
||||
GrGLuint renderFBOID() const { return fRTFBOID; }
|
||||
// FBO ID that has texture ID attached.
|
||||
GrGLuint textureFBOID() const { return fTexFBOID; }
|
||||
|
||||
// override of GrRenderTarget
|
||||
virtual intptr_t getRenderTargetHandle() const {
|
||||
return this->renderFBOID();
|
||||
}
|
||||
virtual intptr_t getRenderTargetResolvedHandle() const {
|
||||
return this->textureFBOID();
|
||||
}
|
||||
virtual ResolveType getResolveType() const {
|
||||
if (fRTFBOID == fTexFBOID) {
|
||||
// catches FBO 0 and non MSAA case
|
||||
return kAutoResolves_ResolveType;
|
||||
} else if (kUnresolvableFBOID == fTexFBOID) {
|
||||
return kCantResolve_ResolveType;
|
||||
} else {
|
||||
return kCanResolve_ResolveType;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
// override of GrResource
|
||||
virtual void onAbandon();
|
||||
virtual void onRelease();
|
||||
|
||||
private:
|
||||
GrGLuint fRTFBOID;
|
||||
GrGLuint fTexFBOID;
|
||||
GrGLuint fStencilRenderbufferID;
|
||||
GrGLuint fMSColorRenderbufferID;
|
||||
|
||||
// Should this object delete IDs when it is destroyed or does someone
|
||||
// else own them.
|
||||
bool fOwnIDs;
|
||||
|
||||
// when we switch to this rendertarget we want to set the viewport to
|
||||
// only render to to content area (as opposed to the whole allocation) and
|
||||
// we want the rendering to be at top left (GL has origin in bottom left)
|
||||
GrGLIRect fViewport;
|
||||
|
||||
// non-NULL if this RT was created by Gr with an associated GrGLTexture.
|
||||
GrGLTexID* fTexIDObj;
|
||||
|
||||
typedef GrRenderTarget INHERITED;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class GrGLTexture : public GrTexture {
|
||||
|
||||
@ -235,7 +149,6 @@ private:
|
||||
GrScalar fScaleX;
|
||||
GrScalar fScaleY;
|
||||
Orientation fOrientation;
|
||||
GrGpuGL* fGpuGL;
|
||||
|
||||
typedef GrTexture INHERITED;
|
||||
};
|
||||
|
58
gpu/src/GrRenderTarget.cpp
Normal file
58
gpu/src/GrRenderTarget.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#include "GrRenderTarget.h"
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "GrGpu.h"
|
||||
|
||||
bool GrRenderTarget::readPixels(int left, int top, int width, int height,
|
||||
GrPixelConfig config, void* buffer) {
|
||||
// go through context so that all necessary flushing occurs
|
||||
GrContext* context = this->getGpu()->getContext();
|
||||
GrAssert(NULL != context);
|
||||
return context->readRenderTargetPixels(this,
|
||||
left, top,
|
||||
width, height,
|
||||
config, buffer);
|
||||
}
|
||||
|
||||
size_t GrRenderTarget::sizeInBytes() const {
|
||||
int colorBits;
|
||||
if (kUnknown_GrPixelConfig == fConfig) {
|
||||
colorBits = 32; // don't know, make a guess
|
||||
} else {
|
||||
colorBits = GrBytesPerPixel(fConfig);
|
||||
}
|
||||
return fWidth * fHeight * (fStencilBits + colorBits);
|
||||
}
|
||||
|
||||
void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) {
|
||||
if (kCanResolve_ResolveType == getResolveType()) {
|
||||
if (NULL != rect) {
|
||||
fResolveRect.join(*rect);
|
||||
if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
|
||||
fResolveRect.setEmpty();
|
||||
}
|
||||
} else {
|
||||
fResolveRect.setLTRB(0, 0, this->width(), this->height());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GrRenderTarget::overrideResolveRect(const GrIRect rect) {
|
||||
fResolveRect = rect;
|
||||
if (fResolveRect.isEmpty()) {
|
||||
fResolveRect.setLargestInverted();
|
||||
} else {
|
||||
if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
|
||||
fResolveRect.setLargestInverted();
|
||||
}
|
||||
}
|
||||
}
|
@ -8,53 +8,10 @@
|
||||
|
||||
|
||||
#include "GrTexture.h"
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "GrGpu.h"
|
||||
|
||||
bool GrRenderTarget::readPixels(int left, int top, int width, int height,
|
||||
GrPixelConfig config, void* buffer) {
|
||||
// go through context so that all necessary flushing occurs
|
||||
GrContext* context = this->getGpu()->getContext();
|
||||
GrAssert(NULL != context);
|
||||
return context->readRenderTargetPixels(this,
|
||||
left, top,
|
||||
width, height,
|
||||
config, buffer);
|
||||
}
|
||||
|
||||
size_t GrRenderTarget::sizeInBytes() const {
|
||||
int colorBits;
|
||||
if (kUnknown_GrPixelConfig == fConfig) {
|
||||
colorBits = 32; // don't know, make a guess
|
||||
} else {
|
||||
colorBits = GrBytesPerPixel(fConfig);
|
||||
}
|
||||
return fWidth * fHeight * (fStencilBits + colorBits);
|
||||
}
|
||||
|
||||
void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) {
|
||||
if (kCanResolve_ResolveType == getResolveType()) {
|
||||
if (NULL != rect) {
|
||||
fResolveRect.join(*rect);
|
||||
if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
|
||||
fResolveRect.setEmpty();
|
||||
}
|
||||
} else {
|
||||
fResolveRect.setLTRB(0, 0, this->width(), this->height());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GrRenderTarget::overrideResolveRect(const GrIRect rect) {
|
||||
fResolveRect = rect;
|
||||
if (fResolveRect.isEmpty()) {
|
||||
fResolveRect.setLargestInverted();
|
||||
} else {
|
||||
if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
|
||||
fResolveRect.setLargestInverted();
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "GrRenderTarget.h"
|
||||
|
||||
bool GrTexture::readPixels(int left, int top, int width, int height,
|
||||
GrPixelConfig config, void* buffer) {
|
||||
@ -67,3 +24,18 @@ bool GrTexture::readPixels(int left, int top, int width, int height,
|
||||
config, buffer);
|
||||
}
|
||||
|
||||
void GrTexture::releaseRenderTarget() {
|
||||
if (NULL != fRenderTarget) {
|
||||
GrAssert(fRenderTarget->asTexture() == this);
|
||||
fRenderTarget->onTextureReleaseRenderTarget();
|
||||
fRenderTarget->unref();
|
||||
fRenderTarget = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void GrTexture::onAbandon() {
|
||||
if (NULL != fRenderTarget) {
|
||||
fRenderTarget->abandon();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,6 +115,7 @@
|
||||
'../gpu/include/GrRect.h',
|
||||
'../gpu/include/GrRectanizer.h',
|
||||
'../gpu/include/GrRefCnt.h',
|
||||
'../gpu/include/GrRenderTarget.h',
|
||||
'../gpu/include/GrResource.h',
|
||||
'../gpu/include/GrSamplerState.h',
|
||||
'../gpu/include/GrScalar.h',
|
||||
@ -150,6 +151,8 @@
|
||||
'../gpu/src/GrGLIRect.h',
|
||||
'../gpu/src/GrGLProgram.cpp',
|
||||
'../gpu/src/GrGLProgram.h',
|
||||
'../gpu/src/GrGLRenderTarget.cpp',
|
||||
'../gpu/src/GrGLRenderTarget.h',
|
||||
'../gpu/src/GrGLTexture.cpp',
|
||||
'../gpu/src/GrGLTexture.h',
|
||||
'../gpu/src/GrGLUtil.cpp',
|
||||
@ -171,6 +174,7 @@
|
||||
'../gpu/src/GrPathUtils.h',
|
||||
'../gpu/src/GrRectanizer.cpp',
|
||||
'../gpu/src/GrRedBlackTree.h',
|
||||
'../gpu/src/GrRenderTarget.cpp',
|
||||
'../gpu/src/GrResource.cpp',
|
||||
'../gpu/src/GrResourceCache.cpp',
|
||||
'../gpu/src/GrResourceCache.h',
|
||||
|
Loading…
Reference in New Issue
Block a user