Greg Daniel | 48cf268 | 2016-02-22 09:11:32 -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; |
| 23 | |
| 24 | class GrVkTextureRenderTarget: public GrVkTexture, public GrVkRenderTarget { |
| 25 | public: |
| 26 | static GrVkTextureRenderTarget* CreateNewTextureRenderTarget(GrVkGpu*, const GrSurfaceDesc&, |
| 27 | GrGpuResource::LifeCycle, |
| 28 | const GrVkImage::ImageDesc&); |
| 29 | |
| 30 | static GrVkTextureRenderTarget* CreateWrappedTextureRenderTarget(GrVkGpu*, |
| 31 | const GrSurfaceDesc&, |
| 32 | GrGpuResource::LifeCycle, |
| 33 | VkFormat, |
| 34 | GrVkImage::Resource*); |
| 35 | |
| 36 | protected: |
| 37 | void onAbandon() override { |
| 38 | GrVkRenderTarget::onAbandon(); |
| 39 | GrVkTexture::onAbandon(); |
| 40 | } |
| 41 | |
| 42 | void onRelease() override { |
| 43 | GrVkRenderTarget::onRelease(); |
| 44 | GrVkTexture::onRelease(); |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | GrVkTextureRenderTarget(GrVkGpu* gpu, |
| 49 | const GrSurfaceDesc& desc, |
| 50 | GrGpuResource::LifeCycle lifeCycle, |
| 51 | const GrVkImage::Resource* imageResource, |
| 52 | const GrVkImageView* texView, |
| 53 | const GrVkImage::Resource* msaaResource, |
| 54 | const GrVkImageView* colorAttachmentView, |
| 55 | const GrVkImageView* resolveAttachmentView) |
| 56 | : GrSurface(gpu, lifeCycle, desc) |
| 57 | , GrVkImage(imageResource) |
| 58 | , GrVkTexture(gpu, desc, lifeCycle, imageResource, texView, GrVkTexture::kDerived) |
| 59 | , GrVkRenderTarget(gpu, desc, lifeCycle, imageResource, msaaResource, colorAttachmentView, |
| 60 | resolveAttachmentView, GrVkRenderTarget::kDerived) { |
| 61 | this->registerWithCache(); |
| 62 | } |
| 63 | |
| 64 | GrVkTextureRenderTarget(GrVkGpu* gpu, |
| 65 | const GrSurfaceDesc& desc, |
| 66 | GrGpuResource::LifeCycle lifeCycle, |
| 67 | const GrVkImage::Resource* imageResource, |
| 68 | const GrVkImageView* texView, |
| 69 | const GrVkImageView* colorAttachmentView) |
| 70 | : GrSurface(gpu, lifeCycle, desc) |
| 71 | , GrVkImage(imageResource) |
| 72 | , GrVkTexture(gpu, desc, lifeCycle, imageResource, texView, GrVkTexture::kDerived) |
| 73 | , GrVkRenderTarget(gpu, desc, lifeCycle, imageResource, colorAttachmentView, |
| 74 | GrVkRenderTarget::kDerived) { |
| 75 | this->registerWithCache(); |
| 76 | } |
| 77 | |
| 78 | static GrVkTextureRenderTarget* Create(GrVkGpu*, const GrSurfaceDesc&, |
| 79 | GrGpuResource::LifeCycle, |
| 80 | VkFormat format, |
| 81 | const GrVkImage::Resource* imageResource); |
| 82 | |
| 83 | // GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory. |
| 84 | size_t onGpuMemorySize() const override { |
| 85 | return GrVkRenderTarget::onGpuMemorySize(); |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | #endif |