summaryrefslogtreecommitdiff
path: root/chromium/content/common
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-02-11 11:06:35 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-02-11 10:19:37 +0000
commit47c928e8a4986fa683c5763762fa0069c9b3debe (patch)
tree6e4893678bde0f02995d1a66639eccd24f947a47 /chromium/content/common
parent98a0061b881063a62c1941ccb67af6660ca89062 (diff)
downloadqtwebengine-chromium-47c928e8a4986fa683c5763762fa0069c9b3debe.tar.gz
BASELINE: Update Chromium to 49.0.2623.48
Change-Id: I684541113ff518e3a7d51dfd0b31962b06d10af1 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'chromium/content/common')
-rw-r--r--chromium/content/common/gpu/ca_layer_partial_damage_tree_mac.h56
-rw-r--r--chromium/content/common/gpu/ca_layer_partial_damage_tree_mac.mm287
-rw-r--r--chromium/content/common/gpu/ca_layer_tree_mac.h6
-rw-r--r--chromium/content/common/gpu/ca_layer_tree_mac.mm79
-rw-r--r--chromium/content/common/gpu/image_transport_surface_overlay_mac.h18
-rw-r--r--chromium/content/common/gpu/image_transport_surface_overlay_mac.mm305
6 files changed, 455 insertions, 296 deletions
diff --git a/chromium/content/common/gpu/ca_layer_partial_damage_tree_mac.h b/chromium/content/common/gpu/ca_layer_partial_damage_tree_mac.h
new file mode 100644
index 00000000000..f52000d6ddf
--- /dev/null
+++ b/chromium/content/common/gpu/ca_layer_partial_damage_tree_mac.h
@@ -0,0 +1,56 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_COMMON_GPU_CA_LAYER_PARTIAL_DAMAGE_TREE_MAC_H_
+#define CONTENT_COMMON_GPU_CA_LAYER_PARTIAL_DAMAGE_TREE_MAC_H_
+
+#include <IOSurface/IOSurface.h>
+#include <QuartzCore/QuartzCore.h>
+#include <deque>
+
+#include "base/mac/scoped_cftyperef.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/geometry/rect_f.h"
+
+namespace content {
+
+class CALayerPartialDamageTree {
+ public:
+ CALayerPartialDamageTree(bool allow_partial_swap,
+ base::ScopedCFTypeRef<IOSurfaceRef> io_surface,
+ const gfx::Rect& pixel_frame_rect);
+ ~CALayerPartialDamageTree();
+
+ base::ScopedCFTypeRef<IOSurfaceRef> RootLayerIOSurface();
+ void CommitCALayers(CALayer* superlayer,
+ scoped_ptr<CALayerPartialDamageTree> old_tree,
+ float scale_factor,
+ const gfx::Rect& pixel_damage_rect);
+
+ private:
+ class OverlayPlane;
+
+ // This will populate |partial_damage_planes_|, potentially re-using the
+ // CALayers and |partial_damage_planes_| from |old_tree|. After this function
+ // completes, the back() of |partial_damage_planes_| is the plane that will
+ // be updated this frame (and if it is empty, then the root plane will be
+ // updated).
+ void UpdatePartialDamagePlanes(CALayerPartialDamageTree* old_tree,
+ const gfx::Rect& pixel_damage_rect);
+
+ void UpdateRootAndPartialDamagePlanes(
+ scoped_ptr<CALayerPartialDamageTree> old_tree,
+ const gfx::Rect& pixel_damage_rect);
+
+ void UpdateCALayers(CALayer* superlayer, float scale_factor);
+
+ const bool allow_partial_swap_;
+ scoped_ptr<OverlayPlane> root_plane_;
+ std::deque<scoped_ptr<OverlayPlane>> partial_damage_planes_;
+};
+
+} // content
+
+#endif // CONTENT_COMMON_GPU_CA_LAYER_PARTIAL_DAMAGE_TREE_MAC_H_
diff --git a/chromium/content/common/gpu/ca_layer_partial_damage_tree_mac.mm b/chromium/content/common/gpu/ca_layer_partial_damage_tree_mac.mm
new file mode 100644
index 00000000000..f42738947a0
--- /dev/null
+++ b/chromium/content/common/gpu/ca_layer_partial_damage_tree_mac.mm
@@ -0,0 +1,287 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/gpu/ca_layer_partial_damage_tree_mac.h"
+
+#include "base/command_line.h"
+#include "base/mac/scoped_nsobject.h"
+#include "base/mac/sdk_forward_declarations.h"
+#include "base/trace_event/trace_event.h"
+#include "ui/base/ui_base_switches.h"
+#include "ui/gfx/transform.h"
+
+@interface CALayer(Private)
+-(void)setContentsChanged;
+@end
+
+namespace content {
+namespace {
+
+// When selecting a CALayer to re-use for partial damage, this is the maximum
+// fraction of the merged layer's pixels that may be not-updated by the swap
+// before we consider the CALayer to not be a good enough match, and create a
+// new one.
+const float kMaximumPartialDamageWasteFraction = 1.2f;
+
+// The maximum number of partial damage layers that may be created before we
+// give up and remove them all (doing full damage in the process).
+const size_t kMaximumPartialDamageLayers = 8;
+
+} // namespace
+
+class CALayerPartialDamageTree::OverlayPlane {
+ public:
+ OverlayPlane(base::ScopedCFTypeRef<IOSurfaceRef> io_surface,
+ const gfx::Rect& pixel_frame_rect,
+ const gfx::RectF& contents_rect)
+ : io_surface(io_surface),
+ contents_rect(contents_rect),
+ pixel_frame_rect(pixel_frame_rect),
+ layer_needs_update(true) {}
+
+ ~OverlayPlane() {
+ [ca_layer setContents:nil];
+ [ca_layer removeFromSuperlayer];
+ ca_layer.reset();
+ }
+
+ const base::ScopedCFTypeRef<IOSurfaceRef> io_surface;
+ const gfx::RectF contents_rect;
+ const gfx::Rect pixel_frame_rect;
+ bool layer_needs_update;
+ base::scoped_nsobject<CALayer> ca_layer;
+
+ void TakeCALayerFrom(OverlayPlane* other_plane) {
+ ca_layer.swap(other_plane->ca_layer);
+ }
+
+ void UpdateProperties(float scale_factor) {
+ if (layer_needs_update) {
+ [ca_layer setOpaque:YES];
+
+ id new_contents = static_cast<id>(io_surface.get());
+ if ([ca_layer contents] == new_contents)
+ [ca_layer setContentsChanged];
+ else
+ [ca_layer setContents:new_contents];
+ [ca_layer setContentsRect:contents_rect.ToCGRect()];
+
+ [ca_layer setAnchorPoint:CGPointZero];
+
+ if ([ca_layer respondsToSelector:(@selector(setContentsScale:))])
+ [ca_layer setContentsScale:scale_factor];
+ gfx::RectF dip_frame_rect = gfx::RectF(pixel_frame_rect);
+ dip_frame_rect.Scale(1 / scale_factor);
+ [ca_layer setBounds:CGRectMake(0, 0, dip_frame_rect.width(),
+ dip_frame_rect.height())];
+ [ca_layer
+ setPosition:CGPointMake(dip_frame_rect.x(), dip_frame_rect.y())];
+ }
+ static bool show_borders =
+ base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kShowMacOverlayBorders);
+ if (show_borders) {
+ base::ScopedCFTypeRef<CGColorRef> color;
+ if (!layer_needs_update) {
+ // Green represents contents that are unchanged across frames.
+ color.reset(CGColorCreateGenericRGB(0, 1, 0, 1));
+ } else {
+ // Red represents damaged contents.
+ color.reset(CGColorCreateGenericRGB(1, 0, 0, 1));
+ }
+ [ca_layer setBorderWidth:1];
+ [ca_layer setBorderColor:color];
+ }
+ layer_needs_update = false;
+ }
+
+ private:
+};
+
+void CALayerPartialDamageTree::UpdatePartialDamagePlanes(
+ CALayerPartialDamageTree* old_tree,
+ const gfx::Rect& pixel_damage_rect) {
+ // Don't create partial damage layers if partial swap is disabled.
+ if (!allow_partial_swap_)
+ return;
+ // Only create partial damage layers when building on top of an existing tree.
+ if (!old_tree)
+ return;
+ // If the frame size has changed, discard all of the old partial damage
+ // layers.
+ if (old_tree->root_plane_->pixel_frame_rect != root_plane_->pixel_frame_rect)
+ return;
+ // If there is full damage, discard all of the old partial damage layers.
+ if (pixel_damage_rect == root_plane_->pixel_frame_rect)
+ return;
+
+ // If there is no damage, don't change anything.
+ if (pixel_damage_rect.IsEmpty()) {
+ std::swap(partial_damage_planes_, old_tree->partial_damage_planes_);
+ return;
+ }
+
+ // Find the last partial damage plane to re-use the CALayer from. Grow the
+ // new rect for this layer to include this damage, and all nearby partial
+ // damage layers.
+ scoped_ptr<OverlayPlane> plane_for_swap;
+ {
+ auto plane_to_reuse_iter = old_tree->partial_damage_planes_.end();
+ gfx::Rect plane_to_reuse_enlarged_pixel_damage_rect;
+
+ for (auto old_plane_iter = old_tree->partial_damage_planes_.begin();
+ old_plane_iter != old_tree->partial_damage_planes_.end();
+ ++old_plane_iter) {
+ gfx::Rect enlarged_pixel_damage_rect =
+ (*old_plane_iter)->pixel_frame_rect;
+ enlarged_pixel_damage_rect.Union(pixel_damage_rect);
+
+ // Compute the fraction of the pixels that would not be updated by this
+ // swap. If it is too big, try another layer.
+ float waste_fraction = enlarged_pixel_damage_rect.size().GetArea() * 1.f /
+ pixel_damage_rect.size().GetArea();
+ if (waste_fraction > kMaximumPartialDamageWasteFraction)
+ continue;
+
+ plane_to_reuse_iter = old_plane_iter;
+ plane_to_reuse_enlarged_pixel_damage_rect.Union(
+ enlarged_pixel_damage_rect);
+ }
+ if (plane_to_reuse_iter != old_tree->partial_damage_planes_.end()) {
+ gfx::RectF enlarged_contents_rect =
+ gfx::RectF(plane_to_reuse_enlarged_pixel_damage_rect);
+ enlarged_contents_rect.Scale(1. / root_plane_->pixel_frame_rect.width(),
+ 1. / root_plane_->pixel_frame_rect.height());
+
+ plane_for_swap.reset(new OverlayPlane(
+ root_plane_->io_surface, plane_to_reuse_enlarged_pixel_damage_rect,
+ enlarged_contents_rect));
+
+ plane_for_swap->TakeCALayerFrom((*plane_to_reuse_iter).get());
+ if (*plane_to_reuse_iter != old_tree->partial_damage_planes_.back()) {
+ CALayer* superlayer = [plane_for_swap->ca_layer superlayer];
+ [plane_for_swap->ca_layer removeFromSuperlayer];
+ [superlayer addSublayer:plane_for_swap->ca_layer];
+ }
+ }
+ }
+
+ // If we haven't found an appropriate layer to re-use, create a new one, if
+ // we haven't already created too many.
+ if (!plane_for_swap.get() &&
+ old_tree->partial_damage_planes_.size() < kMaximumPartialDamageLayers) {
+ gfx::RectF contents_rect = gfx::RectF(pixel_damage_rect);
+ contents_rect.Scale(1. / root_plane_->pixel_frame_rect.width(),
+ 1. / root_plane_->pixel_frame_rect.height());
+ plane_for_swap.reset(new OverlayPlane(root_plane_->io_surface,
+ pixel_damage_rect, contents_rect));
+ }
+
+ // And if we still don't have a layer, do full damage.
+ if (!plane_for_swap.get())
+ return;
+
+ // Walk all old partial damage planes. Remove anything that is now completely
+ // covered, and move everything else into the new |partial_damage_planes_|.
+ for (auto& old_plane : old_tree->partial_damage_planes_) {
+ if (!old_plane.get())
+ continue;
+ // Intersect the planes' frames with the new root plane to ensure that
+ // they don't get kept alive inappropriately.
+ gfx::Rect old_plane_frame_rect = old_plane->pixel_frame_rect;
+ old_plane_frame_rect.Intersect(root_plane_->pixel_frame_rect);
+
+ bool old_plane_covered_by_swap = false;
+ if (plane_for_swap.get() &&
+ plane_for_swap->pixel_frame_rect.Contains(old_plane_frame_rect)) {
+ old_plane_covered_by_swap = true;
+ }
+ if (!old_plane_covered_by_swap) {
+ DCHECK(old_plane->ca_layer);
+ partial_damage_planes_.push_back(std::move(old_plane));
+ }
+ }
+
+ partial_damage_planes_.push_back(std::move(plane_for_swap));
+}
+
+void CALayerPartialDamageTree::UpdateRootAndPartialDamagePlanes(
+ scoped_ptr<CALayerPartialDamageTree> old_tree,
+ const gfx::Rect& pixel_damage_rect) {
+ // First update the partial damage tree.
+ UpdatePartialDamagePlanes(old_tree.get(), pixel_damage_rect);
+ if (old_tree) {
+ if (partial_damage_planes_.empty()) {
+ // If there are no partial damage planes, then we will be updating the
+ // root layer. Take the CALayer from the old tree.
+ root_plane_->TakeCALayerFrom(old_tree->root_plane_.get());
+ } else {
+ // If there is a partial damage tree, then just take the old plane
+ // from the previous frame, so that there is no update to it.
+ root_plane_.swap(old_tree->root_plane_);
+ }
+ }
+}
+
+void CALayerPartialDamageTree::UpdateCALayers(CALayer* superlayer,
+ float scale_factor) {
+ if (!allow_partial_swap_) {
+ DCHECK(partial_damage_planes_.empty());
+ return;
+ }
+
+ // Allocate and update CALayers for the backbuffer and partial damage layers.
+ if (!root_plane_->ca_layer) {
+ DCHECK(partial_damage_planes_.empty());
+ root_plane_->ca_layer.reset([[CALayer alloc] init]);
+ [superlayer setSublayers:nil];
+ [superlayer addSublayer:root_plane_->ca_layer];
+ }
+ // Excessive logging to debug white screens (crbug.com/583805).
+ // TODO(ccameron): change this back to a DLOG.
+ if ([root_plane_->ca_layer superlayer] != superlayer) {
+ LOG(ERROR) << "CALayerPartialDamageTree root layer not attached to tree.";
+ }
+ for (auto& plane : partial_damage_planes_) {
+ if (!plane->ca_layer) {
+ DCHECK(plane == partial_damage_planes_.back());
+ plane->ca_layer.reset([[CALayer alloc] init]);
+ }
+ if (![plane->ca_layer superlayer]) {
+ DCHECK(plane == partial_damage_planes_.back());
+ [superlayer addSublayer:plane->ca_layer];
+ }
+ }
+ root_plane_->UpdateProperties(scale_factor);
+ for (auto& plane : partial_damage_planes_)
+ plane->UpdateProperties(scale_factor);
+}
+
+CALayerPartialDamageTree::CALayerPartialDamageTree(
+ bool allow_partial_swap,
+ base::ScopedCFTypeRef<IOSurfaceRef> io_surface,
+ const gfx::Rect& pixel_frame_rect)
+ : allow_partial_swap_(allow_partial_swap) {
+ root_plane_.reset(
+ new OverlayPlane(io_surface, pixel_frame_rect, gfx::RectF(0, 0, 1, 1)));
+}
+
+CALayerPartialDamageTree::~CALayerPartialDamageTree() {}
+
+base::ScopedCFTypeRef<IOSurfaceRef>
+CALayerPartialDamageTree::RootLayerIOSurface() {
+ return root_plane_->io_surface;
+}
+
+void CALayerPartialDamageTree::CommitCALayers(
+ CALayer* superlayer,
+ scoped_ptr<CALayerPartialDamageTree> old_tree,
+ float scale_factor,
+ const gfx::Rect& pixel_damage_rect) {
+ TRACE_EVENT0("gpu", "CALayerPartialDamageTree::CommitCALayers");
+ UpdateRootAndPartialDamagePlanes(std::move(old_tree), pixel_damage_rect);
+ UpdateCALayers(superlayer, scale_factor);
+}
+
+} // namespace content
diff --git a/chromium/content/common/gpu/ca_layer_tree_mac.h b/chromium/content/common/gpu/ca_layer_tree_mac.h
index 163474eb9cd..d20bdb0d8be 100644
--- a/chromium/content/common/gpu/ca_layer_tree_mac.h
+++ b/chromium/content/common/gpu/ca_layer_tree_mac.h
@@ -163,11 +163,13 @@ class CALayerTree {
ContentLayer* old_layer,
float scale_factor);
- base::ScopedCFTypeRef<IOSurfaceRef> io_surface;
+ const base::ScopedCFTypeRef<IOSurfaceRef> io_surface;
gfx::RectF contents_rect;
gfx::Rect rect;
unsigned background_color = 0;
- unsigned edge_aa_mask = 0;
+ // Note that the CoreAnimation edge antialiasing mask is not the same as
+ // the edge antialiasing mask passed to the constructor.
+ CAEdgeAntialiasingMask ca_edge_aa_mask = 0;
float opacity = 1;
base::scoped_nsobject<CALayer> ca_layer;
diff --git a/chromium/content/common/gpu/ca_layer_tree_mac.mm b/chromium/content/common/gpu/ca_layer_tree_mac.mm
index 47343c4ff05..8c7d93886a5 100644
--- a/chromium/content/common/gpu/ca_layer_tree_mac.mm
+++ b/chromium/content/common/gpu/ca_layer_tree_mac.mm
@@ -6,6 +6,8 @@
#include "base/command_line.h"
#include "base/mac/sdk_forward_declarations.h"
+#include "base/trace_event/trace_event.h"
+#include "gpu/GLES2/gl2extchromium.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/cocoa/animation_utils.h"
#include "ui/base/ui_base_switches.h"
@@ -27,8 +29,10 @@ bool CALayerTree::ScheduleCALayer(
unsigned background_color,
unsigned edge_aa_mask,
float opacity) {
+ // Excessive logging to debug white screens (crbug.com/583805).
+ // TODO(ccameron): change this back to a DLOG.
if (has_committed_) {
- DLOG(ERROR) << "ScheduleCALayer called after CommitScheduledCALayers.";
+ LOG(ERROR) << "ScheduleCALayer called after CommitScheduledCALayers.";
return false;
}
return root_layer_.AddContentLayer(is_clipped, clip_rect, sorting_context_id,
@@ -39,6 +43,7 @@ bool CALayerTree::ScheduleCALayer(
void CALayerTree::CommitScheduledCALayers(CALayer* superlayer,
scoped_ptr<CALayerTree> old_tree,
float scale_factor) {
+ TRACE_EVENT0("gpu", "CALayerTree::CommitScheduledCALayers");
RootLayer* old_root_layer = nullptr;
if (old_tree) {
DCHECK(old_tree->has_committed_);
@@ -117,24 +122,62 @@ CALayerTree::ContentLayer::ContentLayer(
contents_rect(contents_rect),
rect(rect),
background_color(background_color),
- edge_aa_mask(edge_aa_mask),
- opacity(opacity) {}
+ ca_edge_aa_mask(0),
+ opacity(opacity) {
+ // Because the root layer has setGeometryFlipped:YES, there is some ambiguity
+ // about what exactly top and bottom mean. This ambiguity is resolved in
+ // different ways for solid color CALayers and for CALayers that have content
+ // (surprise!). For CALayers with IOSurface content, the top edge in the AA
+ // mask refers to what appears as the bottom edge on-screen. For CALayers
+ // without content (solid color layers), the top edge in the AA mask is the
+ // top edge on-screen.
+ // http://crbug.com/567946
+ if (edge_aa_mask & GL_CA_LAYER_EDGE_LEFT_CHROMIUM)
+ ca_edge_aa_mask |= kCALayerLeftEdge;
+ if (edge_aa_mask & GL_CA_LAYER_EDGE_RIGHT_CHROMIUM)
+ ca_edge_aa_mask |= kCALayerRightEdge;
+ if (io_surface) {
+ if (edge_aa_mask & GL_CA_LAYER_EDGE_TOP_CHROMIUM)
+ ca_edge_aa_mask |= kCALayerBottomEdge;
+ if (edge_aa_mask & GL_CA_LAYER_EDGE_BOTTOM_CHROMIUM)
+ ca_edge_aa_mask |= kCALayerTopEdge;
+ } else {
+ if (edge_aa_mask & GL_CA_LAYER_EDGE_TOP_CHROMIUM)
+ ca_edge_aa_mask |= kCALayerTopEdge;
+ if (edge_aa_mask & GL_CA_LAYER_EDGE_BOTTOM_CHROMIUM)
+ ca_edge_aa_mask |= kCALayerBottomEdge;
+ }
+
+ // Ensure that the IOSurface be in use as soon as it is added to a
+ // ContentLayer, so that, by the time that the call to SwapBuffers completes,
+ // all IOSurfaces that can be used as CALayer contents in the future will be
+ // marked as InUse.
+ if (io_surface)
+ IOSurfaceIncrementUseCount(io_surface);
+}
CALayerTree::ContentLayer::ContentLayer(ContentLayer&& layer)
: io_surface(layer.io_surface),
contents_rect(layer.contents_rect),
rect(layer.rect),
background_color(layer.background_color),
- edge_aa_mask(layer.edge_aa_mask),
+ ca_edge_aa_mask(layer.ca_edge_aa_mask),
opacity(layer.opacity),
ca_layer(layer.ca_layer) {
DCHECK(!layer.ca_layer);
- layer.io_surface.reset();
layer.ca_layer.reset();
+ // See remarks in the non-move constructor.
+ if (io_surface)
+ IOSurfaceIncrementUseCount(io_surface);
}
CALayerTree::ContentLayer::~ContentLayer() {
[ca_layer removeFromSuperlayer];
+ // By the time the destructor is called, the IOSurface will have been passed
+ // to the WindowServer, and will remain InUse by the WindowServer as long as
+ // is needed to avoid recycling bugs.
+ if (io_surface)
+ IOSurfaceDecrementUseCount(io_surface);
}
bool CALayerTree::RootLayer::AddContentLayer(
@@ -165,7 +208,9 @@ bool CALayerTree::RootLayer::AddContentLayer(
current_layer.sorting_context_id == sorting_context_id &&
(current_layer.is_clipped != is_clipped ||
current_layer.clip_rect != clip_rect)) {
- DLOG(ERROR) << "CALayer changed clip inside non-zero sorting context.";
+ // Excessive logging to debug white screens (crbug.com/583805).
+ // TODO(ccameron): change this back to a DLOG.
+ LOG(ERROR) << "CALayer changed clip inside non-zero sorting context.";
return false;
}
if (!is_singleton_sorting_context &&
@@ -232,7 +277,11 @@ void CALayerTree::RootLayer::CommitToCA(CALayer* superlayer,
[superlayer addSublayer:ca_layer];
[superlayer setBorderWidth:0];
}
- DCHECK_EQ([ca_layer superlayer], superlayer);
+ // Excessive logging to debug white screens (crbug.com/583805).
+ // TODO(ccameron): change this back to a DCHECK.
+ if ([ca_layer superlayer] != superlayer) {
+ LOG(ERROR) << "CALayerTree root layer not attached to tree.";
+ }
for (size_t i = 0; i < clip_and_sorting_layers.size(); ++i) {
ClipAndSortingLayer* old_clip_and_sorting_layer = nullptr;
@@ -260,7 +309,11 @@ void CALayerTree::ClipAndSortingLayer::CommitToCA(
[ca_layer setAnchorPoint:CGPointZero];
[superlayer addSublayer:ca_layer];
}
- DCHECK_EQ([ca_layer superlayer], superlayer);
+ // Excessive logging to debug white screens (crbug.com/583805).
+ // TODO(ccameron): change this back to a DCHECK.
+ if ([ca_layer superlayer] != superlayer) {
+ LOG(ERROR) << "CALayerTree root layer not attached to tree.";
+ }
if (update_is_clipped)
[ca_layer setMasksToBounds:is_clipped];
@@ -333,7 +386,7 @@ void CALayerTree::ContentLayer::CommitToCA(CALayer* superlayer,
bool update_contents_rect = true;
bool update_rect = true;
bool update_background_color = true;
- bool update_edge_aa_mask = true;
+ bool update_ca_edge_aa_mask = true;
bool update_opacity = true;
if (old_layer) {
DCHECK(old_layer->ca_layer);
@@ -342,7 +395,7 @@ void CALayerTree::ContentLayer::CommitToCA(CALayer* superlayer,
update_contents_rect = old_layer->contents_rect != contents_rect;
update_rect = old_layer->rect != rect;
update_background_color = old_layer->background_color != background_color;
- update_edge_aa_mask = old_layer->edge_aa_mask != edge_aa_mask;
+ update_ca_edge_aa_mask = old_layer->ca_edge_aa_mask != ca_edge_aa_mask;
update_opacity = old_layer->opacity != opacity;
} else {
ca_layer.reset([[CALayer alloc] init]);
@@ -352,7 +405,7 @@ void CALayerTree::ContentLayer::CommitToCA(CALayer* superlayer,
DCHECK_EQ([ca_layer superlayer], superlayer);
bool update_anything = update_contents || update_contents_rect ||
update_rect || update_background_color ||
- update_edge_aa_mask || update_opacity;
+ update_ca_edge_aa_mask || update_opacity;
if (update_contents) {
[ca_layer setContents:static_cast<id>(io_surface.get())];
@@ -378,8 +431,8 @@ void CALayerTree::ContentLayer::CommitToCA(CALayer* superlayer,
CGColorSpaceCreateWithName(kCGColorSpaceSRGB), rgba_color_components));
[ca_layer setBackgroundColor:srgb_background_color];
}
- if (update_edge_aa_mask)
- [ca_layer setEdgeAntialiasingMask:edge_aa_mask];
+ if (update_ca_edge_aa_mask)
+ [ca_layer setEdgeAntialiasingMask:ca_edge_aa_mask];
if (update_opacity)
[ca_layer setOpacity:opacity];
diff --git a/chromium/content/common/gpu/image_transport_surface_overlay_mac.h b/chromium/content/common/gpu/image_transport_surface_overlay_mac.h
index 5b86a5e9876..2103bbf7108 100644
--- a/chromium/content/common/gpu/image_transport_surface_overlay_mac.h
+++ b/chromium/content/common/gpu/image_transport_surface_overlay_mac.h
@@ -8,7 +8,6 @@
#include <list>
#include <vector>
-#include "base/memory/linked_ptr.h"
#import "base/mac/scoped_nsobject.h"
#include "base/timer/timer.h"
#include "content/common/gpu/gpu_command_buffer_stub.h"
@@ -22,6 +21,7 @@
namespace content {
class CALayerTree;
+class CALayerPartialDamageTree;
class ImageTransportSurfaceOverlayMac : public gfx::GLSurface,
public ImageTransportSurface,
@@ -78,13 +78,6 @@ class ImageTransportSurfaceOverlayMac : public gfx::GLSurface,
gfx::SwapResult SwapBuffersInternal(const gfx::Rect& pixel_damage_rect);
- void UpdateRootAndPartialDamagePlanes(
- const linked_ptr<OverlayPlane>& new_root_plane,
- const gfx::RectF& pixel_damage_rect);
- void UpdateRootAndPartialDamageCALayers(float scale_factor);
- void UpdateCALayerTree(scoped_ptr<CALayerTree> ca_layer_tree,
- float scale_factor);
-
// Returns true if the front of |pending_swaps_| has completed, or has timed
// out by |now|.
bool IsFirstPendingSwapReadyToDisplay(
@@ -125,7 +118,7 @@ class ImageTransportSurfaceOverlayMac : public gfx::GLSurface,
// Planes that have been scheduled, but have not had a subsequent SwapBuffers
// call made yet.
- linked_ptr<OverlayPlane> pending_root_plane_;
+ scoped_ptr<CALayerPartialDamageTree> pending_partial_damage_tree_;
scoped_ptr<CALayerTree> pending_ca_layer_tree_;
// A queue of all frames that have been created by SwapBuffersInternal but
@@ -134,8 +127,7 @@ class ImageTransportSurfaceOverlayMac : public gfx::GLSurface,
std::deque<linked_ptr<PendingSwap>> pending_swaps_;
// The planes that are currently being displayed on the screen.
- linked_ptr<OverlayPlane> current_root_plane_;
- std::list<linked_ptr<OverlayPlane>> current_partial_damage_planes_;
+ scoped_ptr<CALayerPartialDamageTree> current_partial_damage_tree_;
scoped_ptr<CALayerTree> current_ca_layer_tree_;
// The time of the last swap was issued. If this is more than two vsyncs, then
@@ -147,10 +139,6 @@ class ImageTransportSurfaceOverlayMac : public gfx::GLSurface,
base::TimeTicks vsync_timebase_;
base::TimeDelta vsync_interval_;
- // Calls to ScheduleCALayer come in back-to-front. This is reset to 1 at each
- // swap and increments with each call to ScheduleCALayer.
- int next_ca_layer_z_order_;
-
base::Timer display_pending_swap_timer_;
base::WeakPtrFactory<ImageTransportSurfaceOverlayMac> weak_factory_;
};
diff --git a/chromium/content/common/gpu/image_transport_surface_overlay_mac.mm b/chromium/content/common/gpu/image_transport_surface_overlay_mac.mm
index 724f135b729..1b0e3372e2d 100644
--- a/chromium/content/common/gpu/image_transport_surface_overlay_mac.mm
+++ b/chromium/content/common/gpu/image_transport_surface_overlay_mac.mm
@@ -20,15 +20,14 @@
typedef void* GLeglImageOES;
#endif
-#include "base/command_line.h"
#include "base/mac/scoped_cftyperef.h"
-#include "base/mac/sdk_forward_declarations.h"
+#include "base/trace_event/trace_event.h"
+#include "content/common/gpu/ca_layer_partial_damage_tree_mac.h"
#include "content/common/gpu/ca_layer_tree_mac.h"
#include "content/common/gpu/gpu_messages.h"
#include "ui/accelerated_widget_mac/io_surface_context.h"
#include "ui/base/cocoa/animation_utils.h"
#include "ui/base/cocoa/remote_layer_api.h"
-#include "ui/base/ui_base_switches.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/transform.h"
#include "ui/gl/gl_context.h"
@@ -59,16 +58,6 @@ const double kVSyncIntervalFractionForDisplayCallback = 0.5;
// they come.
const double kMaximumVSyncsBetweenSwapsForSmoothAnimation = 1.5;
-// When selecting a CALayer to re-use for partial damage, this is the maximum
-// fraction of the merged layer's pixels that may be not-updated by the swap
-// before we consider the CALayer to not be a good enough match, and create a
-// new one.
-const float kMaximumPartialDamageWasteFraction = 1.2f;
-
-// The maximum number of partial damage layers that may be created before we
-// give up and remove them all (doing full damage in the process).
-const size_t kMaximumPartialDamageLayers = 8;
-
void CheckGLErrors(const char* msg) {
GLenum gl_error;
while ((gl_error = glGetError()) != GL_NO_ERROR) {
@@ -94,88 +83,6 @@ scoped_refptr<gfx::GLSurface> ImageTransportSurfaceCreateNativeSurface(
return new ImageTransportSurfaceOverlayMac(manager, stub, handle);
}
-class ImageTransportSurfaceOverlayMac::OverlayPlane {
- public:
- static linked_ptr<OverlayPlane> CreateWithFrameRect(
- int z_order,
- base::ScopedCFTypeRef<IOSurfaceRef> io_surface,
- const gfx::RectF& pixel_frame_rect,
- const gfx::RectF& contents_rect) {
- gfx::Transform transform;
- transform.Translate(pixel_frame_rect.x(), pixel_frame_rect.y());
- return linked_ptr<OverlayPlane>(
- new OverlayPlane(z_order, io_surface, contents_rect, pixel_frame_rect));
- }
-
- ~OverlayPlane() {
- [ca_layer setContents:nil];
- [ca_layer removeFromSuperlayer];
- ca_layer.reset();
- }
-
- const int z_order;
- const base::ScopedCFTypeRef<IOSurfaceRef> io_surface;
- const gfx::RectF contents_rect;
- const gfx::RectF pixel_frame_rect;
- bool layer_needs_update;
- base::scoped_nsobject<CALayer> ca_layer;
-
- void TakeCALayerFrom(OverlayPlane* other_plane) {
- ca_layer.swap(other_plane->ca_layer);
- }
-
- void UpdateProperties(float scale_factor) {
- if (layer_needs_update) {
- [ca_layer setOpaque:YES];
-
- id new_contents = static_cast<id>(io_surface.get());
- if ([ca_layer contents] == new_contents && z_order == 0)
- [ca_layer setContentsChanged];
- else
- [ca_layer setContents:new_contents];
- [ca_layer setContentsRect:contents_rect.ToCGRect()];
-
- [ca_layer setAnchorPoint:CGPointZero];
-
- if ([ca_layer respondsToSelector:(@selector(setContentsScale:))])
- [ca_layer setContentsScale:scale_factor];
- gfx::RectF dip_frame_rect = gfx::RectF(pixel_frame_rect);
- dip_frame_rect.Scale(1 / scale_factor);
- [ca_layer setBounds:CGRectMake(0, 0, dip_frame_rect.width(),
- dip_frame_rect.height())];
- [ca_layer
- setPosition:CGPointMake(dip_frame_rect.x(), dip_frame_rect.y())];
- }
- static bool show_borders =
- base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kShowMacOverlayBorders);
- if (show_borders) {
- base::ScopedCFTypeRef<CGColorRef> color;
- if (!layer_needs_update) {
- // Green represents contents that are unchanged across frames.
- color.reset(CGColorCreateGenericRGB(0, 1, 0, 1));
- } else {
- // Red represents damaged contents.
- color.reset(CGColorCreateGenericRGB(1, 0, 0, 1));
- }
- [ca_layer setBorderWidth:1];
- [ca_layer setBorderColor:color];
- }
- layer_needs_update = false;
- }
-
- private:
- OverlayPlane(int z_order,
- base::ScopedCFTypeRef<IOSurfaceRef> io_surface,
- const gfx::RectF& contents_rect,
- const gfx::RectF& pixel_frame_rect)
- : z_order(z_order),
- io_surface(io_surface),
- contents_rect(contents_rect),
- pixel_frame_rect(pixel_frame_rect),
- layer_needs_update(true) {}
-};
-
class ImageTransportSurfaceOverlayMac::PendingSwap {
public:
PendingSwap() {}
@@ -185,7 +92,7 @@ class ImageTransportSurfaceOverlayMac::PendingSwap {
float scale_factor;
gfx::Rect pixel_damage_rect;
- linked_ptr<OverlayPlane> root_plane;
+ scoped_ptr<CALayerPartialDamageTree> partial_damage_tree;
scoped_ptr<CALayerTree> ca_layer_tree;
std::vector<ui::LatencyInfo> latency_info;
@@ -211,7 +118,6 @@ ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac(
scale_factor_(1),
gl_renderer_id_(0),
vsync_parameters_valid_(false),
- next_ca_layer_z_order_(1),
display_pending_swap_timer_(true, false),
weak_factory_(this) {
helper_.reset(new ImageTransportHelper(this, manager, stub, handle));
@@ -243,8 +149,9 @@ bool ImageTransportSurfaceOverlayMac::Initialize() {
void ImageTransportSurfaceOverlayMac::Destroy() {
DisplayAndClearAllPendingSwaps();
- current_partial_damage_planes_.clear();
- current_root_plane_.reset();
+
+ current_partial_damage_tree_.reset();
+ current_ca_layer_tree_.reset();
}
bool ImageTransportSurfaceOverlayMac::IsOffscreen() {
@@ -254,7 +161,6 @@ bool ImageTransportSurfaceOverlayMac::IsOffscreen() {
gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal(
const gfx::Rect& pixel_damage_rect) {
TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal");
- next_ca_layer_z_order_ = 1;
// Use the same concept of 'now' for the entire function. The duration of
// this function only affect the result if this function lasts across a vsync
@@ -285,8 +191,7 @@ gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal(
new_swap->pixel_size = pixel_size_;
new_swap->scale_factor = scale_factor_;
new_swap->pixel_damage_rect = pixel_damage_rect;
- new_swap->root_plane = pending_root_plane_;
- pending_root_plane_ = linked_ptr<OverlayPlane>();
+ new_swap->partial_damage_tree.swap(pending_partial_damage_tree_);
new_swap->ca_layer_tree.swap(pending_ca_layer_tree_);
new_swap->latency_info.swap(latency_info_);
@@ -366,15 +271,30 @@ void ImageTransportSurfaceOverlayMac::DisplayFirstPendingSwapImmediately() {
CheckGLErrors("while deleting active fence");
}
- // Update the plane lists.
+ // Update the CALayer hierarchy.
{
- // Sort the input planes by z-index, and remove any overlays from the
- // damage rect.
gfx::RectF pixel_damage_rect = gfx::RectF(swap->pixel_damage_rect);
ScopedCAActionDisabler disabler;
- UpdateRootAndPartialDamagePlanes(swap->root_plane, pixel_damage_rect);
- UpdateRootAndPartialDamageCALayers(swap->scale_factor);
- UpdateCALayerTree(std::move(swap->ca_layer_tree), swap->scale_factor);
+ if (swap->ca_layer_tree) {
+ swap->ca_layer_tree->CommitScheduledCALayers(
+ ca_root_layer_.get(), std::move(current_ca_layer_tree_),
+ swap->scale_factor);
+ current_ca_layer_tree_.swap(swap->ca_layer_tree);
+ current_partial_damage_tree_.reset();
+ } else if (swap->partial_damage_tree) {
+ swap->partial_damage_tree->CommitCALayers(
+ ca_root_layer_.get(), std::move(current_partial_damage_tree_),
+ swap->scale_factor, swap->pixel_damage_rect);
+ current_partial_damage_tree_.swap(swap->partial_damage_tree);
+ current_ca_layer_tree_.reset();
+ } else {
+ TRACE_EVENT0("gpu", "Blank frame: No overlays or CALayers");
+ [ca_root_layer_ setSublayers:nil];
+ current_partial_damage_tree_.reset();
+ current_ca_layer_tree_.reset();
+ }
+ swap->ca_layer_tree.reset();
+ swap->partial_damage_tree.reset();
}
// Update the latency info to reflect the swap time.
@@ -391,9 +311,9 @@ void ImageTransportSurfaceOverlayMac::DisplayFirstPendingSwapImmediately() {
GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params;
if (use_remote_layer_api_) {
params.ca_context_id = [ca_context_ contextId];
- } else if (current_root_plane_.get()) {
- params.io_surface.reset(
- IOSurfaceCreateMachPort(current_root_plane_->io_surface));
+ } else if (current_partial_damage_tree_) {
+ params.io_surface.reset(IOSurfaceCreateMachPort(
+ current_partial_damage_tree_->RootLayerIOSurface()));
}
params.size = swap->pixel_size;
params.scale_factor = swap->scale_factor;
@@ -404,157 +324,6 @@ void ImageTransportSurfaceOverlayMac::DisplayFirstPendingSwapImmediately() {
pending_swaps_.pop_front();
}
-void ImageTransportSurfaceOverlayMac::UpdateRootAndPartialDamagePlanes(
- const linked_ptr<OverlayPlane>& new_root_plane,
- const gfx::RectF& pixel_damage_rect) {
- std::list<linked_ptr<OverlayPlane>> old_partial_damage_planes;
- old_partial_damage_planes.swap(current_partial_damage_planes_);
- linked_ptr<OverlayPlane> plane_for_swap;
-
- // If there is no new root plane, remove everything.
- if (!new_root_plane.get()) {
- old_partial_damage_planes.clear();
- current_root_plane_.reset();
- return;
- }
-
- // If the frame's size changed, if we haven't updated the root layer, if
- // we have full damage, or if we don't support remote layers, then use the
- // root layer directly.
- if (!use_remote_layer_api_ || !current_root_plane_.get() ||
- current_root_plane_->pixel_frame_rect !=
- new_root_plane->pixel_frame_rect ||
- pixel_damage_rect == new_root_plane->pixel_frame_rect) {
- plane_for_swap = new_root_plane;
- }
-
- // Walk though the existing partial damage layers and see if there is one that
- // is appropriate to re-use.
- if (!plane_for_swap.get() && !pixel_damage_rect.IsEmpty()) {
- gfx::RectF plane_to_reuse_dip_enlarged_rect;
-
- // Find the last partial damage plane to re-use the CALayer from. Grow the
- // new rect for this layer to include this damage, and all nearby partial
- // damage layers.
- linked_ptr<OverlayPlane> plane_to_reuse;
- for (auto& old_plane : old_partial_damage_planes) {
- gfx::RectF dip_enlarged_rect = old_plane->pixel_frame_rect;
- dip_enlarged_rect.Union(pixel_damage_rect);
-
- // Compute the fraction of the pixels that would not be updated by this
- // swap. If it is too big, try another layer.
- float waste_fraction = dip_enlarged_rect.size().GetArea() * 1.f /
- pixel_damage_rect.size().GetArea();
- if (waste_fraction > kMaximumPartialDamageWasteFraction)
- continue;
-
- plane_to_reuse = old_plane;
- plane_to_reuse_dip_enlarged_rect.Union(dip_enlarged_rect);
- }
-
- if (plane_to_reuse.get()) {
- gfx::RectF enlarged_contents_rect = plane_to_reuse_dip_enlarged_rect;
- enlarged_contents_rect.Scale(
- 1. / new_root_plane->pixel_frame_rect.width(),
- 1. / new_root_plane->pixel_frame_rect.height());
-
- plane_for_swap = OverlayPlane::CreateWithFrameRect(
- 0, new_root_plane->io_surface, plane_to_reuse_dip_enlarged_rect,
- enlarged_contents_rect);
-
- plane_for_swap->TakeCALayerFrom(plane_to_reuse.get());
- if (plane_to_reuse != old_partial_damage_planes.back())
- [plane_for_swap->ca_layer removeFromSuperlayer];
- }
- }
-
- // If we haven't found an appropriate layer to re-use, create a new one, if
- // we haven't already created too many.
- if (!plane_for_swap.get() && !pixel_damage_rect.IsEmpty() &&
- old_partial_damage_planes.size() < kMaximumPartialDamageLayers) {
- gfx::RectF contents_rect = gfx::RectF(pixel_damage_rect);
- contents_rect.Scale(1. / new_root_plane->pixel_frame_rect.width(),
- 1. / new_root_plane->pixel_frame_rect.height());
- plane_for_swap = OverlayPlane::CreateWithFrameRect(
- 0, new_root_plane->io_surface, pixel_damage_rect, contents_rect);
- }
-
- // And if we still don't have a layer, use the root layer.
- if (!plane_for_swap.get() && !pixel_damage_rect.IsEmpty())
- plane_for_swap = new_root_plane;
-
- // Walk all old partial damage planes. Remove anything that is now completely
- // covered, and move everything else into the new
- // |current_partial_damage_planes_|.
- for (auto& old_plane : old_partial_damage_planes) {
- // Intersect the planes' frames with the new root plane to ensure that
- // they don't get kept alive inappropriately.
- gfx::RectF old_plane_frame_rect = old_plane->pixel_frame_rect;
- old_plane_frame_rect.Intersect(new_root_plane->pixel_frame_rect);
-
- bool old_plane_covered_by_swap = false;
- if (plane_for_swap.get() &&
- plane_for_swap->pixel_frame_rect.Contains(old_plane_frame_rect)) {
- old_plane_covered_by_swap = true;
- }
- if (!old_plane_covered_by_swap) {
- DCHECK(old_plane->ca_layer);
- current_partial_damage_planes_.push_back(old_plane);
- }
- }
-
- // Finally, add the new swap's plane at the back of the list, if it exists.
- if (plane_for_swap == new_root_plane) {
- current_root_plane_ = new_root_plane;
- } else if (plane_for_swap.get()) {
- current_partial_damage_planes_.push_back(plane_for_swap);
- }
-}
-
-void ImageTransportSurfaceOverlayMac::UpdateRootAndPartialDamageCALayers(
- float scale_factor) {
- if (!use_remote_layer_api_) {
- DCHECK(current_partial_damage_planes_.empty());
- return;
- }
-
- // Allocate and update CALayers for the backbuffer and partial damage layers.
- if (current_root_plane_.get()) {
- if (!current_root_plane_->ca_layer) {
- current_root_plane_->ca_layer.reset([[CALayer alloc] init]);
- [ca_root_layer_ setSublayers:nil];
- [ca_root_layer_ addSublayer:current_root_plane_->ca_layer];
- }
- }
- for (auto& plane : current_partial_damage_planes_) {
- if (!plane->ca_layer) {
- DCHECK(plane == current_partial_damage_planes_.back());
- plane->ca_layer.reset([[CALayer alloc] init]);
- }
- if (![plane->ca_layer superlayer]) {
- DCHECK(plane == current_partial_damage_planes_.back());
- [ca_root_layer_ addSublayer:plane->ca_layer];
- }
- }
- if (current_root_plane_.get())
- current_root_plane_->UpdateProperties(scale_factor);
- for (auto& plane : current_partial_damage_planes_)
- plane->UpdateProperties(scale_factor);
-}
-
-void ImageTransportSurfaceOverlayMac::UpdateCALayerTree(
- scoped_ptr<CALayerTree> ca_layer_tree,
- float scale_factor) {
- if (ca_layer_tree) {
- ca_layer_tree->CommitScheduledCALayers(
- ca_root_layer_.get(), std::move(current_ca_layer_tree_), scale_factor);
- current_ca_layer_tree_.swap(ca_layer_tree);
- ca_layer_tree.reset();
- } else {
- current_ca_layer_tree_.reset();
- }
-}
-
void ImageTransportSurfaceOverlayMac::DisplayAndClearAllPendingSwaps() {
TRACE_EVENT0("gpu",
"ImageTransportSurfaceOverlayMac::DisplayAndClearAllPendingSwaps");
@@ -645,10 +414,14 @@ bool ImageTransportSurfaceOverlayMac::ScheduleOverlayPlane(
DLOG(ERROR) << "Invalid non-zero Z order.";
return false;
}
-
- pending_root_plane_ = OverlayPlane::CreateWithFrameRect(
- z_order, static_cast<gl::GLImageIOSurface*>(image)->io_surface(),
- gfx::RectF(pixel_frame_rect), crop_rect);
+ if (pending_partial_damage_tree_) {
+ DLOG(ERROR) << "Only one overlay per swap is allowed.";
+ return false;
+ }
+ pending_partial_damage_tree_.reset(new CALayerPartialDamageTree(
+ use_remote_layer_api_,
+ static_cast<gl::GLImageIOSurface*>(image)->io_surface(),
+ pixel_frame_rect));
return true;
}