bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 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" |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 14 | #include "SkScalar.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 15 | |
| 16 | class GrGpuGL; |
| 17 | class GrGLTexture; |
| 18 | class GrGLTexID; |
| 19 | |
| 20 | class GrGLRenderTarget : public GrRenderTarget { |
| 21 | |
| 22 | public: |
| 23 | // set fTexFBOID to this value to indicate that it is multisampled but |
| 24 | // Gr doesn't know how to resolve it. |
| 25 | enum { kUnresolvableFBOID = 0 }; |
| 26 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 27 | struct Desc { |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 28 | GrGLuint fRTFBOID; |
| 29 | GrGLuint fTexFBOID; |
| 30 | GrGLuint fMSColorRenderbufferID; |
| 31 | bool fIsWrapped; |
| 32 | GrPixelConfig fConfig; |
| 33 | int fSampleCnt; |
| 34 | GrSurfaceOrigin fOrigin; |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 35 | bool fCheckAllocation; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 38 | // creates a GrGLRenderTarget associated with a texture |
| 39 | GrGLRenderTarget(GrGpuGL* gpu, |
| 40 | const Desc& desc, |
| 41 | const GrGLIRect& viewport, |
| 42 | GrGLTexID* texID, |
| 43 | GrGLTexture* texture); |
| 44 | |
| 45 | // creates an independent GrGLRenderTarget |
| 46 | GrGLRenderTarget(GrGpuGL* gpu, |
| 47 | const Desc& desc, |
| 48 | const GrGLIRect& viewport); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 49 | |
| 50 | virtual ~GrGLRenderTarget() { this->release(); } |
| 51 | |
| 52 | void setViewport(const GrGLIRect& rect) { fViewport = rect; } |
| 53 | const GrGLIRect& getViewport() const { return fViewport; } |
| 54 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 55 | // The following two functions return the same ID when a |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 56 | // texture/render target is multisampled, and different IDs when |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 57 | // it is. |
| 58 | // FBO ID used to render into |
| 59 | GrGLuint renderFBOID() const { return fRTFBOID; } |
| 60 | // FBO ID that has texture ID attached. |
| 61 | GrGLuint textureFBOID() const { return fTexFBOID; } |
| 62 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 63 | // override of GrRenderTarget |
bsalomon@google.com | 08afc84 | 2012-10-25 18:56:10 +0000 | [diff] [blame] | 64 | virtual GrBackendObject getRenderTargetHandle() const { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 65 | return this->renderFBOID(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 66 | } |
bsalomon@google.com | 08afc84 | 2012-10-25 18:56:10 +0000 | [diff] [blame] | 67 | virtual GrBackendObject getRenderTargetResolvedHandle() const { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 68 | return this->textureFBOID(); |
| 69 | } |
| 70 | virtual ResolveType getResolveType() const { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 71 | |
| 72 | if (!this->isMultisampled() || |
| 73 | fRTFBOID == fTexFBOID) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 74 | // catches FBO 0 and non MSAA case |
| 75 | return kAutoResolves_ResolveType; |
| 76 | } else if (kUnresolvableFBOID == fTexFBOID) { |
| 77 | return kCantResolve_ResolveType; |
| 78 | } else { |
| 79 | return kCanResolve_ResolveType; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | protected: |
| 84 | // override of GrResource |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 85 | virtual void onAbandon() SK_OVERRIDE; |
| 86 | virtual void onRelease() SK_OVERRIDE; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 87 | |
| 88 | private: |
| 89 | GrGLuint fRTFBOID; |
| 90 | GrGLuint fTexFBOID; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 91 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 92 | GrGLuint fMSColorRenderbufferID; |
| 93 | |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 94 | // when we switch to this render target we want to set the viewport to |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 95 | // only render to to content area (as opposed to the whole allocation) and |
| 96 | // we want the rendering to be at top left (GL has origin in bottom left) |
| 97 | GrGLIRect fViewport; |
| 98 | |
| 99 | // non-NULL if this RT was created by Gr with an associated GrGLTexture. |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 100 | SkAutoTUnref<GrGLTexID> fTexIDObj; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 101 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 102 | void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID); |
| 103 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 104 | typedef GrRenderTarget INHERITED; |
| 105 | }; |
| 106 | |
| 107 | #endif |