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