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 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 16 | class GrGLGpu; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 17 | |
| 18 | class GrGLRenderTarget : public GrRenderTarget { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 19 | public: |
| 20 | // set fTexFBOID to this value to indicate that it is multisampled but |
| 21 | // Gr doesn't know how to resolve it. |
| 22 | enum { kUnresolvableFBOID = 0 }; |
| 23 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 24 | struct IDDesc { |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 25 | GrGLuint fRTFBOID; |
| 26 | GrGLuint fTexFBOID; |
| 27 | GrGLuint fMSColorRenderbufferID; |
| 28 | bool fIsWrapped; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 31 | GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 32 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 33 | void setViewport(const GrGLIRect& rect) { fViewport = rect; } |
| 34 | const GrGLIRect& getViewport() const { return fViewport; } |
| 35 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 36 | // The following two functions return the same ID when a |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 37 | // texture/render target is multisampled, and different IDs when |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 38 | // it is. |
| 39 | // FBO ID used to render into |
| 40 | GrGLuint renderFBOID() const { return fRTFBOID; } |
| 41 | // FBO ID that has texture ID attached. |
| 42 | GrGLuint textureFBOID() const { return fTexFBOID; } |
| 43 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 44 | // override of GrRenderTarget |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 45 | GrBackendObject getRenderTargetHandle() const SK_OVERRIDE { return this->renderFBOID(); } |
| 46 | GrBackendObject getRenderTargetResolvedHandle() const SK_OVERRIDE { return this->textureFBOID(); } |
| 47 | ResolveType getResolveType() const SK_OVERRIDE { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 48 | if (!this->isMultisampled() || |
| 49 | fRTFBOID == fTexFBOID) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 50 | // catches FBO 0 and non MSAA case |
| 51 | return kAutoResolves_ResolveType; |
| 52 | } else if (kUnresolvableFBOID == fTexFBOID) { |
| 53 | return kCantResolve_ResolveType; |
| 54 | } else { |
| 55 | return kCanResolve_ResolveType; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | protected: |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 60 | // The public constructor registers this object with the cache. However, only the most derived |
| 61 | // class should register with the cache. This constructor does not do the registration and |
| 62 | // rather moves that burden onto the derived class. |
| 63 | enum Derived { kDerived }; |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 64 | GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 65 | |
| 66 | void init(const GrSurfaceDesc&, const IDDesc&); |
| 67 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 68 | void onAbandon() SK_OVERRIDE; |
| 69 | void onRelease() SK_OVERRIDE; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 70 | |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 71 | // In protected because subclass GrGLTextureRenderTarget calls this version. |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 72 | size_t onGpuMemorySize() const SK_OVERRIDE; |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 73 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 74 | private: |
| 75 | GrGLuint fRTFBOID; |
| 76 | GrGLuint fTexFBOID; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 77 | GrGLuint fMSColorRenderbufferID; |
| 78 | |
hendrikw | 9a0c7ab | 2014-12-09 14:26:47 -0800 | [diff] [blame] | 79 | // We track this separately from GrGpuResource because this may be both a texture and a render |
| 80 | // target, and the texture may be wrapped while the render target is not. |
| 81 | bool fIsWrapped; |
| 82 | |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 83 | // when we switch to this render target we want to set the viewport to |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 84 | // only render to content area (as opposed to the whole allocation) and |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 85 | // we want the rendering to be at top left (GL has origin in bottom left) |
| 86 | GrGLIRect fViewport; |
| 87 | |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 88 | // onGpuMemorySize() needs to know what how many color values are owned per pixel. However, |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 89 | // abandon and release zero out the IDs and the cache needs to know the size even after those |
| 90 | // actions. |
| 91 | uint8_t fColorValuesPerPixel; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 92 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 93 | typedef GrRenderTarget INHERITED; |
| 94 | }; |
| 95 | |
| 96 | #endif |