1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import <OpenGL/OpenGL.h>
7 #include "content/plugin/webplugin_accelerated_surface_proxy_mac.h"
10 #include "base/command_line.h"
11 #include "content/plugin/webplugin_proxy.h"
12 #include "ui/base/ui_base_switches.h"
13 #include "ui/surface/accelerated_surface_mac.h"
14 #include "ui/surface/io_surface_support_mac.h"
15 #include "ui/surface/transport_dib.h"
19 WebPluginAcceleratedSurfaceProxy
* WebPluginAcceleratedSurfaceProxy::Create(
20 WebPluginProxy
* plugin_proxy
,
21 gfx::GpuPreference gpu_preference
) {
22 bool composited
= !CommandLine::ForCurrentProcess()->HasSwitch(
23 switches::kDisableCompositedCoreAnimationPlugins
);
25 // Require IOSurface support for drawing Core Animation plugins.
26 if (composited
&& !IOSurfaceSupport::Initialize())
29 AcceleratedSurface
* surface
= new AcceleratedSurface
;
30 // It's possible for OpenGL to fail to initialize (e.g., if an incompatible
31 // mode is forced via flags), so handle that gracefully.
32 if (!surface
->Initialize(NULL
, true, gpu_preference
)) {
39 if (!composited
&& surface
) {
40 // Only used for 10.5 support, but harmless on 10.6+.
41 surface
->SetTransportDIBAllocAndFree(
42 base::Bind(&WebPluginProxy::AllocSurfaceDIB
,
43 base::Unretained(plugin_proxy
)),
44 base::Bind(&WebPluginProxy::FreeSurfaceDIB
,
45 base::Unretained(plugin_proxy
)));
48 return new WebPluginAcceleratedSurfaceProxy(
49 plugin_proxy
, surface
, composited
);
52 WebPluginAcceleratedSurfaceProxy::WebPluginAcceleratedSurfaceProxy(
53 WebPluginProxy
* plugin_proxy
,
54 AcceleratedSurface
* surface
,
56 : plugin_proxy_(plugin_proxy
),
58 composited_(composited
) {
61 WebPluginAcceleratedSurfaceProxy::~WebPluginAcceleratedSurfaceProxy() {
69 void WebPluginAcceleratedSurfaceProxy::SetWindowHandle(
70 gfx::PluginWindowHandle window
) {
71 window_handle_
= window
;
74 bool WebPluginAcceleratedSurfaceProxy::IsComposited() {
78 void WebPluginAcceleratedSurfaceProxy::SetSize(const gfx::Size
& size
) {
83 uint32 io_surface_id
= surface_
->SetSurfaceSize(size
);
84 // If allocation fails for some reason, still inform the plugin proxy.
85 plugin_proxy_
->AcceleratedPluginAllocatedIOSurface(
86 size
.width(), size
.height(), io_surface_id
);
88 uint32 io_surface_id
= surface_
->SetSurfaceSize(size
);
90 plugin_proxy_
->SetAcceleratedSurface(window_handle_
, size
, io_surface_id
);
92 TransportDIB::Handle transport_dib
= surface_
->SetTransportDIBSize(size
);
93 if (TransportDIB::is_valid_handle(transport_dib
)) {
94 plugin_proxy_
->SetAcceleratedDIB(window_handle_
, size
, transport_dib
);
100 CGLContextObj
WebPluginAcceleratedSurfaceProxy::context() {
101 return surface_
? surface_
->context() : NULL
;
104 void WebPluginAcceleratedSurfaceProxy::StartDrawing() {
108 surface_
->MakeCurrent();
109 surface_
->Clear(gfx::Rect(surface_
->GetSize()));
112 void WebPluginAcceleratedSurfaceProxy::EndDrawing() {
116 surface_
->SwapBuffers();
118 plugin_proxy_
->AcceleratedPluginSwappedIOSurface();
120 plugin_proxy_
->AcceleratedFrameBuffersDidSwap(
121 window_handle_
, surface_
->GetSurfaceId());
125 } // namespace content