blob: 78bccec91ac1ec6eb1a71a7021254440924cfa13 [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"
[email protected]38564622014-08-19 02:47:1810#include "cc/blink/web_layer_impl.h"
lfgcccffbe2016-03-10 00:05:4611#include "cc/layers/picture_image_layer.h"
[email protected]cc3cfaa2013-03-18 09:05:5212#include "cc/layers/solid_color_layer.h"
kenrbfc7c02c92015-05-29 22:20:5813#include "cc/layers/surface_layer.h"
vmpstr55c7657ca2017-04-29 00:46:4814#include "cc/paint/paint_image.h"
Vladimir Levin988d0242017-08-08 00:02:5715#include "cc/paint/paint_image_builder.h"
Fady Samuel4e717f52018-02-07 05:51:5016#include "content/renderer/child_frame_compositor.h"
[email protected]73405fb2013-12-11 04:59:3717#include "skia/ext/image_operations.h"
lfgcccffbe2016-03-10 00:05:4618#include "third_party/skia/include/core/SkBitmap.h"
19#include "third_party/skia/include/core/SkImage.h"
20#include "ui/gfx/geometry/point_f.h"
Fady Samuel4e717f52018-02-07 05:51:5021#include "ui/gfx/geometry/size.h"
[email protected]73405fb2013-12-11 04:59:3722#include "ui/gfx/skia_util.h"
[email protected]0f21e8582013-01-11 11:06:5623
24namespace content {
25
[email protected]bffc8302014-01-23 20:52:1626ChildFrameCompositingHelper::ChildFrameCompositingHelper(
Fady Samuel4e717f52018-02-07 05:51:5027 ChildFrameCompositor* child_frame_compositor)
28 : child_frame_compositor_(child_frame_compositor) {
29 DCHECK(child_frame_compositor_);
lfga7d368e2015-02-03 23:01:3730}
[email protected]bffc8302014-01-23 20:52:1631
Fady Samuel4e717f52018-02-07 05:51:5032ChildFrameCompositingHelper::~ChildFrameCompositingHelper() = default;
[email protected]94224ba62014-02-04 00:25:2433
Fady Samuel4e717f52018-02-07 05:51:5034void ChildFrameCompositingHelper::ChildFrameGone(
35 const gfx::Size& frame_size_in_dip,
36 float device_scale_factor) {
37 primary_surface_id_ = viz::SurfaceId();
38 fallback_surface_id_ = viz::SurfaceId();
[email protected]94224ba62014-02-04 00:25:2439
lfgfd437a272015-11-24 21:24:5340 scoped_refptr<cc::SolidColorLayer> crashed_layer =
loyso0940d412016-03-14 01:30:3141 cc::SolidColorLayer::Create();
lfgfd437a272015-11-24 21:24:5342 crashed_layer->SetMasksToBounds(true);
lfgcccffbe2016-03-10 00:05:4643 crashed_layer->SetBackgroundColor(SK_ColorBLACK);
44
Fady Samuel4e717f52018-02-07 05:51:5045 if (child_frame_compositor_->GetLayer()) {
46 SkBitmap* sad_bitmap = child_frame_compositor_->GetSadPageBitmap();
47 if (sad_bitmap && frame_size_in_dip.width() > sad_bitmap->width() &&
48 frame_size_in_dip.height() > sad_bitmap->height()) {
lfgcccffbe2016-03-10 00:05:4649 scoped_refptr<cc::PictureImageLayer> sad_layer =
loyso0940d412016-03-14 01:30:3150 cc::PictureImageLayer::Create();
Vladimir Levinf67b0fc02017-10-06 01:48:1151 sad_layer->SetImage(cc::PaintImageBuilder::WithDefault()
Khushal73760a32018-02-16 19:29:5152 .set_id(cc::PaintImage::GetNextId())
53 .set_image(SkImage::MakeFromBitmap(*sad_bitmap),
54 cc::PaintImage::GetNextContentId())
Adrienne Walker3178dcb2018-02-13 23:49:4055 .TakePaintImage(),
56 SkMatrix::I(), false);
lfgcccffbe2016-03-10 00:05:4657 sad_layer->SetBounds(
Fady Samuel4e717f52018-02-07 05:51:5058 gfx::Size(sad_bitmap->width() * device_scale_factor,
59 sad_bitmap->height() * device_scale_factor));
60 sad_layer->SetPosition(
61 gfx::PointF((frame_size_in_dip.width() - sad_bitmap->width()) / 2,
62 (frame_size_in_dip.height() - sad_bitmap->height()) / 2));
lfgcccffbe2016-03-10 00:05:4663 sad_layer->SetIsDrawable(true);
64
65 crashed_layer->AddChild(sad_layer);
66 }
67 }
68
danakje1b64262018-05-05 01:35:5469 bool prevent_contents_opaque_changes = false;
Fady Samuel4e717f52018-02-07 05:51:5070 child_frame_compositor_->SetLayer(
danakje1b64262018-05-05 01:35:5471 std::make_unique<cc_blink::WebLayerImpl>(crashed_layer),
72 prevent_contents_opaque_changes);
[email protected]f49722f2014-01-30 17:54:5073}
74
Fady Samuel1cc05222017-11-17 10:42:2675void ChildFrameCompositingHelper::SetPrimarySurfaceId(
76 const viz::SurfaceId& surface_id,
Vladimir Levin6220cb62018-04-05 02:44:3877 const gfx::Size& frame_size_in_dip,
78 const cc::DeadlinePolicy& deadline) {
Fady Samuel4e717f52018-02-07 05:51:5079 if (primary_surface_id_ == surface_id)
Fady Samuel64eb4b4f2017-11-09 00:31:5280 return;
81
Fady Samuel4e717f52018-02-07 05:51:5082 primary_surface_id_ = surface_id;
Fady Samuel509c2d52017-08-28 19:00:5883
kylecharee539faa02018-01-22 17:00:5584 surface_layer_ = cc::SurfaceLayer::Create();
Fady Samuel509c2d52017-08-28 19:00:5885 surface_layer_->SetMasksToBounds(true);
sunxd26e9bae2018-03-22 19:32:3386 surface_layer_->SetHitTestable(true);
Fady Samuel02de6ee2018-01-05 21:20:2187 surface_layer_->SetBackgroundColor(SK_ColorTRANSPARENT);
Fady Samuel509c2d52017-08-28 19:00:5888
Vladimir Levin6220cb62018-04-05 02:44:3889 surface_layer_->SetPrimarySurfaceId(surface_id, deadline);
Fady Samuelb47442d2017-10-13 04:17:3490 surface_layer_->SetFallbackSurfaceId(fallback_surface_id_);
Fady Samuel509c2d52017-08-28 19:00:5891
danakje1b64262018-05-05 01:35:5492 auto layer_owned = std::make_unique<cc_blink::WebLayerImpl>(surface_layer_);
93 auto* layer = layer_owned.get();
94
95 // TODO(lfg): Investigate if it's possible to propagate the information
96 // about the child surface's opacity. https://crbug.com/629851.
97 bool prevent_contents_opaque_changes = true;
98 child_frame_compositor_->SetLayer(std::move(layer_owned),
99 prevent_contents_opaque_changes);
Fady Samuel509c2d52017-08-28 19:00:58100
101 UpdateVisibility(true);
102
danakje1b64262018-05-05 01:35:54103 layer->SetBounds(frame_size_in_dip);
Fady Samuel509c2d52017-08-28 19:00:58104}
105
Fady Samuel1cc05222017-11-17 10:42:26106void ChildFrameCompositingHelper::SetFallbackSurfaceId(
107 const viz::SurfaceId& surface_id,
kylecharee539faa02018-01-22 17:00:55108 const gfx::Size& frame_size_in_dip) {
Fady Samuel1cc05222017-11-17 10:42:26109 if (fallback_surface_id_ == surface_id)
Fady Samuel64eb4b4f2017-11-09 00:31:52110 return;
111
Fady Samuel1cc05222017-11-17 10:42:26112 fallback_surface_id_ = surface_id;
kenrb6ef29da2017-06-09 22:16:21113
Fady Samueld10aadd82017-11-03 18:23:57114 if (!surface_layer_) {
Vladimir Levin6220cb62018-04-05 02:44:38115 SetPrimarySurfaceId(surface_id, frame_size_in_dip,
116 cc::DeadlinePolicy::UseDefaultDeadline());
Fady Samueld10aadd82017-11-03 18:23:57117 return;
118 }
119
Fady Samuel1cc05222017-11-17 10:42:26120 surface_layer_->SetFallbackSurfaceId(surface_id);
kenrbfc7c02c92015-05-29 22:20:58121}
122
[email protected]bffc8302014-01-23 20:52:16123void ChildFrameCompositingHelper::UpdateVisibility(bool visible) {
Fady Samuel4e717f52018-02-07 05:51:50124 blink::WebLayer* web_layer = child_frame_compositor_->GetLayer();
125 if (web_layer)
126 web_layer->SetDrawsContent(visible);
[email protected]69b79122013-02-14 19:16:45127}
128
[email protected]0f21e8582013-01-11 11:06:56129} // namespace content