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