blob: ba084ff442b33be8dc560a66ec4204a9e4cf5d9e [file] [log] [blame] [edit]
// 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.
#include "impeller/renderer/render_pass.h"
namespace impeller {
RenderPass::RenderPass(std::weak_ptr<const Context> context,
RenderTarget target)
: context_(std::move(context)),
render_target_(std::move(target)),
transients_buffer_(HostBuffer::Create()) {}
RenderPass::~RenderPass() = default;
const RenderTarget& RenderPass::GetRenderTarget() const {
return render_target_;
}
ISize RenderPass::GetRenderTargetSize() const {
return render_target_.GetRenderTargetSize();
}
HostBuffer& RenderPass::GetTransientsBuffer() {
return *transients_buffer_;
}
void RenderPass::SetLabel(std::string label) {
if (label.empty()) {
return;
}
transients_buffer_->SetLabel(SPrintF("%s Transients", label.c_str()));
OnSetLabel(std::move(label));
}
bool RenderPass::AddCommand(Command command) {
if (!command) {
VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
return false;
}
if (command.scissor.has_value()) {
auto target_rect = IRect({}, render_target_.GetRenderTargetSize());
if (!target_rect.Contains(command.scissor.value())) {
VALIDATION_LOG << "Cannot apply a scissor that lies outside the bounds "
"of the render target.";
return false;
}
}
if (command.index_count == 0u) {
// Essentially a no-op. Don't record the command but this is not necessary
// an error either.
return true;
}
if (command.instance_count == 0u) {
// Essentially a no-op. Don't record the command but this is not necessary
// an error either.
return true;
}
commands_.emplace_back(std::move(command));
return true;
}
bool RenderPass::EncodeCommands() const {
auto context = context_.lock();
// The context could have been collected in the meantime.
if (!context) {
return false;
}
return OnEncodeCommands(*context);
}
} // namespace impeller