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 #ifndef GrRenderTarget_DEFINED 9 #define GrRenderTarget_DEFINED 10 11 #include "include/core/SkRect.h" 12 #include "src/gpu/GrSurface.h" 13 14 class GrCaps; 15 class GrRenderTargetPriv; 16 class GrStencilAttachment; 17 class GrBackendRenderTarget; 18 19 /** 20 * GrRenderTarget represents a 2D buffer of pixels that can be rendered to. 21 * A context's render target is set by setRenderTarget(). Render targets are 22 * created by a createTexture with the kRenderTarget_SurfaceFlag flag. 23 * Additionally, GrContext provides methods for creating GrRenderTargets 24 * that wrap externally created render targets. 25 */ 26 class GrRenderTarget : virtual public GrSurface { 27 public: 28 // Make manual MSAA resolve publicly accessible from GrRenderTarget. 29 using GrSurface::setRequiresManualMSAAResolve; 30 using GrSurface::requiresManualMSAAResolve; 31 alwaysClearStencil()32 virtual bool alwaysClearStencil() const { return false; } 33 34 // GrSurface overrides asRenderTarget()35 GrRenderTarget* asRenderTarget() override { return this; } asRenderTarget()36 const GrRenderTarget* asRenderTarget() const override { return this; } 37 38 /** 39 * Returns the number of samples/pixel in the color buffer (One if non-MSAA). 40 */ numSamples()41 int numSamples() const { return fSampleCnt; } 42 43 virtual GrBackendRenderTarget getBackendRenderTarget() const = 0; 44 45 // Checked when this object is asked to attach a stencil buffer. 46 virtual bool canAttemptStencilAttachment() const = 0; 47 48 // Provides access to functions that aren't part of the public API. 49 GrRenderTargetPriv renderTargetPriv(); 50 const GrRenderTargetPriv renderTargetPriv() const; 51 52 protected: 53 GrRenderTarget(GrGpu*, const SkISize&, int sampleCount, GrProtected, 54 GrStencilAttachment* = nullptr); 55 ~GrRenderTarget() override; 56 57 // override of GrResource 58 void onAbandon() override; 59 void onRelease() override; 60 61 private: 62 // Allows the backends to perform any additional work that is required for attaching a 63 // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto 64 // the GrRenderTarget. This function must return false if any failures occur when completing the 65 // stencil attachment. 66 virtual bool completeStencilAttachment() = 0; 67 68 friend class GrRenderTargetPriv; 69 70 int fSampleCnt; 71 int fSamplePatternKey; 72 sk_sp<GrStencilAttachment> fStencilAttachment; 73 74 typedef GrSurface INHERITED; 75 }; 76 77 #endif 78