Commit 2dfb726a authored by Piotr Bialecki's avatar Piotr Bialecki Committed by Commit Bot

WebXR depth: make XRDepthData a union

CL followup - make XRDepthData into an union so that it is possible
to express that the data sent over mojom boundary is either still valid,
or that new data has arrived.

For discussion, see:
https://crrev.com/c/2391619/comment/177fee99_a1338219/

Change-Id: I240357a32dc7fadcae379c3b5f1ca29bdeffcb6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2417570Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Piotr Bialecki <bialpio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809471}
parent 21e0f910
...@@ -1501,11 +1501,11 @@ mojom::XRDepthDataPtr ArCoreImpl::GetDepthData() { ...@@ -1501,11 +1501,11 @@ mojom::XRDepthDataPtr ArCoreImpl::GetDepthData() {
CHECK_EQ(num_planes, 1) << "Depth image must have 1 plane, found: " CHECK_EQ(num_planes, 1) << "Depth image must have 1 plane, found: "
<< num_planes; << num_planes;
mojom::XRDepthDataPtr result = mojom::XRDepthData::New(); if (time_delta > previous_depth_data_time_) {
mojom::XRDepthDataUpdatedPtr result = mojom::XRDepthDataUpdated::New();
result->time_delta = time_delta; result->time_delta = time_delta;
if (time_delta > previous_depth_data_time_) {
int32_t width = 0, height = 0; int32_t width = 0, height = 0;
ArImage_getWidth(arcore_session_.get(), ar_image.get(), &width); ArImage_getWidth(arcore_session_.get(), ar_image.get(), &width);
ArImage_getHeight(arcore_session_.get(), ar_image.get(), &height); ArImage_getHeight(arcore_session_.get(), ar_image.get(), &height);
...@@ -1540,12 +1540,15 @@ mojom::XRDepthDataPtr ArCoreImpl::GetDepthData() { ...@@ -1540,12 +1540,15 @@ mojom::XRDepthDataPtr ArCoreImpl::GetDepthData() {
result->size = gfx::Size(width, height); result->size = gfx::Size(width, height);
DVLOG(3) << __func__ << ": norm_texture_from_norm_view=\n" DVLOG(3) << __func__ << ": norm_texture_from_norm_view=\n"
<< result->norm_texture_from_norm_view->ToString(); << result->norm_texture_from_norm_view.ToString();
previous_depth_data_time_ = time_delta; previous_depth_data_time_ = time_delta;
return mojom::XRDepthData::NewUpdatedDepthData(std::move(result));
} }
return result; return mojom::XRDepthData::NewDataStillValid(
mojom::XRDepthDataStillValid::New());
} }
bool ArCoreImpl::IsOnGlThread() const { bool ArCoreImpl::IsOnGlThread() const {
......
...@@ -537,24 +537,36 @@ struct XRLightEstimationData { ...@@ -537,24 +537,36 @@ struct XRLightEstimationData {
XRReflectionProbe? reflection_probe; XRReflectionProbe? reflection_probe;
}; };
struct XRDepthData { // Structure that signifies that the depth data is still valid, no additional
// Timestamp of the returned data, in unspecified base. In case the data is // information is provided. See |XRDepthData| for more details.
// equal to the one returned on a previous frame (for example because the struct XRDepthDataStillValid {};
// latest depth data is unavailable), the pixel_data member will be null and
// the timestamp will match the timestamp of the previously returned depth // Structure that signifies that the Depth data was updated. Provides
// data. // information about current depth data. See |XRDepthData| for more details.
struct XRDepthDataUpdated {
// Timestamp of the returned data, in unspecified base.
mojo_base.mojom.TimeDelta time_delta; mojo_base.mojom.TimeDelta time_delta;
// Array of 16-bit numbers representing depth in millimeters from the camera // Array of 16-bit numbers representing depth in millimeters from the camera
// plane. // plane.
mojo_base.mojom.BigBuffer? pixel_data; mojo_base.mojom.BigBuffer pixel_data;
// Transform that needs to be applied when indexing into pixel_data when using // Transform that needs to be applied when indexing into pixel_data when using
// normalized view coordinates (with origin at bottom left corner of the // normalized view coordinates (with origin at bottom left corner of the
// screen). // screen).
gfx.mojom.Transform? norm_texture_from_norm_view; gfx.mojom.Transform norm_texture_from_norm_view;
// Size of the pixel array. Valid iff pixel_data is not null. // Size of the pixel array. Valid iff pixel_data is not null.
gfx.mojom.Size size; gfx.mojom.Size size;
}; };
// Depth data may be the same as the one returned in the previous frame - it is
// represented as a union of (empty) XRDepthDataStillValid structure that
// conveys no additional information except that the previously returned depth
// data is still valid, and the XRDepthDataUpdated structure that signifies that
// the depth data was updated & carries all information about it.
union XRDepthData {
XRDepthDataStillValid data_still_valid;
XRDepthDataUpdated updated_depth_data;
};
// The data needed for each animation frame of an XRSession. // The data needed for each animation frame of an XRSession.
struct XRFrameData { struct XRFrameData {
// General XRSession value // General XRSession value
...@@ -575,7 +587,8 @@ struct XRFrameData { ...@@ -575,7 +587,8 @@ struct XRFrameData {
// Depth data (if the device supports it and the environment integration is // Depth data (if the device supports it and the environment integration is
// enabled). This assumes that depth information is provided from a single // enabled). This assumes that depth information is provided from a single
// sensor. // sensor. If for any reason the latest depth data could not be obtained, it
// will be set to null.
XRDepthData? depth_data; XRDepthData? depth_data;
// Indicates that there has been a significant discontinuity in the mojo space // Indicates that there has been a significant discontinuity in the mojo space
......
...@@ -21,20 +21,20 @@ constexpr char kOutOfBoundsAccess[] = ...@@ -21,20 +21,20 @@ constexpr char kOutOfBoundsAccess[] =
namespace blink { namespace blink {
XRDepthInformation::XRDepthInformation( XRDepthInformation::XRDepthInformation(
const device::mojom::blink::XRDepthData& depth_data) const device::mojom::blink::XRDepthDataUpdated& depth_data)
: width_(depth_data.size.width()), : width_(depth_data.size.width()),
height_(depth_data.size.height()), height_(depth_data.size.height()),
norm_texture_from_norm_view_(*depth_data.norm_texture_from_norm_view) { norm_texture_from_norm_view_(depth_data.norm_texture_from_norm_view) {
DVLOG(3) << __func__ << ": width_=" << width_ << ", height_=" << height_ DVLOG(3) << __func__ << ": width_=" << width_ << ", height_=" << height_
<< ", norm_texture_from_norm_view_=" << ", norm_texture_from_norm_view_="
<< norm_texture_from_norm_view_.ToString(); << norm_texture_from_norm_view_.ToString();
CHECK_EQ(base::CheckMul(2, width_, height_).ValueOrDie(), CHECK_EQ(base::CheckMul(2, width_, height_).ValueOrDie(),
depth_data.pixel_data->size()); depth_data.pixel_data.size());
base::span<const uint16_t> pixel_data = base::make_span( base::span<const uint16_t> pixel_data = base::make_span(
reinterpret_cast<const uint16_t*>(depth_data.pixel_data->data()), reinterpret_cast<const uint16_t*>(depth_data.pixel_data.data()),
depth_data.pixel_data->size() / 2); depth_data.pixel_data.size() / 2);
// Copy the underlying pixel data into DOMUint16Array: // Copy the underlying pixel data into DOMUint16Array:
data_ = DOMUint16Array::Create(pixel_data.data(), pixel_data.size()); data_ = DOMUint16Array::Create(pixel_data.data(), pixel_data.size());
......
...@@ -21,7 +21,7 @@ class XRDepthInformation final : public ScriptWrappable { ...@@ -21,7 +21,7 @@ class XRDepthInformation final : public ScriptWrappable {
public: public:
explicit XRDepthInformation( explicit XRDepthInformation(
const device::mojom::blink::XRDepthData& depth_data); const device::mojom::blink::XRDepthDataUpdated& depth_data);
DOMUint16Array* data() const; DOMUint16Array* data() const;
......
...@@ -1154,14 +1154,23 @@ void XRSession::ProcessDepthData( ...@@ -1154,14 +1154,23 @@ void XRSession::ProcessDepthData(
device::mojom::blink::XRDepthDataPtr depth_data) { device::mojom::blink::XRDepthDataPtr depth_data) {
DVLOG(3) << __func__ << ": depth_data valid? " << !!depth_data; DVLOG(3) << __func__ << ": depth_data valid? " << !!depth_data;
if (depth_data && depth_data->pixel_data) { if (depth_data) {
// Just store the current depth data as a member - we will need to construct switch (depth_data->which()) {
// instances of XRDepthInformation once the app requests them anyway. case device::mojom::blink::XRDepthData::Tag::DATA_STILL_VALID:
depth_data_ = std::move(depth_data); // Stale depth buffer is still the most recent information we have.
// Current API shape is not well-suited to return data pertaining to
// older frames, so just discard what we have.
depth_data_ = nullptr;
break;
case device::mojom::blink::XRDepthData::Tag::UPDATED_DEPTH_DATA:
// Just store the current depth data as a member - we will need to
// construct instances of XRDepthInformation once the app requests them
// anyway.
depth_data_ = std::move(depth_data->get_updated_depth_data());
break;
}
} else { } else {
// Device did not return new pixel data - stale depth buffer is still the // Device did not return new pixel data.
// most recent information we have. Current API shape is not well-suited to
// return data pertaining to older frames, so just discard what we have.
depth_data_ = nullptr; depth_data_ = nullptr;
} }
} }
......
...@@ -553,7 +553,7 @@ class XRSession final ...@@ -553,7 +553,7 @@ class XRSession final
std::unique_ptr<TransformationMatrix> mojo_from_viewer_; std::unique_ptr<TransformationMatrix> mojo_from_viewer_;
// Current depth data buffer. // Current depth data buffer.
device::mojom::blink::XRDepthDataPtr depth_data_; device::mojom::blink::XRDepthDataUpdatedPtr depth_data_;
bool pending_frame_ = false; bool pending_frame_ = false;
bool resolving_frame_ = false; bool resolving_frame_ = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment