1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/gl/GrGLRenderTarget.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +/* 1.5 + * Copyright 2011 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 + 1.12 +#ifndef GrGLRenderTarget_DEFINED 1.13 +#define GrGLRenderTarget_DEFINED 1.14 + 1.15 +#include "GrGLIRect.h" 1.16 +#include "GrRenderTarget.h" 1.17 +#include "SkScalar.h" 1.18 + 1.19 +class GrGpuGL; 1.20 +class GrGLTexture; 1.21 +class GrGLTexID; 1.22 + 1.23 +class GrGLRenderTarget : public GrRenderTarget { 1.24 + 1.25 +public: 1.26 + // set fTexFBOID to this value to indicate that it is multisampled but 1.27 + // Gr doesn't know how to resolve it. 1.28 + enum { kUnresolvableFBOID = 0 }; 1.29 + 1.30 + struct Desc { 1.31 + GrGLuint fRTFBOID; 1.32 + GrGLuint fTexFBOID; 1.33 + GrGLuint fMSColorRenderbufferID; 1.34 + bool fIsWrapped; 1.35 + GrPixelConfig fConfig; 1.36 + int fSampleCnt; 1.37 + GrSurfaceOrigin fOrigin; 1.38 + bool fCheckAllocation; 1.39 + }; 1.40 + 1.41 + // creates a GrGLRenderTarget associated with a texture 1.42 + GrGLRenderTarget(GrGpuGL* gpu, 1.43 + const Desc& desc, 1.44 + const GrGLIRect& viewport, 1.45 + GrGLTexID* texID, 1.46 + GrGLTexture* texture); 1.47 + 1.48 + // creates an independent GrGLRenderTarget 1.49 + GrGLRenderTarget(GrGpuGL* gpu, 1.50 + const Desc& desc, 1.51 + const GrGLIRect& viewport); 1.52 + 1.53 + virtual ~GrGLRenderTarget() { this->release(); } 1.54 + 1.55 + void setViewport(const GrGLIRect& rect) { fViewport = rect; } 1.56 + const GrGLIRect& getViewport() const { return fViewport; } 1.57 + 1.58 + // The following two functions return the same ID when a 1.59 + // texture/render target is multisampled, and different IDs when 1.60 + // it is. 1.61 + // FBO ID used to render into 1.62 + GrGLuint renderFBOID() const { return fRTFBOID; } 1.63 + // FBO ID that has texture ID attached. 1.64 + GrGLuint textureFBOID() const { return fTexFBOID; } 1.65 + 1.66 + // override of GrRenderTarget 1.67 + virtual GrBackendObject getRenderTargetHandle() const { 1.68 + return this->renderFBOID(); 1.69 + } 1.70 + virtual GrBackendObject getRenderTargetResolvedHandle() const { 1.71 + return this->textureFBOID(); 1.72 + } 1.73 + virtual ResolveType getResolveType() const { 1.74 + 1.75 + if (!this->isMultisampled() || 1.76 + fRTFBOID == fTexFBOID) { 1.77 + // catches FBO 0 and non MSAA case 1.78 + return kAutoResolves_ResolveType; 1.79 + } else if (kUnresolvableFBOID == fTexFBOID) { 1.80 + return kCantResolve_ResolveType; 1.81 + } else { 1.82 + return kCanResolve_ResolveType; 1.83 + } 1.84 + } 1.85 + 1.86 +protected: 1.87 + // override of GrResource 1.88 + virtual void onAbandon() SK_OVERRIDE; 1.89 + virtual void onRelease() SK_OVERRIDE; 1.90 + 1.91 +private: 1.92 + GrGLuint fRTFBOID; 1.93 + GrGLuint fTexFBOID; 1.94 + 1.95 + GrGLuint fMSColorRenderbufferID; 1.96 + 1.97 + // when we switch to this render target we want to set the viewport to 1.98 + // only render to to content area (as opposed to the whole allocation) and 1.99 + // we want the rendering to be at top left (GL has origin in bottom left) 1.100 + GrGLIRect fViewport; 1.101 + 1.102 + // non-NULL if this RT was created by Gr with an associated GrGLTexture. 1.103 + SkAutoTUnref<GrGLTexID> fTexIDObj; 1.104 + 1.105 + void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID); 1.106 + 1.107 + typedef GrRenderTarget INHERITED; 1.108 +}; 1.109 + 1.110 +#endif