bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 GrGLTextureRenderTarget_DEFINED |
| 10 | #define GrGLTextureRenderTarget_DEFINED |
| 11 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 12 | #include "GrGLGpu.h" |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 13 | #include "GrGLTexture.h" |
| 14 | #include "GrGLRenderTarget.h" |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 15 | #include "GrTexturePriv.h" |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 16 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 17 | class GrGLGpu; |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 18 | |
| 19 | #ifdef SK_BUILD_FOR_WIN |
| 20 | // Windows gives bogus warnings about inheriting asTexture/asRenderTarget via dominance. |
| 21 | #pragma warning(push) |
| 22 | #pragma warning(disable: 4250) |
| 23 | #endif |
| 24 | |
| 25 | class GrGLTextureRenderTarget : public GrGLTexture, public GrGLRenderTarget { |
| 26 | public: |
| 27 | // We're virtually derived from GrSurface (via both GrGLTexture and GrGLRenderTarget) so its |
| 28 | // constructor must be explicitly called. |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 29 | GrGLTextureRenderTarget(GrGLGpu* gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 30 | SkBudgeted budgeted, |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 31 | const GrSurfaceDesc& desc, |
| 32 | const GrGLTexture::IDDesc& texIDDesc, |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 33 | const GrGLRenderTarget::IDDesc& rtIDDesc, |
| 34 | bool wasMipMapDataProvided) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 35 | : GrSurface(gpu, desc) |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 36 | , GrGLTexture(gpu, desc, texIDDesc, wasMipMapDataProvided) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 37 | , GrGLRenderTarget(gpu, desc, rtIDDesc) { |
| 38 | this->registerWithCache(budgeted); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 39 | } |
| 40 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 41 | bool canAttemptStencilAttachment() const override; |
| 42 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 43 | void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; |
| 44 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 45 | static sk_sp<GrGLTextureRenderTarget> MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc, |
| 46 | const GrGLTexture::IDDesc& texIDDesc, |
| 47 | const GrGLRenderTarget::IDDesc& rtIDDesc); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 48 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 49 | void onAbandon() override { |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 50 | GrGLRenderTarget::onAbandon(); |
| 51 | GrGLTexture::onAbandon(); |
| 52 | } |
| 53 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 54 | void onRelease() override { |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 55 | GrGLRenderTarget::onRelease(); |
| 56 | GrGLTexture::onRelease(); |
| 57 | } |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 58 | |
| 59 | private: |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 60 | // Constructor for instances wrapping backend objects. |
| 61 | GrGLTextureRenderTarget(GrGLGpu* gpu, |
| 62 | const GrSurfaceDesc& desc, |
| 63 | const GrGLTexture::IDDesc& texIDDesc, |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 64 | const GrGLRenderTarget::IDDesc& rtIDDesc, |
| 65 | bool wasMipMapDataProvided) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 66 | : GrSurface(gpu, desc) |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 67 | , GrGLTexture(gpu, desc, texIDDesc, wasMipMapDataProvided) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 68 | , GrGLRenderTarget(gpu, desc, rtIDDesc) { |
| 69 | this->registerWithCacheWrapped(); |
| 70 | } |
| 71 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 72 | size_t onGpuMemorySize() const override { |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 73 | return GrSurface::ComputeSize(fDesc, |
| 74 | this->numSamplesOwnedPerPixel(), |
| 75 | this->texturePriv().hasMipMaps()); |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 76 | } |
| 77 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | #ifdef SK_BUILD_FOR_WIN |
| 81 | #pragma warning(pop) |
| 82 | #endif |
| 83 | |
| 84 | #endif |