blob: 9c551267224b31449a04b2f67f152841b3b07ceb [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()
Vladimir Levin988d0242017-08-08 00:02:5752 .set_id(cc::PaintImage::kNonLazyStableId)
53 .set_image(SkImage::MakeFromBitmap(*sad_bitmap))
54 .TakePaintImage());
lfgcccffbe2016-03-10 00:05:4655 sad_layer->SetBounds(
Fady Samuel4e717f52018-02-07 05:51:5056 gfx::Size(sad_bitmap->width() * device_scale_factor,
57 sad_bitmap->height() * device_scale_factor));
58 sad_layer->SetPosition(
59 gfx::PointF((frame_size_in_dip.width() - sad_bitmap->width()) / 2,
60 (frame_size_in_dip.height() - sad_bitmap->height()) / 2));
lfgcccffbe2016-03-10 00:05:4661 sad_layer->SetIsDrawable(true);
62
63 crashed_layer->AddChild(sad_layer);
64 }
65 }
66
Fady Samuel4e717f52018-02-07 05:51:5067 child_frame_compositor_->SetLayer(
68 std::make_unique<cc_blink::WebLayerImpl>(crashed_layer));
[email protected]f49722f2014-01-30 17:54:5069}
70
Fady Samuel1cc05222017-11-17 10:42:2671void ChildFrameCompositingHelper::SetPrimarySurfaceId(
72 const viz::SurfaceId& surface_id,
73 const gfx::Size& frame_size_in_dip) {
Fady Samuel4e717f52018-02-07 05:51:5074 if (primary_surface_id_ == surface_id)
Fady Samuel64eb4b4f2017-11-09 00:31:5275 return;
76
Fady Samuel4e717f52018-02-07 05:51:5077 primary_surface_id_ = surface_id;
Fady Samuel509c2d52017-08-28 19:00:5878
kylecharee539faa02018-01-22 17:00:5579 surface_layer_ = cc::SurfaceLayer::Create();
Fady Samuel509c2d52017-08-28 19:00:5880 surface_layer_->SetMasksToBounds(true);
Fady Samuel02de6ee2018-01-05 21:20:2181 surface_layer_->SetBackgroundColor(SK_ColorTRANSPARENT);
Fady Samuel509c2d52017-08-28 19:00:5882
Fady Samuelb46e0ef2018-01-30 04:48:4183 surface_layer_->SetPrimarySurfaceId(surface_id,
84 cc::DeadlinePolicy::UseDefaultDeadline());
Fady Samuelb47442d2017-10-13 04:17:3485 surface_layer_->SetFallbackSurfaceId(fallback_surface_id_);
Fady Samuel509c2d52017-08-28 19:00:5886
87 std::unique_ptr<cc_blink::WebLayerImpl> layer(
88 new cc_blink::WebLayerImpl(surface_layer_));
89 // TODO(lfg): Investigate if it's possible to propagate the information about
90 // the child surface's opacity. https://crbug.com/629851.
91 layer->SetOpaque(false);
92 layer->SetContentsOpaqueIsFixed(true);
Fady Samuel4e717f52018-02-07 05:51:5093 child_frame_compositor_->SetLayer(std::move(layer));
Fady Samuel509c2d52017-08-28 19:00:5894
95 UpdateVisibility(true);
96
Fady Samuel4e717f52018-02-07 05:51:5097 static_cast<cc_blink::WebLayerImpl*>(child_frame_compositor_->GetLayer())
Fady Samuel1cc05222017-11-17 10:42:2698 ->layer()
99 ->SetBounds(frame_size_in_dip);
Fady Samuel509c2d52017-08-28 19:00:58100}
101
Fady Samuel1cc05222017-11-17 10:42:26102void ChildFrameCompositingHelper::SetFallbackSurfaceId(
103 const viz::SurfaceId& surface_id,
kylecharee539faa02018-01-22 17:00:55104 const gfx::Size& frame_size_in_dip) {
Fady Samuel1cc05222017-11-17 10:42:26105 if (fallback_surface_id_ == surface_id)
Fady Samuel64eb4b4f2017-11-09 00:31:52106 return;
107
Fady Samuel1cc05222017-11-17 10:42:26108 fallback_surface_id_ = surface_id;
kenrb6ef29da2017-06-09 22:16:21109
Fady Samueld10aadd82017-11-03 18:23:57110 if (!surface_layer_) {
Fady Samuel1cc05222017-11-17 10:42:26111 SetPrimarySurfaceId(surface_id, frame_size_in_dip);
Fady Samueld10aadd82017-11-03 18:23:57112 return;
113 }
114
Fady Samuel1cc05222017-11-17 10:42:26115 surface_layer_->SetFallbackSurfaceId(surface_id);
kenrbfc7c02c92015-05-29 22:20:58116}
117
[email protected]bffc8302014-01-23 20:52:16118void ChildFrameCompositingHelper::UpdateVisibility(bool visible) {
Fady Samuel4e717f52018-02-07 05:51:50119 blink::WebLayer* web_layer = child_frame_compositor_->GetLayer();
120 if (web_layer)
121 web_layer->SetDrawsContent(visible);
[email protected]69b79122013-02-14 19:16:45122}
123
[email protected]0f21e8582013-01-11 11:06:56124} // namespace content