Add an UMA stat to be able to see if the User pods are show on start screen,
[chromium-blink-merge.git] / content / plugin / webplugin_accelerated_surface_proxy_mac.cc
blobe5f643ba54a7008e80b91728120519cafeb08d3b
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"
9 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "content/plugin/webplugin_proxy.h"
12 #include "content/public/common/content_switches.h"
13 #include "ui/surface/accelerated_surface_mac.h"
14 #include "ui/surface/transport_dib.h"
16 namespace content {
18 WebPluginAcceleratedSurfaceProxy* WebPluginAcceleratedSurfaceProxy::Create(
19 WebPluginProxy* plugin_proxy,
20 gfx::GpuPreference gpu_preference) {
21 // This code path shouldn't be taken if CA plugins are disabled
22 // because the CA drawing model shouldn't be advertised.
23 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
24 switches::kDisableCoreAnimationPlugins));
26 AcceleratedSurface* surface = new AcceleratedSurface;
27 // It's possible for OpenGL to fail to initialize (e.g., if an incompatible
28 // mode is forced via flags), so handle that gracefully.
29 if (!surface->Initialize(NULL, true, gpu_preference)) {
30 delete surface;
31 return NULL;
34 return new WebPluginAcceleratedSurfaceProxy(plugin_proxy, surface);
37 WebPluginAcceleratedSurfaceProxy::WebPluginAcceleratedSurfaceProxy(
38 WebPluginProxy* plugin_proxy,
39 AcceleratedSurface* surface)
40 : plugin_proxy_(plugin_proxy),
41 surface_(surface) {
44 WebPluginAcceleratedSurfaceProxy::~WebPluginAcceleratedSurfaceProxy() {
45 if (surface_) {
46 surface_->Destroy();
47 delete surface_;
48 surface_ = NULL;
52 void WebPluginAcceleratedSurfaceProxy::SetSize(const gfx::Size& size) {
53 if (!surface_)
54 return;
56 uint32 io_surface_id = surface_->SetSurfaceSize(size);
57 // If allocation fails for some reason, still inform the plugin proxy.
58 plugin_proxy_->AcceleratedPluginAllocatedIOSurface(
59 size.width(), size.height(), io_surface_id);
62 CGLContextObj WebPluginAcceleratedSurfaceProxy::context() {
63 return surface_ ? surface_->context() : NULL;
66 void WebPluginAcceleratedSurfaceProxy::StartDrawing() {
67 if (!surface_)
68 return;
70 surface_->MakeCurrent();
71 surface_->Clear(gfx::Rect(surface_->GetSize()));
74 void WebPluginAcceleratedSurfaceProxy::EndDrawing() {
75 if (!surface_)
76 return;
78 surface_->SwapBuffers();
79 plugin_proxy_->AcceleratedPluginSwappedIOSurface();
82 } // namespace content