Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Revert 484688634c71ec38c18218eaa13dc47fa7007b74 #52680

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -40210,6 +40210,8 @@ ORIGIN: ../../../flutter/impeller/aiks/aiks_context.cc + ../../../flutter/LICENS
ORIGIN: ../../../flutter/impeller/aiks/aiks_context.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/aiks_playground.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/aiks_playground.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/aiks_playground_inspector.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/aiks_playground_inspector.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/canvas.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/canvas.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/aiks/canvas_benchmarks.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -40311,6 +40313,8 @@ ORIGIN: ../../../flutter/impeller/core/allocator.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/core/allocator.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/core/buffer_view.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/core/buffer_view.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/core/capture.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/core/capture.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/core/device_buffer.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/core/device_buffer.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/core/device_buffer_descriptor.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -43088,6 +43092,8 @@ FILE: ../../../flutter/impeller/aiks/aiks_context.cc
FILE: ../../../flutter/impeller/aiks/aiks_context.h
FILE: ../../../flutter/impeller/aiks/aiks_playground.cc
FILE: ../../../flutter/impeller/aiks/aiks_playground.h
FILE: ../../../flutter/impeller/aiks/aiks_playground_inspector.cc
FILE: ../../../flutter/impeller/aiks/aiks_playground_inspector.h
FILE: ../../../flutter/impeller/aiks/canvas.cc
FILE: ../../../flutter/impeller/aiks/canvas.h
FILE: ../../../flutter/impeller/aiks/canvas_benchmarks.cc
Expand Down Expand Up @@ -43189,6 +43195,8 @@ FILE: ../../../flutter/impeller/core/allocator.cc
FILE: ../../../flutter/impeller/core/allocator.h
FILE: ../../../flutter/impeller/core/buffer_view.cc
FILE: ../../../flutter/impeller/core/buffer_view.h
FILE: ../../../flutter/impeller/core/capture.cc
FILE: ../../../flutter/impeller/core/capture.h
FILE: ../../../flutter/impeller/core/device_buffer.cc
FILE: ../../../flutter/impeller/core/device_buffer.h
FILE: ../../../flutter/impeller/core/device_buffer_descriptor.cc
Expand Down
4 changes: 4 additions & 0 deletions impeller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ config("impeller_public_config") {
defines += [ "IMPELLER_DEBUG=1" ]
}

if (impeller_capture) {
defines += [ "IMPELLER_ENABLE_CAPTURE=1" ]
}

if (impeller_supports_rendering) {
defines += [ "IMPELLER_SUPPORTS_RENDERING=1" ]
}
Expand Down
2 changes: 2 additions & 0 deletions impeller/aiks/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ impeller_component("aiks_playground") {
sources = [
"aiks_playground.cc",
"aiks_playground.h",
"aiks_playground_inspector.cc",
"aiks_playground_inspector.h",
]
deps = [
":aiks",
Expand Down
6 changes: 4 additions & 2 deletions impeller/aiks/aiks_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void AiksPlayground::SetTypographerContext(
}

void AiksPlayground::TearDown() {
inspector_.HackResetDueToTextureLeaks();
PlaygroundTest::TearDown();
}

Expand All @@ -44,8 +45,9 @@ bool AiksPlayground::OpenPlaygroundHere(AiksPlaygroundCallback callback) {
}

return Playground::OpenPlaygroundHere(
[&renderer, &callback](RenderTarget& render_target) -> bool {
const std::optional<Picture>& picture = callback(renderer);
[this, &renderer, &callback](RenderTarget& render_target) -> bool {
const std::optional<Picture>& picture = inspector_.RenderInspector(
renderer, [&]() { return callback(renderer); });

if (!picture.has_value()) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions impeller/aiks/aiks_playground.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define FLUTTER_IMPELLER_AIKS_AIKS_PLAYGROUND_H_

#include "impeller/aiks/aiks_context.h"
#include "impeller/aiks/aiks_playground_inspector.h"
#include "impeller/aiks/picture.h"
#include "impeller/playground/playground_test.h"
#include "impeller/typographer/typographer_context.h"
Expand Down Expand Up @@ -37,6 +38,7 @@ class AiksPlayground : public PlaygroundTest {

private:
std::shared_ptr<TypographerContext> typographer_context_;
AiksInspector inspector_;

AiksPlayground(const AiksPlayground&) = delete;

Expand Down
277 changes: 277 additions & 0 deletions impeller/aiks/aiks_playground_inspector.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
// 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/aiks/aiks_playground_inspector.h"

#include <initializer_list>

#include "impeller/core/capture.h"
#include "impeller/entity/entity_pass.h"
#include "impeller/renderer/context.h"
#include "third_party/imgui/imgui.h"
#include "third_party/imgui/imgui_internal.h"

namespace impeller {

static const char* kElementsWindowName = "Elements";
static const char* kPropertiesWindowName = "Properties";

static const std::initializer_list<std::string> kSupportedDocuments = {
EntityPass::kCaptureDocumentName};

AiksInspector::AiksInspector() = default;

const std::optional<Picture>& AiksInspector::RenderInspector(
AiksContext& aiks_context,
const std::function<std::optional<Picture>()>& picture_callback) {
//----------------------------------------------------------------------------
/// Configure the next frame.
///

RenderCapture(aiks_context.GetContext()->capture);

//----------------------------------------------------------------------------
/// Configure the next frame.
///

if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
wireframe_ = !wireframe_;
aiks_context.GetContentContext().SetWireframe(wireframe_);
}

if (ImGui::IsKeyPressed(ImGuiKey_C)) {
capturing_ = !capturing_;
if (capturing_) {
aiks_context.GetContext()->capture =
CaptureContext::MakeAllowlist({kSupportedDocuments});
}
}
if (!capturing_) {
hovered_element_ = nullptr;
selected_element_ = nullptr;
aiks_context.GetContext()->capture = CaptureContext::MakeInactive();
std::optional<Picture> new_picture = picture_callback();

// If the new picture doesn't have a pass, that means it was already moved
// into the inspector. Simply re-emit the last received valid picture.
if (!new_picture.has_value() || new_picture->pass) {
last_picture_ = std::move(new_picture);
}
}

return last_picture_;
}

void AiksInspector::HackResetDueToTextureLeaks() {
last_picture_.reset();
}

static const auto kPropertiesProcTable = CaptureProcTable{
.boolean =
[](CaptureBooleanProperty& p) {
ImGui::Checkbox(p.label.c_str(), &p.value);
},
.integer =
[](CaptureIntegerProperty& p) {
if (p.options.range.has_value()) {
ImGui::SliderInt(p.label.c_str(), &p.value,
static_cast<int>(p.options.range->min),
static_cast<int>(p.options.range->max));
return;
}
ImGui::InputInt(p.label.c_str(), &p.value);
},
.scalar =
[](CaptureScalarProperty& p) {
if (p.options.range.has_value()) {
ImGui::SliderFloat(p.label.c_str(), &p.value, p.options.range->min,
p.options.range->max);
return;
}
ImGui::DragFloat(p.label.c_str(), &p.value, 0.01);
},
.point =
[](CapturePointProperty& p) {
if (p.options.range.has_value()) {
ImGui::SliderFloat2(p.label.c_str(),
reinterpret_cast<float*>(&p.value),
p.options.range->min, p.options.range->max);
return;
}
ImGui::DragFloat2(p.label.c_str(), reinterpret_cast<float*>(&p.value),
0.01);
},
.vector3 =
[](CaptureVector3Property& p) {
if (p.options.range.has_value()) {
ImGui::SliderFloat3(p.label.c_str(),
reinterpret_cast<float*>(&p.value),
p.options.range->min, p.options.range->max);
return;
}
ImGui::DragFloat3(p.label.c_str(), reinterpret_cast<float*>(&p.value),
0.01);
},
.rect =
[](CaptureRectProperty& p) {
ImGui::DragFloat4(p.label.c_str(), reinterpret_cast<float*>(&p.value),
0.01);
},
.color =
[](CaptureColorProperty& p) {
ImGui::ColorEdit4(p.label.c_str(),
reinterpret_cast<float*>(&p.value));
},
.matrix =
[](CaptureMatrixProperty& p) {
float* pointer = reinterpret_cast<float*>(&p.value);
ImGui::DragFloat4((p.label + " X basis").c_str(), pointer, 0.001);
ImGui::DragFloat4((p.label + " Y basis").c_str(), pointer + 4, 0.001);
ImGui::DragFloat4((p.label + " Z basis").c_str(), pointer + 8, 0.001);
ImGui::DragFloat4((p.label + " Translation").c_str(), pointer + 12,
0.001);
},
.string =
[](CaptureStringProperty& p) {
ImGui::InputTextEx(p.label.c_str(), "",
// Fine as long as it's read-only.
const_cast<char*>(p.value.c_str()), p.value.size(),
ImVec2(0, 0), ImGuiInputTextFlags_ReadOnly);
},
};

void AiksInspector::RenderCapture(CaptureContext& capture_context) {
if (!capturing_) {
return;
}

auto document = capture_context.GetDocument(EntityPass::kCaptureDocumentName);

//----------------------------------------------------------------------------
/// Setup a shared dockspace to collect the capture windows.
///

ImGui::SetNextWindowBgAlpha(0.5);
ImGui::Begin("Capture");
auto dockspace_id = ImGui::GetID("CaptureDockspace");
if (!ImGui::DockBuilderGetNode(dockspace_id)) {
ImGui::SetWindowSize(ImVec2(370, 680));
ImGui::SetWindowPos(ImVec2(640, 55));

ImGui::DockBuilderRemoveNode(dockspace_id);
ImGui::DockBuilderAddNode(dockspace_id);

ImGuiID opposite_id;
ImGuiID up_id = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Up, 0.6,
nullptr, &opposite_id);
ImGuiID down_id = ImGui::DockBuilderSplitNode(opposite_id, ImGuiDir_Down,
0.0, nullptr, nullptr);
ImGui::DockBuilderDockWindow(kElementsWindowName, up_id);
ImGui::DockBuilderDockWindow(kPropertiesWindowName, down_id);

ImGui::DockBuilderFinish(dockspace_id);
}
ImGui::DockSpace(dockspace_id);
ImGui::End(); // Capture window.

//----------------------------------------------------------------------------
/// Element hierarchy window.
///

ImGui::Begin(kElementsWindowName);
auto root_element = document.GetElement();
hovered_element_ = nullptr;
if (root_element) {
RenderCaptureElement(*root_element);
}
ImGui::End(); // Hierarchy window.

if (selected_element_) {
//----------------------------------------------------------------------------
/// Properties window.
///

ImGui::Begin(kPropertiesWindowName);
{
selected_element_->properties.Iterate([&](CaptureProperty& property) {
property.Invoke(kPropertiesProcTable);
});
}
ImGui::End(); // Inspector window.

//----------------------------------------------------------------------------
/// Selected coverage highlighting.
///

auto coverage_property =
selected_element_->properties.FindFirstByLabel("Coverage");
if (coverage_property) {
auto coverage = coverage_property->AsRect();
if (coverage.has_value()) {
Scalar scale = ImGui::GetWindowDpiScale();
ImGui::GetBackgroundDrawList()->AddRect(
ImVec2(coverage->GetLeft() / scale,
coverage->GetTop() / scale), // p_min
ImVec2(coverage->GetRight() / scale,
coverage->GetBottom() / scale), // p_max
0x992222FF, // col
0.0, // rounding
ImDrawFlags_None, // flags
8.0); // thickness
}
}
}

//----------------------------------------------------------------------------
/// Hover coverage highlight.
///

if (hovered_element_) {
auto coverage_property =
hovered_element_->properties.FindFirstByLabel("Coverage");
if (coverage_property) {
auto coverage = coverage_property->AsRect();
if (coverage.has_value()) {
Scalar scale = ImGui::GetWindowDpiScale();
ImGui::GetBackgroundDrawList()->AddRect(
ImVec2(coverage->GetLeft() / scale,
coverage->GetTop() / scale), // p_min
ImVec2(coverage->GetRight() / scale,
coverage->GetBottom() / scale), // p_max
0x66FF2222, // col
0.0, // rounding
ImDrawFlags_None, // flags
8.0); // thickness
}
}
}
}

void AiksInspector::RenderCaptureElement(CaptureElement& element) {
ImGui::PushID(&element);

bool is_selected = selected_element_ == &element;
bool has_children = element.children.Count() > 0;

bool opened = ImGui::TreeNodeEx(
element.label.c_str(), (is_selected ? ImGuiTreeNodeFlags_Selected : 0) |
(has_children ? 0 : ImGuiTreeNodeFlags_Leaf) |
ImGuiTreeNodeFlags_SpanFullWidth |
ImGuiTreeNodeFlags_OpenOnArrow |
ImGuiTreeNodeFlags_DefaultOpen);
if (ImGui::IsItemClicked()) {
selected_element_ = &element;
}
if (ImGui::IsItemHovered()) {
hovered_element_ = &element;
}
if (opened) {
element.children.Iterate(
[&](CaptureElement& child) { RenderCaptureElement(child); });
ImGui::TreePop();
}
ImGui::PopID();
}

} // namespace impeller
Loading