Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 GrVkTextureRenderTarget_DEFINED |
| 10 | #define GrVkTextureRenderTarget_DEFINED |
| 11 | |
| 12 | #include "GrVkTexture.h" |
| 13 | #include "GrVkRenderTarget.h" |
| 14 | #include "GrVkGpu.h" |
| 15 | |
| 16 | #ifdef SK_BUILD_FOR_WIN |
| 17 | // Windows gives bogus warnings about inheriting asTexture/asRenderTarget via dominance. |
| 18 | #pragma warning(push) |
| 19 | #pragma warning(disable: 4250) |
| 20 | #endif |
| 21 | |
| 22 | class GrVkImageView; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 23 | struct GrVkTextureInfo; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 24 | |
| 25 | class GrVkTextureRenderTarget: public GrVkTexture, public GrVkRenderTarget { |
| 26 | public: |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame^] | 27 | static GrVkTextureRenderTarget* CreateNewTextureRenderTarget(GrVkGpu*, SkBudgeted, |
| 28 | const GrSurfaceDesc&, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 29 | const GrVkImage::ImageDesc&); |
| 30 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 31 | static GrVkTextureRenderTarget* CreateWrappedTextureRenderTarget(GrVkGpu*, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 32 | const GrSurfaceDesc&, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame^] | 33 | GrWrapOwnership, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 34 | VkFormat, |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 35 | const GrVkTextureInfo*); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 36 | |
| 37 | protected: |
| 38 | void onAbandon() override { |
| 39 | GrVkRenderTarget::onAbandon(); |
| 40 | GrVkTexture::onAbandon(); |
| 41 | } |
| 42 | |
| 43 | void onRelease() override { |
| 44 | GrVkRenderTarget::onRelease(); |
| 45 | GrVkTexture::onRelease(); |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | GrVkTextureRenderTarget(GrVkGpu* gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame^] | 50 | SkBudgeted budgeted, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 51 | const GrSurfaceDesc& desc, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 52 | const GrVkImage::Resource* imageResource, |
| 53 | const GrVkImageView* texView, |
| 54 | const GrVkImage::Resource* msaaResource, |
| 55 | const GrVkImageView* colorAttachmentView, |
| 56 | const GrVkImageView* resolveAttachmentView) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame^] | 57 | : GrSurface(gpu, desc) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 58 | , GrVkImage(imageResource) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame^] | 59 | , GrVkTexture(gpu, desc, imageResource, texView) |
| 60 | , GrVkRenderTarget(gpu, desc, imageResource, msaaResource, colorAttachmentView, |
| 61 | resolveAttachmentView) { |
| 62 | this->registerWithCache(budgeted); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | GrVkTextureRenderTarget(GrVkGpu* gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame^] | 66 | SkBudgeted budgeted, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 67 | const GrSurfaceDesc& desc, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 68 | const GrVkImage::Resource* imageResource, |
| 69 | const GrVkImageView* texView, |
| 70 | const GrVkImageView* colorAttachmentView) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame^] | 71 | : GrSurface(gpu, desc) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 72 | , GrVkImage(imageResource) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame^] | 73 | , GrVkTexture(gpu, desc, imageResource, texView) |
| 74 | , GrVkRenderTarget(gpu, desc, imageResource, colorAttachmentView) { |
| 75 | this->registerWithCache(budgeted); |
| 76 | } |
| 77 | enum Wrapped { kWrapped }; |
| 78 | GrVkTextureRenderTarget(GrVkGpu* gpu, |
| 79 | Wrapped, |
| 80 | const GrSurfaceDesc& desc, |
| 81 | const GrVkImage::Resource* imageResource, |
| 82 | const GrVkImageView* texView, |
| 83 | const GrVkImage::Resource* msaaResource, |
| 84 | const GrVkImageView* colorAttachmentView, |
| 85 | const GrVkImageView* resolveAttachmentView) |
| 86 | : GrSurface(gpu, desc) |
| 87 | , GrVkImage(imageResource) |
| 88 | , GrVkTexture(gpu, desc, imageResource, texView) |
| 89 | , GrVkRenderTarget(gpu, desc, imageResource, msaaResource, colorAttachmentView, |
| 90 | resolveAttachmentView) { |
| 91 | this->registerWithCacheWrapped(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 92 | } |
| 93 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame^] | 94 | GrVkTextureRenderTarget(GrVkGpu* gpu, |
| 95 | Wrapped, |
| 96 | const GrSurfaceDesc& desc, |
| 97 | const GrVkImage::Resource* imageResource, |
| 98 | const GrVkImageView* texView, |
| 99 | const GrVkImageView* colorAttachmentView) |
| 100 | : GrSurface(gpu, desc) |
| 101 | , GrVkImage(imageResource) |
| 102 | , GrVkTexture(gpu, desc, imageResource, texView) |
| 103 | , GrVkRenderTarget(gpu, desc, imageResource, colorAttachmentView) { |
| 104 | this->registerWithCacheWrapped(); |
| 105 | } |
| 106 | |
| 107 | template <typename ResourceType> |
| 108 | static GrVkTextureRenderTarget* Create(GrVkGpu*, |
| 109 | ResourceType, |
| 110 | const GrSurfaceDesc&, |
| 111 | VkFormat, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 112 | const GrVkImage::Resource* imageResource); |
| 113 | |
| 114 | // GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory. |
| 115 | size_t onGpuMemorySize() const override { |
| 116 | return GrVkRenderTarget::onGpuMemorySize(); |
| 117 | } |
| 118 | }; |
| 119 | |
| 120 | #endif |