blob: e5f643ba54a7008e80b91728120519cafeb08d3b (
plain)
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
|
// 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 "content/public/common/content_switches.h"
#include "ui/surface/accelerated_surface_mac.h"
#include "ui/surface/transport_dib.h"
namespace content {
WebPluginAcceleratedSurfaceProxy* WebPluginAcceleratedSurfaceProxy::Create(
WebPluginProxy* plugin_proxy,
gfx::GpuPreference gpu_preference) {
// This code path shouldn't be taken if CA plugins are disabled
// because the CA drawing model shouldn't be advertised.
DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableCoreAnimationPlugins));
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;
return NULL;
}
return new WebPluginAcceleratedSurfaceProxy(plugin_proxy, surface);
}
WebPluginAcceleratedSurfaceProxy::WebPluginAcceleratedSurfaceProxy(
WebPluginProxy* plugin_proxy,
AcceleratedSurface* surface)
: plugin_proxy_(plugin_proxy),
surface_(surface) {
}
WebPluginAcceleratedSurfaceProxy::~WebPluginAcceleratedSurfaceProxy() {
if (surface_) {
surface_->Destroy();
delete surface_;
surface_ = NULL;
}
}
void WebPluginAcceleratedSurfaceProxy::SetSize(const gfx::Size& size) {
if (!surface_)
return;
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);
}
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();
plugin_proxy_->AcceleratedPluginSwappedIOSurface();
}
} // namespace content
|