Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/compositor/browser_compositor_ca_layer_tree_mac.h" | 5 #include "ui/compositor/mac/accelerated_widget_mac.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "cc/output/software_frame_data.h" | |
| 10 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 11 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 12 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 13 #include "content/browser/compositor/io_surface_layer_mac.h" | 12 #include "cc/output/software_frame_data.h" |
| 14 #include "content/browser/renderer_host/dip_util.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "content/common/gpu/surface_handle_types_mac.h" | |
| 16 #include "content/public/browser/context_factory.h" | |
| 17 #include "ui/base/cocoa/animation_utils.h" | 14 #include "ui/base/cocoa/animation_utils.h" |
| 15 #include "ui/compositor/mac/io_surface_layer_mac.h" | |
| 16 #include "ui/compositor/mac/surface_handle_types_mac.h" | |
| 17 #include "ui/gfx/size_conversions.h" | |
| 18 #include "ui/gl/scoped_cgl.h" | 18 #include "ui/gl/scoped_cgl.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 typedef std::map<gfx::AcceleratedWidget,AcceleratedWidgetMac*> | 23 typedef std::map<gfx::AcceleratedWidget,AcceleratedWidgetMac*> |
| 24 WidgetToHelperMap; | 24 WidgetToHelperMap; |
| 25 base::LazyInstance<WidgetToHelperMap> g_widget_to_helper_map; | 25 base::LazyInstance<WidgetToHelperMap> g_widget_to_helper_map; |
| 26 | 26 |
| 27 AcceleratedWidgetMac* GetHelperFromAcceleratedWidget( | 27 AcceleratedWidgetMac* GetHelperFromAcceleratedWidget( |
| 28 gfx::AcceleratedWidget widget) { | 28 gfx::AcceleratedWidget widget) { |
| 29 WidgetToHelperMap::const_iterator found = | 29 WidgetToHelperMap::const_iterator found = |
| 30 g_widget_to_helper_map.Pointer()->find(widget); | 30 g_widget_to_helper_map.Pointer()->find(widget); |
| 31 // This can end up being accessed after the underlying widget has been | 31 // This can end up being accessed after the underlying widget has been |
| 32 // destroyed, but while the ui::Compositor is still being destroyed. | 32 // destroyed, but while the ui::Compositor is still being destroyed. |
| 33 // Return NULL in these cases. | 33 // Return NULL in these cases. |
| 34 if (found == g_widget_to_helper_map.Pointer()->end()) | 34 if (found == g_widget_to_helper_map.Pointer()->end()) |
| 35 return NULL; | 35 return NULL; |
| 36 return found->second; | 36 return found->second; |
| 37 } | 37 } |
| 38 | 38 |
| 39 gfx::Size ConvertSizeToDIP(float scale_factor, const gfx::Size& size_in_pixel) { | |
|
ccameron
2014/11/25 17:54:25
(re-resolve against https://codereview.chromium.or
tapted
2014/11/25 23:53:55
Done.
| |
| 40 return gfx::ToFlooredSize(gfx::ScaleSize(size_in_pixel, 1.0f / scale_factor)); | |
| 41 } | |
| 42 | |
| 39 } | 43 } |
| 40 | 44 |
| 41 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
| 42 // AcceleratedWidgetMac | 46 // AcceleratedWidgetMac |
| 43 | 47 |
| 44 AcceleratedWidgetMac::AcceleratedWidgetMac() | 48 AcceleratedWidgetMac::AcceleratedWidgetMac() |
| 45 : view_(NULL) { | 49 : view_(NULL) { |
| 46 // Disable the fade-in animation as the layers are added. | 50 // Disable the fade-in animation as the layers are added. |
| 47 ScopedCAActionDisabler disabler; | 51 ScopedCAActionDisabler disabler; |
| 48 | 52 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 } | 328 } |
| 325 | 329 |
| 326 bool AcceleratedWidgetMac::IOSurfaceLayerShouldAckImmediately() const { | 330 bool AcceleratedWidgetMac::IOSurfaceLayerShouldAckImmediately() const { |
| 327 // If there is no view then the accelerated layer is not in the view | 331 // If there is no view then the accelerated layer is not in the view |
| 328 // hierarchy and will never draw. | 332 // hierarchy and will never draw. |
| 329 if (!view_) | 333 if (!view_) |
| 330 return true; | 334 return true; |
| 331 return view_->AcceleratedWidgetShouldIgnoreBackpressure(); | 335 return view_->AcceleratedWidgetShouldIgnoreBackpressure(); |
| 332 } | 336 } |
| 333 | 337 |
| 338 bool AcceleratedWidgetMac::IOSurfaceNeedsGLFinishWorkaround() const { | |
| 339 return view_ && view_->AcceleratedWidgetNeedsGLFinishWorkaround(); | |
| 340 } | |
| 341 | |
| 334 void AcceleratedWidgetMac::IOSurfaceLayerDidDrawFrame() { | 342 void AcceleratedWidgetMac::IOSurfaceLayerDidDrawFrame() { |
| 335 AcknowledgeAcceleratedFrame(); | 343 AcknowledgeAcceleratedFrame(); |
| 336 } | 344 } |
| 337 | 345 |
| 338 void AcceleratedWidgetMac::AcknowledgeAcceleratedFrame() { | 346 void AcceleratedWidgetMac::AcknowledgeAcceleratedFrame() { |
| 339 if (accelerated_frame_drawn_callback_.is_null()) | 347 if (accelerated_frame_drawn_callback_.is_null()) |
| 340 return; | 348 return; |
| 341 accelerated_frame_drawn_callback_.Run(); | 349 accelerated_frame_drawn_callback_.Run(); |
| 342 accelerated_frame_drawn_callback_.Reset(); | 350 accelerated_frame_drawn_callback_.Reset(); |
| 343 if (view_) | 351 if (view_) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 void AcceleratedWidgetMacGotSoftwareFrame( | 388 void AcceleratedWidgetMacGotSoftwareFrame( |
| 381 gfx::AcceleratedWidget widget, | 389 gfx::AcceleratedWidget widget, |
| 382 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas) { | 390 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas) { |
| 383 AcceleratedWidgetMac* accelerated_widget_mac = | 391 AcceleratedWidgetMac* accelerated_widget_mac = |
| 384 GetHelperFromAcceleratedWidget(widget); | 392 GetHelperFromAcceleratedWidget(widget); |
| 385 if (accelerated_widget_mac) | 393 if (accelerated_widget_mac) |
| 386 accelerated_widget_mac->GotSoftwareFrame(frame_data, scale_factor, canvas); | 394 accelerated_widget_mac->GotSoftwareFrame(frame_data, scale_factor, canvas); |
| 387 } | 395 } |
| 388 | 396 |
| 389 } // namespace content | 397 } // namespace content |
| OLD | NEW |