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

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

Issue 490393002: Simplify IOSurface CoreAnimation code: Part 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Lower similarity 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
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 90c834054313df4d868f3e913cf59c09f8a70d05..3e1971ca9c71936da1f066cd898b783e87dc46b2 100644
--- a/content/browser/compositor/browser_compositor_view_private_mac.mm
+++ b/content/browser/compositor/browser_compositor_view_private_mac.mm
@@ -10,11 +10,9 @@
#include "base/lazy_instance.h"
#include "base/message_loop/message_loop.h"
#include "content/browser/compositor/gpu_process_transport_factory.h"
-#include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
-#include "content/browser/renderer_host/compositing_iosurface_mac.h"
+#include "content/browser/compositor/software_layer_mac.h"
#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_handle_types_mac.h"
#include "content/public/browser/context_factory.h"
#include "ui/base/cocoa/animation_utils.h"
@@ -34,7 +32,8 @@ base::LazyInstance<WidgetToInternalsMap> g_widget_to_internals_map;
BrowserCompositorViewMacInternal::BrowserCompositorViewMacInternal()
: client_(NULL),
- accelerated_output_surface_id_(0) {
+ accelerated_output_surface_id_(0),
+ weak_factory_(this) {
// Disable the fade-in animation as the layers are added.
ScopedCAActionDisabler disabler;
@@ -110,7 +109,7 @@ bool BrowserCompositorViewMacInternal::HasFrameOfSize(
int BrowserCompositorViewMacInternal::GetRendererID() const {
if (io_surface_layer_)
- return [io_surface_layer_ iosurface]->GetRendererID();
+ return [io_surface_layer_ rendererID];
return 0;
}
@@ -134,7 +133,7 @@ void BrowserCompositorViewMacInternal::GotAcceleratedFrame(
// If there is no client and therefore no superview to draw into, early-out.
if (!client_) {
- AcceleratedLayerDidDrawFrame();
+ IOSurfaceLayerDidDrawFrame();
return;
}
@@ -180,7 +179,7 @@ void BrowserCompositorViewMacInternal::GotAcceleratedCAContextFrame(
// Acknowledge the frame to unblock the compositor immediately (the GPU
// process will do any required throttling).
- AcceleratedLayerDidDrawFrame();
+ IOSurfaceLayerDidDrawFrame();
// If this replacing a same-type layer, remove it now that the new layer is
// in the hierarchy.
@@ -198,68 +197,33 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
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_io_surface_layer =
+ base::scoped_nsobject<IOSurfaceLayer> old_io_surface_layer =
io_surface_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 =
- !io_surface_layer_ ||
- [io_surface_layer_ context]->HasBeenPoisoned() ||
- [io_surface_layer_ iosurface]->scale_factor() != scale_factor;
+ // a layer but it has the wrong scale factor re-create the layer.
+ bool needs_new_layer = !io_surface_layer_ ||
+ [io_surface_layer_ scaleFactor] != scale_factor;
if (needs_new_layer) {
- scoped_refptr<content::CompositingIOSurfaceMac> iosurface =
- content::CompositingIOSurfaceMac::Create();
- if (!iosurface) {
- LOG(ERROR) << "Failed to create CompositingIOSurfaceMac";
- } else {
- io_surface_layer_.reset([[CompositingIOSurfaceLayer alloc]
- initWithIOSurface:iosurface
- withScaleFactor:scale_factor
- withClient:this]);
- if (io_surface_layer_)
- [flipped_layer_ addSublayer:io_surface_layer_];
- else
- LOG(ERROR) << "Failed to create CompositingIOSurfaceLayer";
- }
+ io_surface_layer_.reset([[IOSurfaceLayer alloc]
+ initWithClient:this withScaleFactor:scale_factor]);
+ DCHECK(io_surface_layer_);
+ [flipped_layer_ addSublayer:io_surface_layer_];
}
- // Open the provided IOSurface.
- if (io_surface_layer_) {
- bool result = true;
- gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
- [io_surface_layer_ context]->cgl_context());
- result = [io_surface_layer_ iosurface]->SetIOSurfaceWithContextCurrent(
- [io_surface_layer_ context], io_surface_id, pixel_size, scale_factor);
- if (!result) {
- DestroyIOSurfaceLayer(io_surface_layer_);
- LOG(ERROR) << "Failed open IOSurface in CompositingIOSurfaceLayer";
- }
- }
-
- // Give a final complaint if anything with the layer's creation went wrong.
- // This frame will appear blank, the compositor will try to create another,
- // and maybe that will go better.
- if (!io_surface_layer_) {
- LOG(ERROR) << "CompositingIOSurfaceLayer is nil, tab will be blank";
- AcceleratedLayerHitError();
- }
+ [io_surface_layer_ gotFrameWithIOSurface:io_surface_id
+ withPixelSize:pixel_size
+ withScaleFactor:scale_factor];
- // Make the CALayer draw and set its size appropriately.
- if (io_surface_layer_) {
- [io_surface_layer_ gotNewFrame];
-
- // 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.
- CGRect new_layer_bounds = CGRectMake(
- 0, 0, last_swap_size_dip_.width(), last_swap_size_dip_.height());
- bool bounds_changed = !CGRectEqualToRect(
- new_layer_bounds, [io_surface_layer_ bounds]);
- [io_surface_layer_ setBounds:new_layer_bounds];
- if (bounds_changed)
- [io_surface_layer_ setNeedsDisplayAndDisplayAndAck];
- }
+ // 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.
+ CGRect new_layer_bounds = CGRectMake(
+ 0, 0, last_swap_size_dip_.width(), last_swap_size_dip_.height());
+ bool bounds_changed = !CGRectEqualToRect(
+ new_layer_bounds, [io_surface_layer_ bounds]);
+ [io_surface_layer_ setBounds:new_layer_bounds];
+ if (bounds_changed)
+ [io_surface_layer_ setNeedsDisplayAndDisplayAndAck];
// If this replacing a same-type layer, remove it now that the new layer is
// in the hierarchy.
@@ -313,7 +277,7 @@ void BrowserCompositorViewMacInternal::DestroyCAContextLayer(
}
void BrowserCompositorViewMacInternal::DestroyIOSurfaceLayer(
- base::scoped_nsobject<CompositingIOSurfaceLayer> io_surface_layer) {
+ base::scoped_nsobject<IOSurfaceLayer> io_surface_layer) {
if (!io_surface_layer)
return;
[io_surface_layer resetClient];
@@ -329,7 +293,7 @@ void BrowserCompositorViewMacInternal::DestroySoftwareLayer() {
software_layer_.reset();
}
-bool BrowserCompositorViewMacInternal::AcceleratedLayerShouldAckImmediately()
+bool BrowserCompositorViewMacInternal::IOSurfaceLayerShouldAckImmediately()
const {
// If there is no client then the accelerated layer is not in the hierarchy
// and will never draw.
@@ -338,7 +302,7 @@ bool BrowserCompositorViewMacInternal::AcceleratedLayerShouldAckImmediately()
return client_->BrowserCompositorViewShouldAckImmediately();
}
-void BrowserCompositorViewMacInternal::AcceleratedLayerDidDrawFrame() {
+void BrowserCompositorViewMacInternal::IOSurfaceLayerDidDrawFrame() {
if (accelerated_output_surface_id_) {
content::ImageTransportFactory::GetInstance()->OnSurfaceDisplayed(
accelerated_output_surface_id_);
@@ -351,14 +315,17 @@ void BrowserCompositorViewMacInternal::AcceleratedLayerDidDrawFrame() {
accelerated_latency_info_.clear();
}
-void BrowserCompositorViewMacInternal::AcceleratedLayerHitError() {
- // Perform all acks that would have been done if the frame had succeeded, to
- // un-block the compositor and renderer.
- AcceleratedLayerDidDrawFrame();
+void BrowserCompositorViewMacInternal::IOSurfaceLayerHitError() {
+ base::MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(&BrowserCompositorViewMacInternal::HandleIOSurfaceLayerError,
+ weak_factory_.GetWeakPtr()));
+}
- // Poison the context being used and request a mulligan.
- if (io_surface_layer_)
- [io_surface_layer_ context]->PoisonContextAndSharegroup();
+void BrowserCompositorViewMacInternal::HandleIOSurfaceLayerError() {
+ // Destroy the layer that caused the error.
+ DestroyIOSurfaceLayer(io_surface_layer_);
+
+ // Request a mulligan.
compositor_->ScheduleFullRedraw();
}

Powered by Google App Engine
This is Rietveld 408576698