2011-07-29 15:13:20 +00:00
|
|
|
/*
|
2012-12-13 19:24:05 +00:00
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2011-07-29 15:13:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrRenderTarget_DEFINED
|
|
|
|
#define GrRenderTarget_DEFINED
|
|
|
|
|
2012-06-21 21:09:06 +00:00
|
|
|
#include "GrSurface.h"
|
2013-07-17 21:39:42 +00:00
|
|
|
#include "SkRect.h"
|
2011-07-29 15:13:20 +00:00
|
|
|
|
2011-08-03 15:18:33 +00:00
|
|
|
class GrStencilBuffer;
|
2011-07-29 15:13:20 +00:00
|
|
|
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.
|
|
|
|
*/
|
2012-06-21 21:09:06 +00:00
|
|
|
class GrRenderTarget : public GrSurface {
|
2011-07-29 15:13:20 +00:00
|
|
|
public:
|
2012-06-13 18:54:08 +00:00
|
|
|
SK_DECLARE_INST_COUNT(GrRenderTarget)
|
2011-08-08 17:01:14 +00:00
|
|
|
|
2012-06-21 21:09:06 +00:00
|
|
|
// GrResource overrides
|
|
|
|
virtual size_t sizeInBytes() const SK_OVERRIDE;
|
|
|
|
|
|
|
|
// GrSurface overrides
|
2011-07-29 15:13:20 +00:00
|
|
|
/**
|
2012-10-26 19:01:17 +00:00
|
|
|
* @return the texture associated with the render target, may be NULL.
|
2011-07-29 15:13:20 +00:00
|
|
|
*/
|
2012-06-21 21:09:06 +00:00
|
|
|
virtual GrTexture* asTexture() SK_OVERRIDE { return fTexture; }
|
|
|
|
virtual const GrTexture* asTexture() const SK_OVERRIDE { return fTexture; }
|
|
|
|
|
2011-07-29 15:13:20 +00:00
|
|
|
/**
|
2012-06-21 21:09:06 +00:00
|
|
|
* @return this render target.
|
2011-07-29 15:13:20 +00:00
|
|
|
*/
|
2012-06-21 21:09:06 +00:00
|
|
|
virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return this; }
|
2012-08-23 18:09:54 +00:00
|
|
|
virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE {
|
|
|
|
return this;
|
2012-06-21 21:09:06 +00:00
|
|
|
}
|
2011-07-29 15:13:20 +00:00
|
|
|
|
2012-06-21 21:09:06 +00:00
|
|
|
virtual bool readPixels(int left, int top, int width, int height,
|
2012-08-20 19:22:38 +00:00
|
|
|
GrPixelConfig config,
|
|
|
|
void* buffer,
|
|
|
|
size_t rowBytes = 0,
|
|
|
|
uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
|
2011-07-29 15:13:20 +00:00
|
|
|
|
2012-06-21 21:09:06 +00:00
|
|
|
virtual void writePixels(int left, int top, int width, int height,
|
2012-08-20 19:22:38 +00:00
|
|
|
GrPixelConfig config,
|
|
|
|
const void* buffer,
|
|
|
|
size_t rowBytes = 0,
|
|
|
|
uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
|
2011-07-29 15:13:20 +00:00
|
|
|
|
2012-06-21 21:09:06 +00:00
|
|
|
// GrRenderTarget
|
2011-07-29 15:13:20 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2012-10-25 18:43:28 +00:00
|
|
|
virtual GrBackendObject getRenderTargetHandle() const = 0;
|
2011-07-29 15:13:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If this RT is multisampled, this is the buffer it is resolved to.
|
|
|
|
* Otherwise, same as getRenderTargetHandle().
|
2012-10-26 19:01:17 +00:00
|
|
|
* (In GL a separate FBO ID is used for the MSAA and resolved buffers)
|
2011-07-29 15:13:20 +00:00
|
|
|
* @return the 3D API's handle to this object (e.g. FBO ID in OpenGL)
|
|
|
|
*/
|
2012-10-25 18:43:28 +00:00
|
|
|
virtual GrBackendObject getRenderTargetResolvedHandle() const = 0;
|
2011-07-29 15:13:20 +00:00
|
|
|
|
|
|
|
/**
|
2012-06-21 21:09:06 +00:00
|
|
|
* @return true if the surface is multisampled, false otherwise
|
2011-07-29 15:13:20 +00:00
|
|
|
*/
|
2012-06-13 12:53:07 +00:00
|
|
|
bool isMultisampled() const { return 0 != fDesc.fSampleCnt; }
|
2011-07-29 20:29:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the number of samples-per-pixel or zero if non-MSAA.
|
|
|
|
*/
|
2012-06-13 12:53:07 +00:00
|
|
|
int numSamples() const { return fDesc.fSampleCnt; }
|
2011-07-29 15:13:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2012-10-25 18:43:28 +00:00
|
|
|
* when the render target has been modified outside of Gr. This has no
|
|
|
|
* effect on wrapped backend render targets.
|
|
|
|
*
|
2011-07-29 15:13:20 +00:00
|
|
|
* @param rect a rect bounding the area needing resolve. NULL indicates
|
|
|
|
* the whole RT needs resolving.
|
|
|
|
*/
|
2013-07-17 21:39:42 +00:00
|
|
|
void flagAsNeedingResolve(const SkIRect* rect = NULL);
|
2011-07-29 15:13:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call to override the region that needs to be resolved.
|
|
|
|
*/
|
2013-07-17 21:39:42 +00:00
|
|
|
void overrideResolveRect(const SkIRect rect);
|
2011-07-29 15:13:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-07-17 21:39:42 +00:00
|
|
|
const SkIRect& getResolveRect() const { return fResolveRect; }
|
2011-07-29 15:13:20 +00:00
|
|
|
|
2012-01-31 13:35:56 +00:00
|
|
|
/**
|
|
|
|
* If the render target is multisampled this will perform a multisample
|
|
|
|
* resolve. Any pending draws to the target are first flushed. This only
|
|
|
|
* applies to render targets that are associated with GrTextures. After the
|
|
|
|
* function returns the GrTexture will contain the resolved pixels.
|
|
|
|
*/
|
|
|
|
void resolve();
|
|
|
|
|
2011-07-29 15:13:20 +00:00
|
|
|
// a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
|
2012-08-23 18:09:54 +00:00
|
|
|
// 0 in GL), or be unresolvable because the client didn't give us the
|
2011-07-29 15:13:20 +00:00
|
|
|
// resolve destination.
|
|
|
|
enum ResolveType {
|
|
|
|
kCanResolve_ResolveType,
|
|
|
|
kAutoResolves_ResolveType,
|
|
|
|
kCantResolve_ResolveType,
|
|
|
|
};
|
|
|
|
virtual ResolveType getResolveType() const = 0;
|
|
|
|
|
2011-08-03 15:18:33 +00:00
|
|
|
/**
|
|
|
|
* GrStencilBuffer is not part of the public API.
|
|
|
|
*/
|
|
|
|
GrStencilBuffer* getStencilBuffer() const { return fStencilBuffer; }
|
|
|
|
void setStencilBuffer(GrStencilBuffer* stencilBuffer);
|
|
|
|
|
2011-07-29 15:13:20 +00:00
|
|
|
protected:
|
|
|
|
GrRenderTarget(GrGpu* gpu,
|
2013-01-23 20:25:22 +00:00
|
|
|
bool isWrapped,
|
2011-07-29 15:13:20 +00:00
|
|
|
GrTexture* texture,
|
2013-02-05 19:50:46 +00:00
|
|
|
const GrTextureDesc& desc)
|
|
|
|
: INHERITED(gpu, isWrapped, desc)
|
2011-08-03 15:18:33 +00:00
|
|
|
, fStencilBuffer(NULL)
|
2012-06-13 12:53:07 +00:00
|
|
|
, fTexture(texture) {
|
2011-07-29 15:13:20 +00:00
|
|
|
fResolveRect.setLargestInverted();
|
|
|
|
}
|
|
|
|
|
2012-09-05 15:46:34 +00:00
|
|
|
// override of GrResource
|
|
|
|
virtual void onAbandon() SK_OVERRIDE;
|
|
|
|
virtual void onRelease() SK_OVERRIDE;
|
|
|
|
|
2011-07-29 15:13:20 +00:00
|
|
|
private:
|
2013-04-09 15:04:12 +00:00
|
|
|
friend class GrTexture;
|
|
|
|
// called by ~GrTexture to remove the non-ref'ed back ptr.
|
|
|
|
void owningTextureDestroyed() {
|
2013-08-17 00:02:59 +00:00
|
|
|
SkASSERT(NULL != fTexture);
|
2013-04-09 15:04:12 +00:00
|
|
|
fTexture = NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-08 17:01:14 +00:00
|
|
|
GrStencilBuffer* fStencilBuffer;
|
|
|
|
GrTexture* fTexture; // not ref'ed
|
2012-06-13 12:53:07 +00:00
|
|
|
|
2013-07-17 21:39:42 +00:00
|
|
|
SkIRect fResolveRect;
|
2011-07-29 15:13:20 +00:00
|
|
|
|
2012-06-21 21:09:06 +00:00
|
|
|
typedef GrSurface INHERITED;
|
2011-07-29 15:13:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|