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

Side by Side Diff: content/plugin/webplugin_accelerated_surface_proxy_mac.cc

Issue 8678037: Render Core Animation plugins through WebKit's compositor rather than (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #import <OpenGL/OpenGL.h> 5 #import <OpenGL/OpenGL.h>
6 6
7 #include "content/plugin/webplugin_accelerated_surface_proxy_mac.h" 7 #include "content/plugin/webplugin_accelerated_surface_proxy_mac.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h"
10 #include "content/plugin/webplugin_proxy.h" 11 #include "content/plugin/webplugin_proxy.h"
12 #include "content/public/common/content_switches.h"
11 #include "ui/gfx/surface/accelerated_surface_mac.h" 13 #include "ui/gfx/surface/accelerated_surface_mac.h"
14 #include "ui/gfx/surface/io_surface_support_mac.h"
12 #include "ui/gfx/surface/transport_dib.h" 15 #include "ui/gfx/surface/transport_dib.h"
13 16
17 WebPluginAcceleratedSurfaceProxy* WebPluginAcceleratedSurfaceProxy::Create(
18 WebPluginProxy* plugin_proxy,
19 gfx::GpuPreference gpu_preference) {
20 bool composited = !CommandLine::ForCurrentProcess()->HasSwitch(
21 switches::kDisableCompositedCoreAnimationPlugins);
22
23 // Require IOSurface support for drawing Core Animation plugins.
24 if (composited && !IOSurfaceSupport::Initialize())
25 return NULL;
26
27 AcceleratedSurface* surface = new AcceleratedSurface;
28 // It's possible for OpenGL to fail to initialize (e.g., if an incompatible
29 // mode is forced via flags), so handle that gracefully.
30 if (!surface->Initialize(NULL, true, gpu_preference)) {
31 delete surface;
32 surface = NULL;
33 if (composited)
34 return NULL;
35 }
36
37 if (!composited && surface) {
38 // Only used for 10.5 support, but harmless on 10.6+.
39 surface->SetTransportDIBAllocAndFree(
40 base::Bind(&WebPluginProxy::AllocSurfaceDIB,
41 base::Unretained(plugin_proxy)),
42 base::Bind(&WebPluginProxy::FreeSurfaceDIB,
43 base::Unretained(plugin_proxy)));
44 }
45
46 return new WebPluginAcceleratedSurfaceProxy(
47 plugin_proxy, surface, composited);
48 }
49
14 WebPluginAcceleratedSurfaceProxy::WebPluginAcceleratedSurfaceProxy( 50 WebPluginAcceleratedSurfaceProxy::WebPluginAcceleratedSurfaceProxy(
15 WebPluginProxy* plugin_proxy, 51 WebPluginProxy* plugin_proxy,
16 gfx::GpuPreference gpu_preference) 52 AcceleratedSurface* surface,
53 bool composited)
17 : plugin_proxy_(plugin_proxy), 54 : plugin_proxy_(plugin_proxy),
18 window_handle_(NULL) { 55 surface_(surface),
19 surface_ = new AcceleratedSurface; 56 composited_(composited) {
20 // It's possible for OpenGL to fail to initialze (e.g., if an incompatible
21 // mode is forced via flags), so handle that gracefully.
22 if (!surface_->Initialize(NULL, true, gpu_preference)) {
23 delete surface_;
24 surface_ = NULL;
25 return;
26 }
27
28 // Only used for 10.5 support, but harmless on 10.6+.
29 surface_->SetTransportDIBAllocAndFree(
30 base::Bind(&WebPluginProxy::AllocSurfaceDIB,
31 base::Unretained(plugin_proxy)),
32 base::Bind(&WebPluginProxy::FreeSurfaceDIB,
33 base::Unretained(plugin_proxy)));
34 } 57 }
35 58
36 WebPluginAcceleratedSurfaceProxy::~WebPluginAcceleratedSurfaceProxy() { 59 WebPluginAcceleratedSurfaceProxy::~WebPluginAcceleratedSurfaceProxy() {
37 if (surface_) { 60 if (surface_) {
38 surface_->Destroy(); 61 surface_->Destroy();
39 delete surface_; 62 delete surface_;
40 surface_ = NULL; 63 surface_ = NULL;
41 } 64 }
42 } 65 }
43 66
44 void WebPluginAcceleratedSurfaceProxy::SetWindowHandle( 67 void WebPluginAcceleratedSurfaceProxy::SetWindowHandle(
45 gfx::PluginWindowHandle window) { 68 gfx::PluginWindowHandle window) {
46 window_handle_ = window; 69 window_handle_ = window;
47 } 70 }
48 71
72 bool WebPluginAcceleratedSurfaceProxy::IsComposited() {
73 return composited_;
74 }
75
49 void WebPluginAcceleratedSurfaceProxy::SetSize(const gfx::Size& size) { 76 void WebPluginAcceleratedSurfaceProxy::SetSize(const gfx::Size& size) {
50 if (!surface_) 77 if (!surface_)
51 return; 78 return;
52 79
53 uint64 io_surface_id = surface_->SetSurfaceSize(size); 80 if (composited_) {
54 if (io_surface_id) { 81 uint32 io_surface_id = surface_->SetSurfaceSize(size);
55 plugin_proxy_->SetAcceleratedSurface(window_handle_, size, io_surface_id); 82 // If allocation fails for some reason, still inform the plugin proxy.
83 plugin_proxy_->AcceleratedPluginAllocatedIOSurface(
84 size.width(), size.height(), io_surface_id);
56 } else { 85 } else {
57 TransportDIB::Handle transport_dib = surface_->SetTransportDIBSize(size); 86 uint32 io_surface_id = surface_->SetSurfaceSize(size);
58 if (TransportDIB::is_valid_handle(transport_dib)) { 87 if (io_surface_id) {
59 plugin_proxy_->SetAcceleratedDIB(window_handle_, size, transport_dib); 88 plugin_proxy_->SetAcceleratedSurface(window_handle_, size, io_surface_id);
89 } else {
90 TransportDIB::Handle transport_dib = surface_->SetTransportDIBSize(size);
91 if (TransportDIB::is_valid_handle(transport_dib)) {
92 plugin_proxy_->SetAcceleratedDIB(window_handle_, size, transport_dib);
93 }
60 } 94 }
61 } 95 }
62 } 96 }
63 97
64 CGLContextObj WebPluginAcceleratedSurfaceProxy::context() { 98 CGLContextObj WebPluginAcceleratedSurfaceProxy::context() {
65 return surface_ ? surface_->context() : NULL; 99 return surface_ ? surface_->context() : NULL;
66 } 100 }
67 101
68 void WebPluginAcceleratedSurfaceProxy::StartDrawing() { 102 void WebPluginAcceleratedSurfaceProxy::StartDrawing() {
69 if (!surface_) 103 if (!surface_)
70 return; 104 return;
71 105
72 surface_->MakeCurrent(); 106 surface_->MakeCurrent();
73 surface_->Clear(gfx::Rect(surface_->GetSize())); 107 surface_->Clear(gfx::Rect(surface_->GetSize()));
74 } 108 }
75 109
76 void WebPluginAcceleratedSurfaceProxy::EndDrawing() { 110 void WebPluginAcceleratedSurfaceProxy::EndDrawing() {
77 if (!surface_) 111 if (!surface_)
78 return; 112 return;
79 113
80 surface_->SwapBuffers(); 114 surface_->SwapBuffers();
81 plugin_proxy_->AcceleratedFrameBuffersDidSwap( 115 if (composited_) {
82 window_handle_, surface_->GetSurfaceId()); 116 plugin_proxy_->AcceleratedPluginSwappedIOSurface();
117 } else {
118 plugin_proxy_->AcceleratedFrameBuffersDidSwap(
119 window_handle_, surface_->GetSurfaceId());
120 }
83 } 121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698