blob: 0f44083229fa5cf4e79cd790392f4384d87afec7 [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) {
Saman Samic8fc00a2018-11-19 23:16:3536 surface_id_ = viz::SurfaceId();
[email protected]94224ba62014-02-04 00:25:2437
lfgfd437a272015-11-24 21:24:5338 scoped_refptr<cc::SolidColorLayer> crashed_layer =
loyso0940d412016-03-14 01:30:3139 cc::SolidColorLayer::Create();
lfgfd437a272015-11-24 21:24:5340 crashed_layer->SetMasksToBounds(true);
Bo Liuffa01b022018-09-27 00:06:0541 crashed_layer->SetBackgroundColor(SK_ColorGRAY);
lfgcccffbe2016-03-10 00:05:4642
Fady Samuel4e717f52018-02-07 05:51:5043 if (child_frame_compositor_->GetLayer()) {
44 SkBitmap* sad_bitmap = child_frame_compositor_->GetSadPageBitmap();
45 if (sad_bitmap && frame_size_in_dip.width() > sad_bitmap->width() &&
46 frame_size_in_dip.height() > sad_bitmap->height()) {
lfgcccffbe2016-03-10 00:05:4647 scoped_refptr<cc::PictureImageLayer> sad_layer =
loyso0940d412016-03-14 01:30:3148 cc::PictureImageLayer::Create();
Vladimir Levinf67b0fc02017-10-06 01:48:1149 sad_layer->SetImage(cc::PaintImageBuilder::WithDefault()
Khushal73760a32018-02-16 19:29:5150 .set_id(cc::PaintImage::GetNextId())
51 .set_image(SkImage::MakeFromBitmap(*sad_bitmap),
52 cc::PaintImage::GetNextContentId())
Adrienne Walker3178dcb2018-02-13 23:49:4053 .TakePaintImage(),
54 SkMatrix::I(), false);
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
danakje1b64262018-05-05 01:35:5467 bool prevent_contents_opaque_changes = false;
danakj25f030112018-05-11 18:26:5468 child_frame_compositor_->SetLayer(std::move(crashed_layer),
Daniel Cheng02a0bc12018-09-19 00:42:0969 prevent_contents_opaque_changes,
70 false /* is_surface_layer */);
[email protected]f49722f2014-01-30 17:54:5071}
72
Saman Sami98c524052018-10-26 17:34:5773void ChildFrameCompositingHelper::SetSurfaceId(
Fady Samuel1cc05222017-11-17 10:42:2674 const viz::SurfaceId& surface_id,
Vladimir Levin6220cb62018-04-05 02:44:3875 const gfx::Size& frame_size_in_dip,
76 const cc::DeadlinePolicy& deadline) {
Saman Samic8fc00a2018-11-19 23:16:3577 if (surface_id_ == surface_id)
Fady Samuel64eb4b4f2017-11-09 00:31:5278 return;
79
Saman Samic8fc00a2018-11-19 23:16:3580 surface_id_ = surface_id;
Fady Samuel509c2d52017-08-28 19:00:5881
kylecharee539faa02018-01-22 17:00:5582 surface_layer_ = cc::SurfaceLayer::Create();
Fady Samuel509c2d52017-08-28 19:00:5883 surface_layer_->SetMasksToBounds(true);
sunxd2869c922018-05-14 20:48:3284 surface_layer_->SetSurfaceHitTestable(true);
Fady Samuel02de6ee2018-01-05 21:20:2185 surface_layer_->SetBackgroundColor(SK_ColorTRANSPARENT);
Fady Samuel509c2d52017-08-28 19:00:5886
Saman Sami98c524052018-10-26 17:34:5787 surface_layer_->SetSurfaceId(surface_id, deadline);
Fady Samuel509c2d52017-08-28 19:00:5888
danakje1b64262018-05-05 01:35:5489 // TODO(lfg): Investigate if it's possible to propagate the information
90 // about the child surface's opacity. https://crbug.com/629851.
91 bool prevent_contents_opaque_changes = true;
danakj25f030112018-05-11 18:26:5492 child_frame_compositor_->SetLayer(surface_layer_,
Daniel Cheng02a0bc12018-09-19 00:42:0993 prevent_contents_opaque_changes,
94 true /* is_surface_layer */);
Fady Samuel509c2d52017-08-28 19:00:5895
96 UpdateVisibility(true);
97
danakj25f030112018-05-11 18:26:5498 surface_layer_->SetBounds(frame_size_in_dip);
Fady Samuel509c2d52017-08-28 19:00:5899}
100
[email protected]bffc8302014-01-23 20:52:16101void ChildFrameCompositingHelper::UpdateVisibility(bool visible) {
danakj6a062b112018-05-17 16:25:45102 cc::Layer* layer = child_frame_compositor_->GetLayer();
103 if (layer)
104 layer->SetIsDrawable(visible);
[email protected]69b79122013-02-14 19:16:45105}
106
[email protected]0f21e8582013-01-11 11:06:56107} // namespace content