| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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. | |
| 4 | |
| 5 #import <OpenGL/OpenGL.h> | |
| 6 | |
| 7 #include "chrome/plugin/webplugin_accelerated_surface_proxy_mac.h" | |
| 8 | |
| 9 #include "app/surface/accelerated_surface_mac.h" | |
| 10 #include "app/surface/transport_dib.h" | |
| 11 #include "chrome/plugin/webplugin_proxy.h" | |
| 12 | |
| 13 WebPluginAcceleratedSurfaceProxy::WebPluginAcceleratedSurfaceProxy( | |
| 14 WebPluginProxy* plugin_proxy) | |
| 15 : plugin_proxy_(plugin_proxy), | |
| 16 window_handle_(NULL) { | |
| 17 surface_ = new AcceleratedSurface; | |
| 18 // It's possible for OpenGL to fail to initialze (e.g., if an incompatible | |
| 19 // mode is forced via flags), so handle that gracefully. | |
| 20 if (!surface_->Initialize(NULL, true)) { | |
| 21 delete surface_; | |
| 22 surface_ = NULL; | |
| 23 return; | |
| 24 } | |
| 25 | |
| 26 // Only used for 10.5 support, but harmless on 10.6+. | |
| 27 surface_->SetTransportDIBAllocAndFree( | |
| 28 NewCallback(plugin_proxy_, &WebPluginProxy::AllocSurfaceDIB), | |
| 29 NewCallback(plugin_proxy_, &WebPluginProxy::FreeSurfaceDIB)); | |
| 30 } | |
| 31 | |
| 32 WebPluginAcceleratedSurfaceProxy::~WebPluginAcceleratedSurfaceProxy() { | |
| 33 if (surface_) { | |
| 34 surface_->Destroy(); | |
| 35 delete surface_; | |
| 36 surface_ = NULL; | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 void WebPluginAcceleratedSurfaceProxy::SetWindowHandle( | |
| 41 gfx::PluginWindowHandle window) { | |
| 42 window_handle_ = window; | |
| 43 } | |
| 44 | |
| 45 void WebPluginAcceleratedSurfaceProxy::SetSize(const gfx::Size& size) { | |
| 46 if (!surface_) | |
| 47 return; | |
| 48 | |
| 49 uint64 io_surface_id = surface_->SetSurfaceSize(size); | |
| 50 if (io_surface_id) { | |
| 51 plugin_proxy_->SetAcceleratedSurface(window_handle_, size, io_surface_id); | |
| 52 } else { | |
| 53 TransportDIB::Handle transport_dib = surface_->SetTransportDIBSize(size); | |
| 54 if (TransportDIB::is_valid(transport_dib)) { | |
| 55 plugin_proxy_->SetAcceleratedDIB(window_handle_, size, transport_dib); | |
| 56 } | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 CGLContextObj WebPluginAcceleratedSurfaceProxy::context() { | |
| 61 return surface_ ? surface_->context() : NULL; | |
| 62 } | |
| 63 | |
| 64 void WebPluginAcceleratedSurfaceProxy::StartDrawing() { | |
| 65 if (!surface_) | |
| 66 return; | |
| 67 | |
| 68 surface_->MakeCurrent(); | |
| 69 surface_->Clear(gfx::Rect(surface_->GetSize())); | |
| 70 } | |
| 71 | |
| 72 void WebPluginAcceleratedSurfaceProxy::EndDrawing() { | |
| 73 if (!surface_) | |
| 74 return; | |
| 75 | |
| 76 surface_->SwapBuffers(); | |
| 77 plugin_proxy_->AcceleratedFrameBuffersDidSwap( | |
| 78 window_handle_, surface_->GetSurfaceId()); | |
| 79 } | |
| OLD | NEW |