blob: 08dd3769e22d9a42cb3f741bb62f990a01e5c35b [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include "flutter/fml/macros.h"
#include "impeller/base/backend_cast.h"
#include "impeller/renderer/backend/vulkan/context_vk.h"
#include "impeller/renderer/backend/vulkan/device_buffer_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain_vk.h"
#include "impeller/renderer/backend/vulkan/vk.h"
#include "impeller/renderer/texture.h"
namespace impeller {
enum class TextureBackingTypeVK {
kUnknownType,
kAllocatedTexture,
kWrappedTexture,
};
struct WrappedTextureInfoVK {
SwapchainImageVK* swapchain_image = nullptr;
uint32_t frame_num = 0;
};
struct AllocatedTextureInfoVK {
DeviceBufferAllocationVK staging_buffer = {};
BackingAllocationVK backing_allocation = {};
VkImage image = VK_NULL_HANDLE;
VkImageView image_view = VK_NULL_HANDLE;
};
struct TextureInfoVK {
TextureBackingTypeVK backing_type;
union {
WrappedTextureInfoVK wrapped_texture;
AllocatedTextureInfoVK allocated_texture;
};
};
class TextureVK final : public Texture, public BackendCast<TextureVK, Texture> {
public:
TextureVK(TextureDescriptor desc,
ContextVK* context,
std::unique_ptr<TextureInfoVK> texture_info);
// |Texture|
~TextureVK() override;
bool IsWrapped() const;
vk::Image GetImage() const;
vk::ImageView GetImageView() const;
vk::Buffer GetStagingBuffer() const;
TextureInfoVK* GetTextureInfo() const;
private:
ContextVK* context_;
std::unique_ptr<TextureInfoVK> texture_info_;
// |Texture|
void SetLabel(std::string_view label) override;
// |Texture|
bool OnSetContents(const uint8_t* contents,
size_t length,
size_t slice) override;
// |Texture|
bool OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
size_t slice) override;
// |Texture|
bool IsValid() const override;
// |Texture|
ISize GetSize() const override;
FML_DISALLOW_COPY_AND_ASSIGN(TextureVK);
};
} // namespace impeller