blob: 2c5b2319eba36270a0f9c1e0131ffd1833c21e1b [file] [log] [blame]
[email protected]bffc8302014-01-23 20:52:161// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]0f21e8582013-01-11 11:06:562// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]bffc8302014-01-23 20:52:165#include "content/renderer/child_frame_compositing_helper.h"
[email protected]0f21e8582013-01-11 11:06:566
dcheng07945f632015-12-26 07:59:327#include <utility>
8
kylechar5e037002018-01-05 15:30:199#include "build/build_config.h"
lfgcccffbe2016-03-10 00:05:4610#include "cc/layers/picture_image_layer.h"
[email protected]cc3cfaa2013-03-18 09:05:5211#include "cc/layers/solid_color_layer.h"
kenrbfc7c02c92015-05-29 22:20:5812#include "cc/layers/surface_layer.h"
vmpstr55c7657ca2017-04-29 00:46:4813#include "cc/paint/paint_image.h"
Vladimir Levin988d0242017-08-08 00:02:5714#include "cc/paint/paint_image_builder.h"
Fady Samuel4e717f52018-02-07 05:51:5015#include "content/renderer/child_frame_compositor.h"
[email protected]73405fb2013-12-11 04:59:3716#include "skia/ext/image_operations.h"
lfgcccffbe2016-03-10 00:05:4617#include "third_party/skia/include/core/SkBitmap.h"
18#include "third_party/skia/include/core/SkImage.h"
19#include "ui/gfx/geometry/point_f.h"
Fady Samuel4e717f52018-02-07 05:51:5020#include "ui/gfx/geometry/size.h"
[email protected]73405fb2013-12-11 04:59:3721#include "ui/gfx/skia_util.h"
[email protected]0f21e8582013-01-11 11:06:5622
23namespace content {
24
[email protected]bffc8302014-01-23 20:52:1625ChildFrameCompositingHelper::ChildFrameCompositingHelper(
Fady Samuel4e717f52018-02-07 05:51:5026 ChildFrameCompositor* child_frame_compositor)
27 : child_frame_compositor_(child_frame_compositor) {
28 DCHECK(child_frame_compositor_);
lfga7d368e2015-02-03 23:01:3729}
[email protected]bffc8302014-01-23 20:52:1630
Fady Samuel4e717f52018-02-07 05:51:5031ChildFrameCompositingHelper::~ChildFrameCompositingHelper() = default;
[email protected]94224ba62014-02-04 00:25:2432
Fady Samuel4e717f52018-02-07 05:51:5033void ChildFrameCompositingHelper::ChildFrameGone(
34 const gfx::Size& frame_size_in_dip,
35 float device_scale_factor) {
36 primary_surface_id_ = viz::SurfaceId();
37 fallback_surface_id_ = viz::SurfaceId();
[email protected]94224ba62014-02-04 00:25:2438
lfgfd437a272015-11-24 21:24:5339 scoped_refptr<cc::SolidColorLayer> crashed_layer =
loyso0940d412016-03-14 01:30:3140 cc::SolidColorLayer::Create();
lfgfd437a272015-11-24 21:24:5341 crashed_layer->SetMasksToBounds(true);
Bo Liuffa01b022018-09-27 00:06:0542 crashed_layer->SetBackgroundColor(SK_ColorGRAY);
lfgcccffbe2016-03-10 00:05:4643
Fady Samuel4e717f52018-02-07 05:51:5044 if (child_frame_compositor_->GetLayer()) {
45 SkBitmap* sad_bitmap = child_frame_compositor_->GetSadPageBitmap();
46 if (sad_bitmap && frame_size_in_dip.width() > sad_bitmap->width() &&
47 frame_size_in_dip.height() > sad_bitmap->height()) {
lfgcccffbe2016-03-10 00:05:4648 scoped_refptr<cc::PictureImageLayer> sad_layer =
loyso0940d412016-03-14 01:30:3149 cc::PictureImageLayer::Create();
Vladimir Levinf67b0fc02017-10-06 01:48:1150 sad_layer->SetImage(cc::PaintImageBuilder::WithDefault()
Khushal73760a32018-02-16 19:29:5151 .set_id(cc::PaintImage::GetNextId())
52 .set_image(SkImage::MakeFromBitmap(*sad_bitmap),
53 cc::PaintImage::GetNextContentId())
Adrienne Walker3178dcb2018-02-13 23:49:4054 .TakePaintImage(),
55 SkMatrix::I(), false);
lfgcccffbe2016-03-10 00:05:4656 sad_layer->SetBounds(
Fady Samuel4e717f52018-02-07 05:51:5057 gfx::Size(sad_bitmap->width() * device_scale_factor,
58 sad_bitmap->height() * device_scale_factor));
59 sad_layer->SetPosition(
60 gfx::PointF((frame_size_in_dip.width() - sad_bitmap->width()) / 2,
61 (frame_size_in_dip.height() - sad_bitmap->height()) / 2));
lfgcccffbe2016-03-10 00:05:4662 sad_layer->SetIsDrawable(true);
63
64 crashed_layer->AddChild(sad_layer);
65 }
66 }
67
danakje1b64262018-05-05 01:35:5468 bool prevent_contents_opaque_changes = false;
danakj25f030112018-05-11 18:26:5469 child_frame_compositor_->SetLayer(std::move(crashed_layer),
Daniel Cheng02a0bc12018-09-19 00:42:0970 prevent_contents_opaque_changes,
71 false /* is_surface_layer */);
[email protected]f49722f2014-01-30 17:54:5072}
73
Saman Sami98c524052018-10-26 17:34:5774void ChildFrameCompositingHelper::SetSurfaceId(
Fady Samuel1cc05222017-11-17 10:42:2675 const viz::SurfaceId& surface_id,
Vladimir Levin6220cb62018-04-05 02:44:3876 const gfx::Size& frame_size_in_dip,
77 const cc::DeadlinePolicy& deadline) {
Fady Samuel4e717f52018-02-07 05:51:5078 if (primary_surface_id_ == surface_id)
Fady Samuel64eb4b4f2017-11-09 00:31:5279 return;
80
Fady Samuel4e717f52018-02-07 05:51:5081 primary_surface_id_ = surface_id;
Fady Samuel509c2d52017-08-28 19:00:5882
kylecharee539faa02018-01-22 17:00:5583 surface_layer_ = cc::SurfaceLayer::Create();
Fady Samuel509c2d52017-08-28 19:00:5884 surface_layer_->SetMasksToBounds(true);
sunxd2869c922018-05-14 20:48:3285 surface_layer_->SetSurfaceHitTestable(true);
Fady Samuel02de6ee2018-01-05 21:20:2186 surface_layer_->SetBackgroundColor(SK_ColorTRANSPARENT);
Fady Samuel509c2d52017-08-28 19:00:5887
Saman Sami98c524052018-10-26 17:34:5788 surface_layer_->SetSurfaceId(surface_id, deadline);
89 surface_layer_->SetOldestAcceptableFallback(fallback_surface_id_);
Fady Samuel509c2d52017-08-28 19:00:5890
danakje1b64262018-05-05 01:35:5491 // TODO(lfg): Investigate if it's possible to propagate the information
92 // about the child surface's opacity. https://crbug.com/629851.
93 bool prevent_contents_opaque_changes = true;
danakj25f030112018-05-11 18:26:5494 child_frame_compositor_->SetLayer(surface_layer_,
Daniel Cheng02a0bc12018-09-19 00:42:0995 prevent_contents_opaque_changes,
96 true /* is_surface_layer */);
Fady Samuel509c2d52017-08-28 19:00:5897
98 UpdateVisibility(true);
99
danakj25f030112018-05-11 18:26:54100 surface_layer_->SetBounds(frame_size_in_dip);
Fady Samuel509c2d52017-08-28 19:00:58101}
102
Saman Sami98c524052018-10-26 17:34:57103void ChildFrameCompositingHelper::SetOldestAcceptableFallback(
Fady Samuel1cc05222017-11-17 10:42:26104 const viz::SurfaceId& surface_id,
kylecharee539faa02018-01-22 17:00:55105 const gfx::Size& frame_size_in_dip) {
Fady Samuel1cc05222017-11-17 10:42:26106 fallback_surface_id_ = surface_id;
kenrb6ef29da2017-06-09 22:16:21107
Fady Samueld10aadd82017-11-03 18:23:57108 if (!surface_layer_) {
Saman Sami98c524052018-10-26 17:34:57109 SetSurfaceId(surface_id, frame_size_in_dip,
110 cc::DeadlinePolicy::UseDefaultDeadline());
Fady Samueld10aadd82017-11-03 18:23:57111 return;
112 }
113
Saman Sami98c524052018-10-26 17:34:57114 surface_layer_->SetOldestAcceptableFallback(surface_id);
kenrbfc7c02c92015-05-29 22:20:58115}
116
[email protected]bffc8302014-01-23 20:52:16117void ChildFrameCompositingHelper::UpdateVisibility(bool visible) {
danakj6a062b112018-05-17 16:25:45118 cc::Layer* layer = child_frame_compositor_->GetLayer();
119 if (layer)
120 layer->SetIsDrawable(visible);
[email protected]69b79122013-02-14 19:16:45121}
122
[email protected]0f21e8582013-01-11 11:06:56123} // namespace content