| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/renderer_host/accelerated_surface_container_manager_mac
.h" | 5 #include "chrome/browser/renderer_host/accelerated_surface_container_manager_mac
.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/renderer_host/accelerated_surface_container_mac.h" | 8 #include "chrome/browser/renderer_host/accelerated_surface_container_mac.h" |
| 9 #include "webkit/glue/webplugin.h" | 9 #include "webkit/glue/webplugin.h" |
| 10 | 10 |
| 11 AcceleratedSurfaceContainerManagerMac::AcceleratedSurfaceContainerManagerMac() | 11 AcceleratedSurfaceContainerManagerMac::AcceleratedSurfaceContainerManagerMac() |
| 12 : current_id_(0) { | 12 : current_id_(0) { |
| 13 } | 13 } |
| 14 | 14 |
| 15 gfx::PluginWindowHandle | 15 gfx::PluginWindowHandle |
| 16 AcceleratedSurfaceContainerManagerMac::AllocateFakePluginWindowHandle() { | 16 AcceleratedSurfaceContainerManagerMac::AllocateFakePluginWindowHandle() { |
| 17 AcceleratedSurfaceContainerMac* container = | 17 AcceleratedSurfaceContainerMac* container = |
| 18 new AcceleratedSurfaceContainerMac(); | 18 new AcceleratedSurfaceContainerMac(this); |
| 19 gfx::PluginWindowHandle res = | 19 gfx::PluginWindowHandle res = |
| 20 static_cast<gfx::PluginWindowHandle>(++current_id_); | 20 static_cast<gfx::PluginWindowHandle>(++current_id_); |
| 21 plugin_window_to_container_map_.insert(std::make_pair(res, container)); | 21 plugin_window_to_container_map_.insert(std::make_pair(res, container)); |
| 22 return res; | 22 return res; |
| 23 } | 23 } |
| 24 | 24 |
| 25 void AcceleratedSurfaceContainerManagerMac::DestroyFakePluginWindowHandle( | 25 void AcceleratedSurfaceContainerManagerMac::DestroyFakePluginWindowHandle( |
| 26 gfx::PluginWindowHandle id) { | 26 gfx::PluginWindowHandle id) { |
| 27 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 27 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
| 28 if (container) | 28 if (container) |
| 29 delete container; | 29 delete container; |
| 30 plugin_window_to_container_map_.erase(id); | 30 plugin_window_to_container_map_.erase(id); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void AcceleratedSurfaceContainerManagerMac::SetSizeAndIOSurface( | 33 void AcceleratedSurfaceContainerManagerMac::SetSizeAndIOSurface( |
| 34 gfx::PluginWindowHandle id, | 34 gfx::PluginWindowHandle id, |
| 35 int32 width, | 35 int32 width, |
| 36 int32 height, | 36 int32 height, |
| 37 uint64 io_surface_identifier) { | 37 uint64 io_surface_identifier) { |
| 38 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 38 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
| 39 if (container) | 39 if (container) |
| 40 container->SetSizeAndIOSurface(width, height, | 40 container->SetSizeAndIOSurface(width, height, io_surface_identifier); |
| 41 io_surface_identifier, this); | |
| 42 } | 41 } |
| 43 | 42 |
| 44 void AcceleratedSurfaceContainerManagerMac::SetSizeAndTransportDIB( | 43 void AcceleratedSurfaceContainerManagerMac::SetSizeAndTransportDIB( |
| 45 gfx::PluginWindowHandle id, | 44 gfx::PluginWindowHandle id, |
| 46 int32 width, | 45 int32 width, |
| 47 int32 height, | 46 int32 height, |
| 48 TransportDIB::Handle transport_dib) { | 47 TransportDIB::Handle transport_dib) { |
| 49 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 48 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
| 50 if (container) | 49 if (container) |
| 51 container->SetSizeAndTransportDIB(width, height, | 50 container->SetSizeAndTransportDIB(width, height, transport_dib); |
| 52 transport_dib, this); | |
| 53 } | 51 } |
| 54 | 52 |
| 55 void AcceleratedSurfaceContainerManagerMac::MovePluginContainer( | 53 void AcceleratedSurfaceContainerManagerMac::MovePluginContainer( |
| 56 const webkit_glue::WebPluginGeometry& move) { | 54 const webkit_glue::WebPluginGeometry& move) { |
| 57 AcceleratedSurfaceContainerMac* container = MapIDToContainer(move.window); | 55 AcceleratedSurfaceContainerMac* container = MapIDToContainer(move.window); |
| 58 if (container) | 56 if (container) |
| 59 container->MoveTo(move); | 57 container->MoveTo(move); |
| 60 } | 58 } |
| 61 | 59 |
| 62 void AcceleratedSurfaceContainerManagerMac::Draw(CGLContextObj context) { | 60 void AcceleratedSurfaceContainerManagerMac::Draw(CGLContextObj context) { |
| 61 // Clean up old texture objects. This is essentially a pre-emptive |
| 62 // cleanup, as the resources will be released when the OpenGL |
| 63 // context associated with the CAOpenGLLayer is destroyed. However, |
| 64 // if we render many plugins in the same layer, we should try to |
| 65 // eagerly reclaim their resources. Note also that the OpenGL |
| 66 // context must be current when performing the deletion, and it |
| 67 // seems risky to make the OpenGL context current at an arbitrary |
| 68 // point in time, which is why the deletion does not occur in the |
| 69 // container's destructor. |
| 70 for (std::vector<GLuint>::iterator iter = |
| 71 textures_pending_deletion_.begin(); |
| 72 iter != textures_pending_deletion_.end(); |
| 73 ++iter) { |
| 74 GLuint texture = *iter; |
| 75 glDeleteTextures(1, &texture); |
| 76 } |
| 77 textures_pending_deletion_.clear(); |
| 78 |
| 63 glClearColor(0, 0, 0, 0); | 79 glClearColor(0, 0, 0, 0); |
| 64 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 80 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 65 | 81 |
| 66 GLenum target = GL_TEXTURE_RECTANGLE_ARB; | 82 GLenum target = GL_TEXTURE_RECTANGLE_ARB; |
| 67 glTexEnvi(target, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 83 glTexEnvi(target, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 68 | 84 |
| 69 for (PluginWindowToContainerMap::const_iterator i = | 85 for (PluginWindowToContainerMap::const_iterator i = |
| 70 plugin_window_to_container_map_.begin(); | 86 plugin_window_to_container_map_.begin(); |
| 71 i != plugin_window_to_container_map_.end(); ++i) { | 87 i != plugin_window_to_container_map_.end(); ++i) { |
| 72 AcceleratedSurfaceContainerMac* container = i->second; | 88 AcceleratedSurfaceContainerMac* container = i->second; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 102 gfx::PluginWindowHandle id) { | 118 gfx::PluginWindowHandle id) { |
| 103 PluginWindowToContainerMap::const_iterator i = | 119 PluginWindowToContainerMap::const_iterator i = |
| 104 plugin_window_to_container_map_.find(id); | 120 plugin_window_to_container_map_.find(id); |
| 105 if (i != plugin_window_to_container_map_.end()) | 121 if (i != plugin_window_to_container_map_.end()) |
| 106 return i->second; | 122 return i->second; |
| 107 | 123 |
| 108 LOG(ERROR) << "Request for plugin container for unknown window id " << id; | 124 LOG(ERROR) << "Request for plugin container for unknown window id " << id; |
| 109 | 125 |
| 110 return NULL; | 126 return NULL; |
| 111 } | 127 } |
| OLD | NEW |