更完
This commit is contained in:
@@ -97,10 +97,6 @@ std::string_view frame_mode_name(Gallery_Frame_Mode mode) {
|
||||
return "low_latency";
|
||||
}
|
||||
} // namespace
|
||||
struct Gallery_Pixel_Copy {
|
||||
Pixel_Frame_Copy image;
|
||||
Color background;
|
||||
};
|
||||
class Gallery_Scene final {
|
||||
public:
|
||||
Gallery_Scene(std::uint64_t session_id, std::string case_id,
|
||||
@@ -220,19 +216,19 @@ public:
|
||||
rendered_since_last_pixel_ = true;
|
||||
return rendered;
|
||||
}
|
||||
[[nodiscard]] std::optional<Gallery_Pixel_Copy> copy_latest_pixels() {
|
||||
[[nodiscard]] std::optional<std::string> encode_latest_pixels() {
|
||||
if (!plot_.view_active())
|
||||
return std::nullopt;
|
||||
if (!rendered_since_last_pixel_ && !can_render_automatically() &&
|
||||
!render_latest_frame())
|
||||
return std::nullopt;
|
||||
rendered_since_last_pixel_ = false;
|
||||
Gallery_Pixel_Copy copy;
|
||||
copy.background = plot_.background_color();
|
||||
plot_.with_frame([©](Image_View image) {
|
||||
copy.image = copy_pixel_frame(image);
|
||||
std::string pixels;
|
||||
const Color background = plot_.background_color();
|
||||
plot_.with_frame([&pixels, background](Image_View image) {
|
||||
pixels = encode_pixel_frame(image, background);
|
||||
});
|
||||
return copy.image.empty() ? std::nullopt : std::optional<Gallery_Pixel_Copy>(std::move(copy));
|
||||
return pixels.empty() ? std::nullopt : std::optional<std::string>(std::move(pixels));
|
||||
}
|
||||
void record_pixel_response(std::chrono::steady_clock::time_point request_started,
|
||||
std::chrono::steady_clock::time_point encode_started,
|
||||
@@ -1591,31 +1587,21 @@ struct Gallery_Plot_Session::Impl {
|
||||
}
|
||||
std::optional<Web_Response> handle_frame_request() {
|
||||
const auto request_started = std::chrono::steady_clock::now();
|
||||
std::optional<Gallery_Pixel_Copy> copy;
|
||||
std::uint64_t generation{};
|
||||
std::optional<std::string> pixels;
|
||||
{
|
||||
auto lock = acquire_foreground_lock();
|
||||
if (!scene)
|
||||
return std::nullopt;
|
||||
generation = scene_generation;
|
||||
copy = scene->copy_latest_pixels();
|
||||
}
|
||||
if (!copy)
|
||||
return std::nullopt;
|
||||
const auto encode_started = std::chrono::steady_clock::now();
|
||||
std::string pixels = encode_pixel_frame(copy->image, copy->background);
|
||||
const auto encode_finished = std::chrono::steady_clock::now();
|
||||
{
|
||||
auto lock = acquire_foreground_lock();
|
||||
if (scene && scene_generation == generation)
|
||||
const auto encode_started = std::chrono::steady_clock::now();
|
||||
pixels = scene->encode_latest_pixels();
|
||||
const auto encode_finished = std::chrono::steady_clock::now();
|
||||
if (pixels)
|
||||
scene->record_pixel_response(request_started, encode_started, encode_finished,
|
||||
pixels.size());
|
||||
pixels->size());
|
||||
}
|
||||
return pixels.empty()
|
||||
? std::nullopt
|
||||
: std::optional<Web_Response>(Web_Response{
|
||||
Web_Response_Type::Pixels, std::move(pixels)
|
||||
});
|
||||
if (!pixels)
|
||||
return std::nullopt;
|
||||
return Web_Response{Web_Response_Type::Pixels, std::move(*pixels)};
|
||||
}
|
||||
std::optional<Web_Response> handle(const Web_Event& event) {
|
||||
if (std::holds_alternative<Frame_Request>(event))
|
||||
@@ -1641,7 +1627,7 @@ struct Gallery_Plot_Session::Impl {
|
||||
if (scene)
|
||||
scene->dispatch(value);
|
||||
}
|
||||
else if constexpr (std::is_base_of_v<Event, T>) {
|
||||
else if constexpr (Event_Object<T>) {
|
||||
if (scene)
|
||||
scene->dispatch(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user