Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Unified Diff: content/browser/compositor/browser_compositor_view_private_mac.mm

Issue 441743003: Make remote CALayers work with browser compositor on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make more methods private Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/compositor/browser_compositor_view_private_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/compositor/browser_compositor_view_private_mac.mm
diff --git a/content/browser/compositor/browser_compositor_view_private_mac.mm b/content/browser/compositor/browser_compositor_view_private_mac.mm
index a21f8c5bfc2aab7ce2c2e371887209255fd63bbf..5457da35719fae8c4eeab665514c6a9b14416312 100644
--- a/content/browser/compositor/browser_compositor_view_private_mac.mm
+++ b/content/browser/compositor/browser_compositor_view_private_mac.mm
@@ -15,6 +15,7 @@
#include "content/browser/renderer_host/dip_util.h"
#include "content/browser/renderer_host/render_widget_resize_helper.h"
#include "content/browser/renderer_host/software_layer_mac.h"
+#include "content/common/gpu/surface_handles_mac.h"
#include "content/public/browser/context_factory.h"
#include "ui/base/cocoa/animation_utils.h"
#include "ui/gl/scoped_cgl.h"
@@ -119,12 +120,11 @@ void BrowserCompositorViewMacInternal::EndPumpingFrames() {
[accelerated_layer_ endPumpingFrames];
}
-void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
- IOSurfaceID io_surface_id,
- int output_surface_id,
+void BrowserCompositorViewMacInternal::GotAcceleratedFrame(
+ uint64 surface_handle, int output_surface_id,
const std::vector<ui::LatencyInfo>& latency_info,
- gfx::Size pixel_size,
- float scale_factor) {
+ gfx::Size pixel_size, float scale_factor) {
+ // Record the surface and latency info to use when acknowledging this frame.
DCHECK(!accelerated_layer_output_surface_id_);
accelerated_layer_output_surface_id_ = output_surface_id;
accelerated_latency_info_.insert(accelerated_latency_info_.end(),
@@ -139,18 +139,81 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
// Disable the fade-in or fade-out effect if we create or remove layers.
ScopedCAActionDisabler disabler;
- // If there is already an accelerated layer, but it has the wrong scale
- // factor or it was poisoned, remove the old layer and replace it.
- base::scoped_nsobject<CompositingIOSurfaceLayer> old_accelerated_layer;
- if (accelerated_layer_ && (
- [accelerated_layer_ context]->HasBeenPoisoned() ||
- [accelerated_layer_ iosurface]->scale_factor() != scale_factor)) {
- old_accelerated_layer = accelerated_layer_;
+ last_swap_size_dip_ = ConvertSizeToDIP(scale_factor, pixel_size);
+ switch (GetSurfaceHandleType(surface_handle)) {
+ case kSurfaceHandleTypeIOSurface: {
+ IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle(surface_handle);
+ GotAcceleratedIOSurfaceFrame(io_surface_id, pixel_size, scale_factor);
+ break;
+ }
+ case kSurfaceHandleTypeCAContext: {
+ CAContextID ca_context_id = CAContextIDFromSurfaceHandle(surface_handle);
+ GotAcceleratedCAContextFrame(ca_context_id, pixel_size, scale_factor);
+ break;
+ }
+ default:
+ LOG(ERROR) << "Unrecognized accelerated frame type.";
+ return;
+ }
+}
+
+void BrowserCompositorViewMacInternal::GotAcceleratedCAContextFrame(
+ CAContextID ca_context_id,
+ gfx::Size pixel_size,
+ float scale_factor) {
+ // In the layer is replaced, keep the old one around until after the new one
+ // is installed to avoid flashes.
+ base::scoped_nsobject<CALayerHost> old_accelerated_layer_host =
+ accelerated_layer_host_;
+
+ // Create the layer to host the layer exported by the GPU process with this
+ // particular CAContext ID.
+ if ([accelerated_layer_host_ contextId] != ca_context_id) {
+ accelerated_layer_host_.reset([[CALayerHost alloc] init]);
+ [accelerated_layer_host_ setContextId:ca_context_id];
+ [accelerated_layer_host_
+ setAutoresizingMask:kCALayerMaxXMargin|kCALayerMaxYMargin];
+ [flipped_layer_ addSublayer:accelerated_layer_host_];
+ }
+
+ // Acknowledge the frame to unblock the compositor immediately (the GPU
+ // process will do any required throttling).
+ AcceleratedLayerDidDrawFrame(true);
+
+ // If this replacing a same-type layer, remove it now that the new layer is
+ // in the heirarchy.
Ken Russell (switch to Gerrit) 2014/08/05 02:03:21 typo: hierarchy
ccameron 2014/08/05 04:29:59 Done.
+ if (old_accelerated_layer_host != accelerated_layer_host_)
+ [old_accelerated_layer_host removeFromSuperlayer];
+
+ // Remove any different-type layers that this is replacing.
Ken Russell (switch to Gerrit) 2014/08/05 02:03:21 The naming convention's getting confusing here. Co
ccameron 2014/08/05 04:29:59 You're right -- I was so excited to stop calling t
+ if (accelerated_layer_) {
+ [accelerated_layer_ resetClient];
+ [accelerated_layer_ removeFromSuperlayer];
accelerated_layer_.reset();
}
+ if (software_layer_) {
+ [software_layer_ removeFromSuperlayer];
+ software_layer_.reset();
+ }
+}
- // If there is not a layer for accelerated frames, create one.
- if (!accelerated_layer_) {
+void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
+ IOSurfaceID io_surface_id,
+ gfx::Size pixel_size,
+ float scale_factor) {
+ // In the layer is replaced, keep the old one around until after the new one
+ // is installed to avoid flashes.
+ base::scoped_nsobject<CompositingIOSurfaceLayer> old_accelerated_layer =
+ accelerated_layer_;
+
+ // Create or re-create an IOSurface layer if needed. If there already exists
+ // a layer but it has the wrong scale factor or it was poisoned, re-create the
+ // layer.
+ bool needs_new_layer =
+ !accelerated_layer_ ||
+ [accelerated_layer_ context]->HasBeenPoisoned() ||
+ [accelerated_layer_ iosurface]->scale_factor() != scale_factor;
+ if (needs_new_layer) {
scoped_refptr<content::CompositingIOSurfaceMac> iosurface =
content::CompositingIOSurfaceMac::Create();
accelerated_layer_.reset([[CompositingIOSurfaceLayer alloc]
@@ -174,7 +237,6 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
// Set the bounds of the accelerated layer to match the size of the frame.
// If the bounds changed, force the content to be displayed immediately.
- last_swap_size_dip_ = [accelerated_layer_ iosurface]->dip_io_surface_size();
CGRect new_layer_bounds = CGRectMake(
0, 0, last_swap_size_dip_.width(), last_swap_size_dip_.height());
bool bounds_changed = !CGRectEqualToRect(
@@ -183,14 +245,21 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
if (bounds_changed)
[accelerated_layer_ setNeedsDisplayAndDisplayAndAck];
- // If there was a software layer or an old accelerated layer, remove it.
- // Disable the fade-out animation as the layer is removed.
- {
- [software_layer_ removeFromSuperlayer];
- software_layer_.reset();
+ // If this replacing a same-type layer, remove it now that the new layer is
+ // in the heirarchy.
+ if (old_accelerated_layer != accelerated_layer_) {
[old_accelerated_layer resetClient];
[old_accelerated_layer removeFromSuperlayer];
- old_accelerated_layer.reset();
+ }
+
+ // Remove any different-type layers that this is replacing.
+ if (accelerated_layer_host_) {
+ [accelerated_layer_host_ removeFromSuperlayer];
+ accelerated_layer_host_.reset();
+ }
+ if (software_layer_) {
+ [software_layer_ removeFromSuperlayer];
+ software_layer_.reset();
}
}
@@ -221,8 +290,12 @@ void BrowserCompositorViewMacInternal::GotSoftwareFrame(
withScaleFactor:scale_factor];
last_swap_size_dip_ = ConvertSizeToDIP(scale_factor, pixel_size);
- // If there was an accelerated layer, remove it.
- {
+ // Remove any different-type layers that this is replacing.
+ if (accelerated_layer_host_) {
+ [accelerated_layer_host_ removeFromSuperlayer];
+ accelerated_layer_host_.reset();
+ }
+ if (accelerated_layer_) {
[accelerated_layer_ resetClient];
[accelerated_layer_ removeFromSuperlayer];
accelerated_layer_.reset();
@@ -271,6 +344,4 @@ BrowserCompositorViewMacInternal* BrowserCompositorViewMacInternal::
return found->second;
}
-
} // namespace content
-
« no previous file with comments | « content/browser/compositor/browser_compositor_view_private_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698