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 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 16 | #include "GrTexturePriv.h" |
| 17 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 18 | #ifdef SK_BUILD_FOR_WIN |
| 19 | // Windows gives bogus warnings about inheriting asTexture/asRenderTarget via dominance. |
| 20 | #pragma warning(push) |
| 21 | #pragma warning(disable: 4250) |
| 22 | #endif |
| 23 | |
| 24 | class GrVkImageView; |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 25 | struct GrVkImageInfo; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 26 | |
| 27 | class GrVkTextureRenderTarget: public GrVkTexture, public GrVkRenderTarget { |
| 28 | public: |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame^] | 29 | static sk_sp<GrVkTextureRenderTarget> CreateNewTextureRenderTarget(GrVkGpu*, SkBudgeted, |
| 30 | const GrSurfaceDesc&, |
| 31 | const GrVkImage::ImageDesc&); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 32 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 33 | static sk_sp<GrVkTextureRenderTarget> MakeWrappedTextureRenderTarget(GrVkGpu*, |
| 34 | const GrSurfaceDesc&, |
| 35 | GrWrapOwnership, |
| 36 | const GrVkImageInfo*); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 37 | |
egdaniel | 50ead53 | 2016-07-13 14:23:26 -0700 | [diff] [blame] | 38 | bool updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo); |
| 39 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 40 | protected: |
| 41 | void onAbandon() override { |
| 42 | GrVkRenderTarget::onAbandon(); |
| 43 | GrVkTexture::onAbandon(); |
| 44 | } |
| 45 | |
| 46 | void onRelease() override { |
| 47 | GrVkRenderTarget::onRelease(); |
| 48 | GrVkTexture::onRelease(); |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | GrVkTextureRenderTarget(GrVkGpu* gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 53 | SkBudgeted budgeted, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 54 | const GrSurfaceDesc& desc, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 55 | const GrVkImageInfo& info, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 56 | const GrVkImageView* texView, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 57 | const GrVkImageInfo& msaaInfo, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 58 | const GrVkImageView* colorAttachmentView, |
| 59 | const GrVkImageView* resolveAttachmentView) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 60 | : GrSurface(gpu, desc) |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 61 | , GrVkImage(info, GrVkImage::kNot_Wrapped) |
| 62 | , GrVkTexture(gpu, desc, info, texView, GrVkImage::kNot_Wrapped) |
| 63 | , GrVkRenderTarget(gpu, desc, info, msaaInfo, colorAttachmentView, |
| 64 | resolveAttachmentView, GrVkImage::kNot_Wrapped) { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 65 | this->registerWithCache(budgeted); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | GrVkTextureRenderTarget(GrVkGpu* gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 69 | SkBudgeted budgeted, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 70 | const GrSurfaceDesc& desc, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 71 | const GrVkImageInfo& info, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 72 | const GrVkImageView* texView, |
| 73 | const GrVkImageView* colorAttachmentView) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 74 | : GrSurface(gpu, desc) |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 75 | , GrVkImage(info, GrVkImage::kNot_Wrapped) |
| 76 | , GrVkTexture(gpu, desc, info, texView, GrVkImage::kNot_Wrapped) |
| 77 | , GrVkRenderTarget(gpu, desc, info, colorAttachmentView, GrVkImage::kNot_Wrapped) { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 78 | this->registerWithCache(budgeted); |
| 79 | } |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 80 | GrVkTextureRenderTarget(GrVkGpu* gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 81 | const GrSurfaceDesc& desc, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 82 | const GrVkImageInfo& info, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 83 | const GrVkImageView* texView, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 84 | const GrVkImageInfo& msaaInfo, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 85 | const GrVkImageView* colorAttachmentView, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 86 | const GrVkImageView* resolveAttachmentView, |
| 87 | GrVkImage::Wrapped wrapped) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 88 | : GrSurface(gpu, desc) |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 89 | , GrVkImage(info, wrapped) |
| 90 | , GrVkTexture(gpu, desc, info, texView, wrapped) |
| 91 | , GrVkRenderTarget(gpu, desc, info, msaaInfo, colorAttachmentView, |
| 92 | resolveAttachmentView, wrapped) { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 93 | this->registerWithCacheWrapped(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 94 | } |
| 95 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 96 | GrVkTextureRenderTarget(GrVkGpu* gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 97 | const GrSurfaceDesc& desc, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 98 | const GrVkImageInfo& info, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 99 | const GrVkImageView* texView, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 100 | const GrVkImageView* colorAttachmentView, |
| 101 | GrVkImage::Wrapped wrapped) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 102 | : GrSurface(gpu, desc) |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 103 | , GrVkImage(info, wrapped) |
| 104 | , GrVkTexture(gpu, desc, info, texView, wrapped) |
| 105 | , GrVkRenderTarget(gpu, desc, info, colorAttachmentView, wrapped) { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 106 | this->registerWithCacheWrapped(); |
| 107 | } |
| 108 | |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame^] | 109 | static sk_sp<GrVkTextureRenderTarget> Make(GrVkGpu*, |
| 110 | const GrSurfaceDesc&, |
| 111 | const GrVkImageInfo&, |
| 112 | SkBudgeted budgeted, |
| 113 | GrVkImage::Wrapped wrapped); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 114 | |
| 115 | // GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory. |
| 116 | size_t onGpuMemorySize() const override { |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 117 | // The plus 1 is to account for the resolve texture. |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 118 | int numColorSamples = this->numColorSamples() + 1; |
| 119 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
| 120 | numColorSamples, // TODO: this still correct? |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 121 | this->texturePriv().hasMipMaps()); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 122 | } |
| 123 | }; |
| 124 | |
| 125 | #endif |