1 /* 2 * Copyright 2011 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 9 #ifndef GrGLRenderTarget_DEFINED 10 #define GrGLRenderTarget_DEFINED 11 12 #include "GrGLIRect.h" 13 #include "GrRenderTarget.h" 14 #include "SkScalar.h" 15 16 class GrGLCaps; 17 class GrGLGpu; 18 class GrGLStencilAttachment; 19 20 class GrGLRenderTarget : public GrRenderTarget { 21 public: 22 // set fTexFBOID to this value to indicate that it is multisampled but 23 // Gr doesn't know how to resolve it. 24 enum { kUnresolvableFBOID = 0 }; 25 26 struct IDDesc { 27 GrGLuint fRTFBOID; 28 GrBackendObjectOwnership fRTFBOOwnership; 29 GrGLuint fTexFBOID; 30 GrGLuint fMSColorRenderbufferID; 31 bool fIsMixedSampled; 32 }; 33 34 static sk_sp<GrGLRenderTarget> MakeWrapped(GrGLGpu*, 35 const GrSurfaceDesc&, 36 const IDDesc&, 37 int stencilBits); 38 setViewport(const GrGLIRect & rect)39 void setViewport(const GrGLIRect& rect) { fViewport = rect; } getViewport()40 const GrGLIRect& getViewport() const { return fViewport; } 41 42 // The following two functions return the same ID when a texture/render target is not 43 // multisampled, and different IDs when it is multisampled. 44 // FBO ID used to render into renderFBOID()45 GrGLuint renderFBOID() const { return fRTFBOID; } 46 // FBO ID that has texture ID attached. textureFBOID()47 GrGLuint textureFBOID() const { return fTexFBOID; } 48 49 // override of GrRenderTarget getResolveType()50 ResolveType getResolveType() const override { 51 if (GrFSAAType::kUnifiedMSAA != this->fsaaType() || fRTFBOID == fTexFBOID) { 52 // catches FBO 0 and non unified-MSAA case 53 return kAutoResolves_ResolveType; 54 } else if (kUnresolvableFBOID == fTexFBOID) { 55 return kCantResolve_ResolveType; 56 } else { 57 return kCanResolve_ResolveType; 58 } 59 } 60 getRenderTargetHandle()61 GrBackendObject getRenderTargetHandle() const override { return fRTFBOID; } 62 63 bool canAttemptStencilAttachment() const override; 64 65 // GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer 66 // components seperately. 67 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; 68 69 protected: 70 // Constructor for subclasses. 71 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); 72 73 void init(const GrSurfaceDesc&, const IDDesc&); 74 75 void onAbandon() override; 76 void onRelease() override; 77 numSamplesOwnedPerPixel()78 int numSamplesOwnedPerPixel() const { return fNumSamplesOwnedPerPixel; } 79 80 private: 81 // Constructor for instances wrapping backend objects. 82 GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrGLStencilAttachment*); 83 84 static GrRenderTargetFlags ComputeFlags(const GrGLCaps&, const IDDesc&); 85 86 GrGLGpu* getGLGpu() const; 87 bool completeStencilAttachment() override; 88 89 size_t onGpuMemorySize() const override; 90 91 int msaaSamples() const; 92 // The number total number of samples, including both MSAA and resolve texture samples. 93 int totalSamples() const; 94 95 GrGLuint fRTFBOID; 96 GrGLuint fTexFBOID; 97 GrGLuint fMSColorRenderbufferID; 98 99 GrBackendObjectOwnership fRTFBOOwnership; 100 101 // when we switch to this render target we want to set the viewport to 102 // only render to content area (as opposed to the whole allocation) and 103 // we want the rendering to be at top left (GL has origin in bottom left) 104 GrGLIRect fViewport; 105 106 // The RenderTarget needs to be able to report its VRAM footprint even after abandon and 107 // release have potentially zeroed out the IDs (e.g., so the cache can reset itself). Since 108 // the IDs are just required for the computation in totalSamples we cache that result here. 109 int fNumSamplesOwnedPerPixel; 110 111 typedef GrRenderTarget INHERITED; 112 }; 113 114 #endif 115