blob: 838814e45f0d6b6057e1695716877247610c47c3 [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.
#ifndef FLUTTER_IMPELLER_ENTITY_RENDER_TARGET_CACHE_H_
#define FLUTTER_IMPELLER_ENTITY_RENDER_TARGET_CACHE_H_
#include "impeller/renderer/render_target.h"
namespace impeller {
/// @brief An implementation of the [RenderTargetAllocator] that caches all
/// allocated texture data for one frame.
///
/// Any textures unused after a frame are immediately discarded.
class RenderTargetCache : public RenderTargetAllocator {
public:
explicit RenderTargetCache(std::shared_ptr<Allocator> allocator);
~RenderTargetCache() = default;
// |RenderTargetAllocator|
void Start() override;
// |RenderTargetAllocator|
void End() override;
RenderTarget CreateOffscreen(
const Context& context,
ISize size,
int mip_count,
const std::string& label = "Offscreen",
RenderTarget::AttachmentConfig color_attachment_config =
RenderTarget::kDefaultColorAttachmentConfig,
std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config =
RenderTarget::kDefaultStencilAttachmentConfig,
const std::shared_ptr<Texture>& existing_color_texture = nullptr,
const std::shared_ptr<Texture>& existing_depth_stencil_texture =
nullptr) override;
RenderTarget CreateOffscreenMSAA(
const Context& context,
ISize size,
int mip_count,
const std::string& label = "Offscreen MSAA",
RenderTarget::AttachmentConfigMSAA color_attachment_config =
RenderTarget::kDefaultColorAttachmentConfigMSAA,
std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config =
RenderTarget::kDefaultStencilAttachmentConfig,
const std::shared_ptr<Texture>& existing_color_msaa_texture = nullptr,
const std::shared_ptr<Texture>& existing_color_resolve_texture = nullptr,
const std::shared_ptr<Texture>& existing_depth_stencil_texture =
nullptr) override;
// visible for testing.
size_t CachedTextureCount() const;
private:
struct RenderTargetData {
bool used_this_frame;
RenderTargetConfig config;
RenderTarget render_target;
};
std::vector<RenderTargetData> render_target_data_;
RenderTargetCache(const RenderTargetCache&) = delete;
RenderTargetCache& operator=(const RenderTargetCache&) = delete;
public:
/// Visible for testing.
std::vector<RenderTargetData>::const_iterator GetRenderTargetDataBegin()
const {
return render_target_data_.begin();
}
/// Visible for testing.
std::vector<RenderTargetData>::const_iterator GetRenderTargetDataEnd() const {
return render_target_data_.end();
}
};
} // namespace impeller
#endif // FLUTTER_IMPELLER_ENTITY_RENDER_TARGET_CACHE_H_