Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrVkImage_DEFINED | 8 #ifndef GrVkImage_DEFINED |
| 9 #define GrVkImage_DEFINED | 9 #define GrVkImage_DEFINED |
| 10 | 10 |
| 11 #include "GrVkResource.h" | 11 #include "GrVkResource.h" |
| 12 | 12 |
| 13 #include "GrTypesPriv.h" | 13 #include "GrTypesPriv.h" |
| 14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 15 | 15 |
| 16 #include "vk/GrVkDefines.h" | 16 #include "vk/GrVkDefines.h" |
| 17 #include "vk/GrVkTypes.h" | |
| 17 | 18 |
| 18 class GrVkGpu; | 19 class GrVkGpu; |
| 19 | 20 |
| 20 class GrVkImage : SkNoncopyable { | 21 class GrVkImage : SkNoncopyable { |
| 22 private: | |
| 23 class Resource; | |
| 24 | |
| 21 public: | 25 public: |
| 22 // unlike GrVkBuffer, this needs to be public so GrVkStencilAttachment can u se it | 26 GrVkImage(const GrVkImageInfo& info, bool isBorrowed) : fInfo(info), fIsBorr owed(isBorrowed) { |
|
jvanverth1
2016/05/13 16:14:40
Suggestion: make isBorrowed an enum rather than a
egdaniel
2016/05/13 18:00:05
Done.
| |
| 23 class Resource : public GrVkResource { | 27 if (isBorrowed) { |
| 24 public: | 28 fResource = new BorrowedResource(info.fImage, info.fAlloc); |
| 25 enum Flags { | 29 } else { |
| 26 kNo_Flags = 0, | 30 fResource = new Resource(info.fImage, info.fAlloc); |
| 27 kLinearTiling_Flag = 0x01, | 31 } |
| 28 kBorrowed_Flag = 0x02 | 32 } |
| 29 }; | 33 virtual ~GrVkImage(); |
| 30 | 34 |
| 31 VkImage fImage; | 35 VkImage image() const { return fInfo.fImage; } |
| 32 VkDeviceMemory fAlloc; | 36 VkDeviceMemory memory() const { return fInfo.fAlloc; } |
| 33 VkFormat fFormat; | 37 VkFormat imageFormat() const { return fInfo.fFormat; } |
| 34 uint32_t fLevelCount; | 38 const Resource* resource() const { return fResource; } |
| 35 uint32_t fFlags; | 39 bool isLinearTiled() const { |
| 36 | 40 return SkToBool(VK_IMAGE_TILING_LINEAR == fInfo.fImageTiling); |
| 37 Resource() | |
| 38 : INHERITED() | |
| 39 , fImage(VK_NULL_HANDLE) | |
| 40 , fAlloc(VK_NULL_HANDLE) | |
| 41 , fFormat(VK_FORMAT_UNDEFINED) | |
| 42 , fLevelCount(0) | |
| 43 , fFlags(kNo_Flags) {} | |
| 44 | |
| 45 Resource(VkImage image, VkDeviceMemory alloc, VkFormat format, uint32_t levelCount, | |
| 46 uint32_t flags) | |
| 47 : fImage(image), fAlloc(alloc), fFormat(format), fLevelCount(levelCo unt) | |
| 48 , fFlags(flags) {} | |
| 49 | |
| 50 ~Resource() override {} | |
| 51 | |
| 52 private: | |
| 53 void freeGPUData(const GrVkGpu* gpu) const override; | |
| 54 | |
| 55 typedef GrVkResource INHERITED; | |
| 56 }; | |
| 57 | |
| 58 // for wrapped textures | |
| 59 class BorrowedResource : public Resource { | |
| 60 public: | |
| 61 BorrowedResource(VkImage image, VkDeviceMemory alloc, VkFormat format, u int32_t levelCount, | |
| 62 uint32_t flags) | |
| 63 : Resource(image, alloc, format, levelCount, (flags | kBorrowed_Flag )) { | |
| 64 } | |
| 65 private: | |
| 66 void freeGPUData(const GrVkGpu* gpu) const override; | |
| 67 }; | |
| 68 | |
| 69 GrVkImage(const Resource* imageResource) : fResource(imageResource) { | |
| 70 if (imageResource->fFlags & Resource::kLinearTiling_Flag) { | |
| 71 fCurrentLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; | |
| 72 } else { | |
| 73 fCurrentLayout = VK_IMAGE_LAYOUT_UNDEFINED; | |
| 74 } | |
| 75 imageResource->ref(); | |
| 76 } | 41 } |
| 77 | 42 |
| 78 virtual ~GrVkImage(); | 43 VkImageLayout currentLayout() const { return fInfo.fImageLayout; } |
| 79 | |
| 80 VkImage textureImage() const { return fResource->fImage; } | |
| 81 VkDeviceMemory textureMemory() const { return fResource->fAlloc; } | |
| 82 const Resource* resource() const { return fResource; } | |
| 83 bool isLinearTiled() const { | |
| 84 return SkToBool(fResource->fFlags & Resource::kLinearTiling_Flag); | |
| 85 } | |
| 86 | |
| 87 VkImageLayout currentLayout() const { return fCurrentLayout; } | |
| 88 | 44 |
| 89 void setImageLayout(const GrVkGpu* gpu, | 45 void setImageLayout(const GrVkGpu* gpu, |
| 90 VkImageLayout newLayout, | 46 VkImageLayout newLayout, |
| 91 VkAccessFlags dstAccessMask, | 47 VkAccessFlags dstAccessMask, |
| 92 VkPipelineStageFlags dstStageMask, | 48 VkPipelineStageFlags dstStageMask, |
| 93 bool byRegion); | 49 bool byRegion); |
| 94 | 50 |
| 95 struct ImageDesc { | 51 struct ImageDesc { |
| 96 VkImageType fImageType; | 52 VkImageType fImageType; |
| 97 VkFormat fFormat; | 53 VkFormat fFormat; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 108 , fFormat(VK_FORMAT_UNDEFINED) | 64 , fFormat(VK_FORMAT_UNDEFINED) |
| 109 , fWidth(0) | 65 , fWidth(0) |
| 110 , fHeight(0) | 66 , fHeight(0) |
| 111 , fLevels(1) | 67 , fLevels(1) |
| 112 , fSamples(1) | 68 , fSamples(1) |
| 113 , fImageTiling(VK_IMAGE_TILING_OPTIMAL) | 69 , fImageTiling(VK_IMAGE_TILING_OPTIMAL) |
| 114 , fUsageFlags(0) | 70 , fUsageFlags(0) |
| 115 , fMemProps(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {} | 71 , fMemProps(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {} |
| 116 }; | 72 }; |
| 117 | 73 |
| 118 static const Resource* CreateResource(const GrVkGpu* gpu, const ImageDesc& i mageDesc); | 74 static bool GetImageInfo(const GrVkGpu* gpu, const ImageDesc& imageDesc, GrV kImageInfo*); |
| 119 | 75 |
| 120 protected: | 76 protected: |
| 121 | |
| 122 void releaseImage(const GrVkGpu* gpu); | 77 void releaseImage(const GrVkGpu* gpu); |
| 123 void abandonImage(); | 78 void abandonImage(); |
| 124 | 79 |
| 80 void setNewResource(VkImage image, VkDeviceMemory alloc); | |
| 81 | |
| 82 GrVkImageInfo fInfo; | |
| 83 bool fIsBorrowed; | |
| 84 | |
| 85 private: | |
| 86 // unlike GrVkBuffer, this needs to be public so GrVkStencilAttachment can u se it | |
| 87 class Resource : public GrVkResource { | |
| 88 public: | |
| 89 Resource() | |
| 90 : INHERITED() | |
| 91 , fImage(VK_NULL_HANDLE) | |
| 92 , fAlloc(VK_NULL_HANDLE) { | |
| 93 } | |
| 94 | |
| 95 Resource(VkImage image, VkDeviceMemory alloc) : fImage(image), fAlloc(al loc) {} | |
| 96 | |
| 97 ~Resource() override {} | |
| 98 | |
| 99 private: | |
| 100 void freeGPUData(const GrVkGpu* gpu) const override; | |
| 101 | |
| 102 VkImage fImage; | |
| 103 VkDeviceMemory fAlloc; | |
| 104 | |
| 105 typedef GrVkResource INHERITED; | |
| 106 }; | |
| 107 | |
| 108 // for wrapped textures | |
| 109 class BorrowedResource : public Resource { | |
| 110 public: | |
| 111 BorrowedResource(VkImage image, VkDeviceMemory alloc) : Resource(image, alloc) { | |
| 112 } | |
| 113 private: | |
| 114 void freeGPUData(const GrVkGpu* gpu) const override; | |
| 115 }; | |
| 116 | |
| 125 const Resource* fResource; | 117 const Resource* fResource; |
| 126 | 118 |
| 127 VkImageLayout fCurrentLayout; | 119 friend class GrVkRenderTarget; |
| 128 }; | 120 }; |
| 129 | 121 |
| 130 #endif | 122 #endif |
| OLD | NEW |