Commit 1db5bf4f authored by Michael Spang's avatar Michael Spang Committed by Commit Bot

ozone: scenic: Move rectangle resource from ScenicWindowCanvas to ScenicWindow

The shape and location of the window is independent of rendering method,
so move those resources to ScenicWindow where they can be used for both
software & vulkan rendering paths.

Bug: 861853
Test: ozone_demo --ozone-platform=scenic --enable-vulkan (with full series)

Change-Id: I728d9d6fc173dd629b319a5de14072c60156d695

Reviewed-on: https://chromium-review.googlesource.com/1188970Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Commit-Queue: Michael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586292}
parent 75453eca
...@@ -86,6 +86,12 @@ ScenicWindow::ScenicWindow( ...@@ -86,6 +86,12 @@ ScenicWindow::ScenicWindow(
input_connection_.NewRequest().TakeChannel()); input_connection_.NewRequest().TakeChannel());
input_connection_->SetEventListener(input_listener_binding_.NewBinding()); input_connection_->SetEventListener(input_listener_binding_.NewBinding());
// Add shape node for window.
shape_id_ = scenic_session_.CreateShapeNode();
scenic_session_.AddNodeChild(node_id_, shape_id_);
material_id_ = scenic_session_.CreateMaterial();
scenic_session_.SetNodeMaterial(shape_id_, material_id_);
// Call Present() to ensure that the scenic session commands are processed, // Call Present() to ensure that the scenic session commands are processed,
// which is necessary to receive metrics event from Scenic. // which is necessary to receive metrics event from Scenic.
scenic_session_.Present(); scenic_session_.Present();
...@@ -96,11 +102,17 @@ ScenicWindow::ScenicWindow( ...@@ -96,11 +102,17 @@ ScenicWindow::ScenicWindow(
ScenicWindow::~ScenicWindow() { ScenicWindow::~ScenicWindow() {
scenic_session_.ReleaseResource(node_id_); scenic_session_.ReleaseResource(node_id_);
scenic_session_.ReleaseResource(parent_node_id_); scenic_session_.ReleaseResource(parent_node_id_);
scenic_session_.ReleaseResource(shape_id_);
scenic_session_.ReleaseResource(material_id_);
manager_->RemoveWindow(window_id_, this); manager_->RemoveWindow(window_id_, this);
view_.Unbind(); view_.Unbind();
} }
void ScenicWindow::SetTexture(ScenicSession::ResourceId texture) {
scenic_session_.SetMaterialTexture(material_id_, texture);
}
gfx::Rect ScenicWindow::GetBounds() { gfx::Rect ScenicWindow::GetBounds() {
return gfx::Rect(size_pixels_); return gfx::Rect(size_pixels_);
} }
...@@ -192,6 +204,19 @@ gfx::Rect ScenicWindow::GetRestoredBoundsInPixels() const { ...@@ -192,6 +204,19 @@ gfx::Rect ScenicWindow::GetRestoredBoundsInPixels() const {
void ScenicWindow::UpdateSize() { void ScenicWindow::UpdateSize() {
gfx::SizeF scaled = ScaleSize(size_dips_, device_pixel_ratio_); gfx::SizeF scaled = ScaleSize(size_dips_, device_pixel_ratio_);
size_pixels_ = gfx::Size(ceilf(scaled.width()), ceilf(scaled.height())); size_pixels_ = gfx::Size(ceilf(scaled.width()), ceilf(scaled.height()));
// Translate the node by half of the view dimensions to put it in the center
// of the view.
float translation[] = {size_dips_.width() / 2.0, size_dips_.height() / 2.0,
0.f};
// Set node shape to rectangle that matches size of the view.
ScenicSession::ResourceId rect_id =
scenic_session_.CreateRectangle(size_dips_.width(), size_dips_.height());
scenic_session_.SetNodeShape(shape_id_, rect_id);
scenic_session_.SetNodeTranslation(shape_id_, translation);
scenic_session_.ReleaseResource(rect_id);
delegate_->OnBoundsChanged(gfx::Rect(size_pixels_)); delegate_->OnBoundsChanged(gfx::Rect(size_pixels_));
} }
......
...@@ -41,6 +41,10 @@ class OZONE_EXPORT ScenicWindow : public PlatformWindow, ...@@ -41,6 +41,10 @@ class OZONE_EXPORT ScenicWindow : public PlatformWindow,
ScenicSession::ResourceId node_id() const { return node_id_; } ScenicSession::ResourceId node_id() const { return node_id_; }
float device_pixel_ratio() const { return device_pixel_ratio_; } float device_pixel_ratio() const { return device_pixel_ratio_; }
// Overrides texture of the window. This is used by ScenicWindowCanvas.
// TODO(spang): Deprecate software rendering on fuchsia.
void SetTexture(ScenicSession::ResourceId texture);
// PlatformWindow implementation. // PlatformWindow implementation.
gfx::Rect GetBounds() override; gfx::Rect GetBounds() override;
void SetBounds(const gfx::Rect& bounds) override; void SetBounds(const gfx::Rect& bounds) override;
...@@ -104,6 +108,12 @@ class OZONE_EXPORT ScenicWindow : public PlatformWindow, ...@@ -104,6 +108,12 @@ class OZONE_EXPORT ScenicWindow : public PlatformWindow,
// Node ID in |scenic_session_| for the view. // Node ID in |scenic_session_| for the view.
ScenicSession::ResourceId node_id_; ScenicSession::ResourceId node_id_;
// Shape and material resource ids for the view in the context of the scenic
// session for the window. They are used to set shape and texture for the view
// node.
ScenicSession::ResourceId shape_id_;
ScenicSession::ResourceId material_id_;
// Current view size in DIPs. // Current view size in DIPs.
gfx::SizeF size_dips_; gfx::SizeF size_dips_;
......
...@@ -54,12 +54,6 @@ void ScenicWindowCanvas::Frame::CopyDirtyRegionFrom(const Frame& frame) { ...@@ -54,12 +54,6 @@ void ScenicWindowCanvas::Frame::CopyDirtyRegionFrom(const Frame& frame) {
} }
ScenicWindowCanvas::ScenicWindowCanvas(ScenicWindow* window) : window_(window) { ScenicWindowCanvas::ScenicWindowCanvas(ScenicWindow* window) : window_(window) {
ScenicSession* scenic = window_->scenic_session();
shape_id_ = scenic->CreateShapeNode();
scenic->AddNodeChild(window_->node_id(), shape_id_);
material_id_ = scenic->CreateMaterial();
scenic->SetNodeMaterial(shape_id_, material_id_);
} }
ScenicWindowCanvas::~ScenicWindowCanvas() { ScenicWindowCanvas::~ScenicWindowCanvas() {
...@@ -68,15 +62,12 @@ ScenicWindowCanvas::~ScenicWindowCanvas() { ...@@ -68,15 +62,12 @@ ScenicWindowCanvas::~ScenicWindowCanvas() {
if (!frames_[i].is_empty()) if (!frames_[i].is_empty())
scenic->ReleaseResource(frames_[i].memory_id); scenic->ReleaseResource(frames_[i].memory_id);
} }
scenic->ReleaseResource(material_id_);
scenic->ReleaseResource(shape_id_);
} }
void ScenicWindowCanvas::ResizeCanvas(const gfx::Size& viewport_size) { void ScenicWindowCanvas::ResizeCanvas(const gfx::Size& viewport_size) {
viewport_size_ = viewport_size; viewport_size_ = viewport_size;
ScenicSession* scenic = window_->scenic_session(); ScenicSession* scenic = window_->scenic_session();
float device_pixel_ratio = window_->device_pixel_ratio();
// Allocate new buffers with the new size. // Allocate new buffers with the new size.
for (int i = 0; i < kNumBuffers; ++i) { for (int i = 0; i < kNumBuffers; ++i) {
...@@ -84,21 +75,6 @@ void ScenicWindowCanvas::ResizeCanvas(const gfx::Size& viewport_size) { ...@@ -84,21 +75,6 @@ void ScenicWindowCanvas::ResizeCanvas(const gfx::Size& viewport_size) {
scenic->ReleaseResource(frames_[i].memory_id); scenic->ReleaseResource(frames_[i].memory_id);
frames_[i].Initialize(viewport_size_, scenic); frames_[i].Initialize(viewport_size_, scenic);
} }
gfx::SizeF viewport_size_dips =
gfx::ScaleSize(gfx::SizeF(viewport_size_), 1.0 / device_pixel_ratio);
// Translate the node by half of the view dimensions to put it in the center
// of the view.
float t[] = {viewport_size_dips.width() / 2.0,
viewport_size_dips.height() / 2.0, 0.f};
scenic->SetNodeTranslation(window_->node_id(), t);
// Set node shape to rectangle that matches size of the view.
ScenicSession::ResourceId rect_id = scenic->CreateRectangle(
viewport_size_dips.width(), viewport_size_dips.height());
scenic->SetNodeShape(shape_id_, rect_id);
scenic->ReleaseResource(rect_id);
} }
sk_sp<SkSurface> ScenicWindowCanvas::GetSurface() { sk_sp<SkSurface> ScenicWindowCanvas::GetSurface() {
...@@ -160,7 +136,7 @@ void ScenicWindowCanvas::PresentCanvas(const gfx::Rect& damage) { ...@@ -160,7 +136,7 @@ void ScenicWindowCanvas::PresentCanvas(const gfx::Rect& damage) {
ScenicSession::ResourceId image_id = scenic->CreateImage( ScenicSession::ResourceId image_id = scenic->CreateImage(
frames_[current_frame_].memory_id, 0, std::move(info)); frames_[current_frame_].memory_id, 0, std::move(info));
scenic->SetMaterialTexture(material_id_, image_id); window_->SetTexture(image_id);
scenic->ReleaseResource(image_id); scenic->ReleaseResource(image_id);
// Create release fence for the current buffer or reset it if it already // Create release fence for the current buffer or reset it if it already
......
...@@ -68,12 +68,6 @@ class ScenicWindowCanvas : public SurfaceOzoneCanvas { ...@@ -68,12 +68,6 @@ class ScenicWindowCanvas : public SurfaceOzoneCanvas {
ScenicWindow* const window_; ScenicWindow* const window_;
// Shape and material resource ids for the view in the context of the scenic
// session for the |window_| (window_->scenic()). They are used to set shape
// and texture for the view node.
ScenicSession::ResourceId shape_id_;
ScenicSession::ResourceId material_id_;
Frame frames_[kNumBuffers]; Frame frames_[kNumBuffers];
// Buffer index in |frames_| for the frame that's currently being rendered. // Buffer index in |frames_| for the frame that's currently being rendered.
......
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