Commit 6d4140c0 authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

[web_engine] Set the background color to black at view creation time.

Ensures that the view stays black until webpage style data is loaded and
parsed, by setting up a black background layer and making content
output surfaces initially transparent.

Some IWYU fixes.

Bug: 1051241
Change-Id: I22552863c1ae7cb2b7df280a4936a65445614215
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2123307
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarDavid Dorwin <ddorwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755213}
parent ebb5c8f1
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <fuchsia/ui/gfx/cpp/fidl.h> #include <fuchsia/ui/gfx/cpp/fidl.h>
#include <lib/sys/cpp/component_context.h> #include <lib/sys/cpp/component_context.h>
#include <lib/ui/scenic/cpp/view_ref_pair.h> #include <lib/ui/scenic/cpp/view_ref_pair.h>
#include <limits>
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/fuchsia/default_context.h" #include "base/fuchsia/default_context.h"
...@@ -23,6 +24,9 @@ ...@@ -23,6 +24,9 @@
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/permission_controller_delegate.h" #include "content/public/browser/permission_controller_delegate.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/renderer_preferences_util.h" #include "content/public/browser/renderer_preferences_util.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/was_activated_option.mojom.h" #include "content/public/common/was_activated_option.mojom.h"
...@@ -1024,3 +1028,20 @@ void FrameImpl::DidFinishLoad(content::RenderFrameHost* render_frame_host, ...@@ -1024,3 +1028,20 @@ void FrameImpl::DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) { const GURL& validated_url) {
context_->devtools_controller()->OnFrameLoaded(web_contents_.get()); context_->devtools_controller()->OnFrameLoaded(web_contents_.get());
} }
void FrameImpl::RenderViewCreated(content::RenderViewHost* render_view_host) {
render_view_host->GetWidget()->GetView()->SetBackgroundColor(
SK_AlphaTRANSPARENT);
}
void FrameImpl::RenderViewReady() {
web_contents_->GetRenderViewHost()
->GetWidget()
->GetView()
->SetBackgroundColor(SK_AlphaTRANSPARENT);
// Setting the background color doesn't necessarily apply it right away, so
// request a redraw if there is a view connected to this Frame.
if (window_tree_host_)
window_tree_host_->compositor()->ScheduleDraw();
}
...@@ -217,6 +217,8 @@ class FrameImpl : public fuchsia::web::Frame, ...@@ -217,6 +217,8 @@ class FrameImpl : public fuchsia::web::Frame,
content::NavigationHandle* navigation_handle) override; content::NavigationHandle* navigation_handle) override;
void DidFinishLoad(content::RenderFrameHost* render_frame_host, void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) override; const GURL& validated_url) override;
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
void RenderViewReady() override;
const std::unique_ptr<content::WebContents> web_contents_; const std::unique_ptr<content::WebContents> web_contents_;
ContextImpl* const context_; ContextImpl* const context_;
......
...@@ -10,10 +10,6 @@ ...@@ -10,10 +10,6 @@
namespace { namespace {
// The background color that is shown when the main window does not fully
// fill the View.
constexpr SkColor kLetterboxBackgroundColor = SK_ColorBLACK;
// Returns a scaling factor that will allow |inset| to fit fully inside // Returns a scaling factor that will allow |inset| to fit fully inside
// |container| without clipping. // |container| without clipping.
float ProportionalScale(gfx::Size inset, gfx::Size container) { float ProportionalScale(gfx::Size inset, gfx::Size container) {
...@@ -54,8 +50,13 @@ void FrameLayoutManager::OnWindowAddedToLayout(aura::Window* child) { ...@@ -54,8 +50,13 @@ void FrameLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
main_child_ = child; main_child_ = child;
SetChildBoundsDirect(main_child_, SetChildBoundsDirect(main_child_,
gfx::Rect(main_child_->parent()->bounds().size())); gfx::Rect(main_child_->parent()->bounds().size()));
UpdateContentBounds(); UpdateContentBounds();
// Make the compositor's background transparent by default.
main_child_->parent()->GetHost()->compositor()->SetBackgroundColor(
SK_AlphaTRANSPARENT);
main_child_->GetHost()->compositor()->SetBackgroundColor(
SK_AlphaTRANSPARENT);
} }
} }
...@@ -103,7 +104,4 @@ void FrameLayoutManager::UpdateContentBounds() { ...@@ -103,7 +104,4 @@ void FrameLayoutManager::UpdateContentBounds() {
(actual_size.height() - (render_size_override_.height() * scale)) / 2.0; (actual_size.height() - (render_size_override_.height() * scale)) / 2.0;
transform.Translate(center_x_offset, center_y_offset); transform.Translate(center_x_offset, center_y_offset);
main_child_->SetTransform(transform); main_child_->SetTransform(transform);
main_child_->parent()->GetHost()->compositor()->SetBackgroundColor(
kLetterboxBackgroundColor);
} }
...@@ -37,7 +37,8 @@ ScenicWindow::ScenicWindow(ScenicWindowManager* window_manager, ...@@ -37,7 +37,8 @@ ScenicWindow::ScenicWindow(ScenicWindowManager* window_manager,
"chromium window"), "chromium window"),
node_(&scenic_session_), node_(&scenic_session_),
input_node_(&scenic_session_), input_node_(&scenic_session_),
render_node_(&scenic_session_) { render_node_(&scenic_session_),
background_node_(&scenic_session_) {
scenic_session_.set_error_handler( scenic_session_.set_error_handler(
fit::bind_member(this, &ScenicWindow::OnScenicError)); fit::bind_member(this, &ScenicWindow::OnScenicError));
scenic_session_.set_event_handler( scenic_session_.set_event_handler(
...@@ -51,9 +52,28 @@ ScenicWindow::ScenicWindow(ScenicWindowManager* window_manager, ...@@ -51,9 +52,28 @@ ScenicWindow::ScenicWindow(ScenicWindowManager* window_manager,
// Add input shape. // Add input shape.
node_.AddChild(input_node_); node_.AddChild(input_node_);
// Add rendering subtree. // Add rendering subtree, rooted at Z=-2 to make room for background layers in
// the Z-order (lesser values are higher in the visual ordering).
constexpr float kRenderNodeZPosition = -2.;
constexpr float kBackgroundNodeZPosition = kRenderNodeZPosition + 1.;
render_node_.SetTranslation(0., 0., kRenderNodeZPosition);
node_.AddChild(render_node_); node_.AddChild(render_node_);
// Initialize a black background to be just behind |render_node_|.
scenic::Material background_color(&scenic_session_);
background_color.SetColor(0, 0, 0, 255); // RGBA (0,0,0,255) = opaque black.
background_node_.SetMaterial(background_color);
scenic::Rectangle background_shape(&scenic_session_, 1., 1.);
background_node_.SetShape(background_shape);
background_node_.SetTranslation(0., 0., kBackgroundNodeZPosition);
node_.AddChild(background_node_);
// Render the background immediately.
scenic_session_.Present2(
/*requested_presentation_time=*/0,
/*requested_prediction_span=*/0,
[](fuchsia::scenic::scheduling::FuturePresentationTimes info) {});
delegate_->OnAcceleratedWidgetAvailable(window_id_); delegate_->OnAcceleratedWidgetAvailable(window_id_);
} }
...@@ -223,8 +243,12 @@ void ScenicWindow::UpdateSize() { ...@@ -223,8 +243,12 @@ void ScenicWindow::UpdateSize() {
render_node_.SetScale(size_dips_.width(), size_dips_.height(), 1.f); render_node_.SetScale(size_dips_.width(), size_dips_.height(), 1.f);
// Resize input node to cover the whole surface. // Resize input node to cover the whole surface.
input_node_.SetShape(scenic::Rectangle(&scenic_session_, size_dips_.width(), scenic::Rectangle window_rect(&scenic_session_, size_dips_.width(),
size_dips_.height())); size_dips_.height());
input_node_.SetShape(window_rect);
// Resize the input and background nodes to cover the whole surface.
background_node_.SetShape(window_rect);
// This is necessary when using vulkan because ImagePipes are presented // This is necessary when using vulkan because ImagePipes are presented
// separately and we need to make sure our sizes change is committed. // separately and we need to make sure our sizes change is committed.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <lib/ui/scenic/cpp/resources.h> #include <lib/ui/scenic/cpp/resources.h>
#include <lib/ui/scenic/cpp/session.h> #include <lib/ui/scenic/cpp/session.h>
#include <lib/ui/scenic/cpp/view_ref_pair.h> #include <lib/ui/scenic/cpp/view_ref_pair.h>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -117,6 +118,11 @@ class COMPONENT_EXPORT(OZONE) ScenicWindow ...@@ -117,6 +118,11 @@ class COMPONENT_EXPORT(OZONE) ScenicWindow
// Node in |scenic_session_| for rendering (hit testing disabled). // Node in |scenic_session_| for rendering (hit testing disabled).
scenic::EntityNode render_node_; scenic::EntityNode render_node_;
// Node in |scenic_session_| for rendering a solid color, placed just behind
// |render_node_| in the Z order.
scenic::ShapeNode background_node_;
std::unique_ptr<scenic::ViewHolder> surface_view_holder_; std::unique_ptr<scenic::ViewHolder> surface_view_holder_;
// The ratio used for translating device-independent coordinates to absolute // The ratio used for translating device-independent coordinates to absolute
......
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