1aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com/* 2dd335aeb5d34a8344f98244d722fd205b8e05135reed@google.com * Copyright 2011 Google Inc. 3dd335aeb5d34a8344f98244d722fd205b8e05135reed@google.com * 4dd335aeb5d34a8344f98244d722fd205b8e05135reed@google.com * Use of this source code is governed by a BSD-style license that can be 5dd335aeb5d34a8344f98244d722fd205b8e05135reed@google.com * found in the LICENSE file. 6aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com */ 7aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 8aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#ifndef GrRenderTarget_DEFINED 9aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#define GrRenderTarget_DEFINED 10aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 117d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com#include "GrSurface.h" 12fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org#include "SkRect.h" 13aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 148dc7c3a839b38b73af34cc2674a06f49eb1ce527egdanielclass GrStencilAttachment; 156bc1b5fab8554a9cb643277b4867965dd4535cd6bsalomonclass GrRenderTargetPriv; 16aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 17aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com/** 18aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * GrRenderTarget represents a 2D buffer of pixels that can be rendered to. 19aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * A context's render target is set by setRenderTarget(). Render targets are 2037dd331b20a92ce79cc26556e065dec98a66cb0bbsalomon * created by a createTexture with the kRenderTarget_SurfaceFlag flag. 21aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * Additionally, GrContext provides methods for creating GrRenderTargets 22aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * that wrap externally created render targets. 23aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com */ 2437dd331b20a92ce79cc26556e065dec98a66cb0bbsalomonclass GrRenderTarget : virtual public GrSurface { 25aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.compublic: 264d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com SK_DECLARE_INST_COUNT(GrRenderTarget) 27558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com 287d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com // GrSurface overrides 2936352bf5e38f45a70ee4f4fc132a38048d38206dmtklein GrRenderTarget* asRenderTarget() override { return this; } 3036352bf5e38f45a70ee4f4fc132a38048d38206dmtklein const GrRenderTarget* asRenderTarget() const override { return this; } 31aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 327d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com // GrRenderTarget 33aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com /** 347d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @return true if the surface is multisampled, false otherwise 35aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com */ 36e98ade4fdee03a234f68669bea84d07db4a8527erobertphillips@google.com bool isMultisampled() const { return 0 != fDesc.fSampleCnt; } 375bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com 385bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com /** 395bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com * @return the number of samples-per-pixel or zero if non-MSAA. 405bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com */ 41e98ade4fdee03a234f68669bea84d07db4a8527erobertphillips@google.com int numSamples() const { return fDesc.fSampleCnt; } 42aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 43aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com /** 44aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * Call to indicate the multisample contents were modified such that the 45aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * render target needs to be resolved before it can be used as texture. Gr 46aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * tracks this for its own drawing and thus this only needs to be called 4716e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com * when the render target has been modified outside of Gr. This has no 4816e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com * effect on wrapped backend render targets. 4916e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com * 50aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * @param rect a rect bounding the area needing resolve. NULL indicates 51aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * the whole RT needs resolving. 52aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com */ 53fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org void flagAsNeedingResolve(const SkIRect* rect = NULL); 54aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 55aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com /** 56aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * Call to override the region that needs to be resolved. 57aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com */ 58fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org void overrideResolveRect(const SkIRect rect); 59aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 60aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com /** 61aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * Call to indicate that GrRenderTarget was externally resolved. This may 62aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * allow Gr to skip a redundant resolve step. 63aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com */ 64aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com void flagAsResolved() { fResolveRect.setLargestInverted(); } 65aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 66aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com /** 67aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * @return true if the GrRenderTarget requires MSAA resolving 68aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com */ 69aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com bool needsResolve() const { return !fResolveRect.isEmpty(); } 70aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 71aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com /** 72aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com * Returns a rect bounding the region needing resolving. 73aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com */ 74fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkIRect& getResolveRect() const { return fResolveRect; } 75aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 7675f9f25d8bf2adc0494f9afbbd5965809ee13acabsalomon@google.com /** 7728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * Provide a performance hint that the render target's contents are allowed 7828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * to become undefined. 7928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org */ 8028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org void discard(); 8128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org 82aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO 83fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com // 0 in GL), or be unresolvable because the client didn't give us the 84aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com // resolve destination. 85aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com enum ResolveType { 86aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com kCanResolve_ResolveType, 87aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com kAutoResolves_ResolveType, 88aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com kCantResolve_ResolveType, 89aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com }; 90aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com virtual ResolveType getResolveType() const = 0; 91aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 926bc1b5fab8554a9cb643277b4867965dd4535cd6bsalomon // Provides access to functions that aren't part of the public API. 936bc1b5fab8554a9cb643277b4867965dd4535cd6bsalomon GrRenderTargetPriv renderTargetPriv(); 946bc1b5fab8554a9cb643277b4867965dd4535cd6bsalomon const GrRenderTargetPriv renderTargetPriv() const; 9581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com 96aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.comprotected: 975236cf480daf82b2f36e42795abdbbc915533a59bsalomon GrRenderTarget(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc) 985236cf480daf82b2f36e42795abdbbc915533a59bsalomon : INHERITED(gpu, lifeCycle, desc) 998dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel , fStencilAttachment(NULL) { 100aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com fResolveRect.setLargestInverted(); 101aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com } 102aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 103d6bbbf8a831cc982cda9b91e84c5600c631af5b2robertphillips@google.com // override of GrResource 10436352bf5e38f45a70ee4f4fc132a38048d38206dmtklein void onAbandon() override; 10536352bf5e38f45a70ee4f4fc132a38048d38206dmtklein void onRelease() override; 106d6bbbf8a831cc982cda9b91e84c5600c631af5b2robertphillips@google.com 107aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.comprivate: 1086bc1b5fab8554a9cb643277b4867965dd4535cd6bsalomon // Checked when this object is asked to attach a stencil buffer. 1096bc1b5fab8554a9cb643277b4867965dd4535cd6bsalomon virtual bool canAttemptStencilAttachment() const = 0; 1106bc1b5fab8554a9cb643277b4867965dd4535cd6bsalomon 1116bc1b5fab8554a9cb643277b4867965dd4535cd6bsalomon friend class GrRenderTargetPriv; 1126bc1b5fab8554a9cb643277b4867965dd4535cd6bsalomon 1138dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel GrStencilAttachment* fStencilAttachment; 114e98ade4fdee03a234f68669bea84d07db4a8527erobertphillips@google.com 1158dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel SkIRect fResolveRect; 116aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 1177d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com typedef GrSurface INHERITED; 118aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com}; 119aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com 120aa5b6730f2658618015ed56ffb5882f15b6f053fbsalomon@google.com#endif 121