| 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/plugins/npapi/webplugin.h" | 9 #include "webkit/plugins/npapi/webplugin.h" |
| 10 | 10 |
| 11 AcceleratedSurfaceContainerManagerMac::AcceleratedSurfaceContainerManagerMac() | 11 AcceleratedSurfaceContainerManagerMac::AcceleratedSurfaceContainerManagerMac() |
| 12 : current_id_(0), | 12 : current_id_(0), |
| 13 root_container_(NULL), | 13 root_container_(NULL), |
| 14 root_container_handle_(gfx::kNullPluginWindow), | 14 root_container_handle_(gfx::kNullPluginWindow), |
| 15 gpu_rendering_active_(false) { | 15 gpu_rendering_active_(false) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 gfx::PluginWindowHandle | 18 gfx::PluginWindowHandle |
| 19 AcceleratedSurfaceContainerManagerMac::AllocateFakePluginWindowHandle( | 19 AcceleratedSurfaceContainerManagerMac::AllocateFakePluginWindowHandle( |
| 20 bool opaque, bool root) { | 20 bool opaque, bool root) { |
| 21 AutoLock lock(lock_); | 21 base::AutoLock lock(lock_); |
| 22 | 22 |
| 23 AcceleratedSurfaceContainerMac* container = | 23 AcceleratedSurfaceContainerMac* container = |
| 24 new AcceleratedSurfaceContainerMac(this, opaque); | 24 new AcceleratedSurfaceContainerMac(this, opaque); |
| 25 gfx::PluginWindowHandle res = | 25 gfx::PluginWindowHandle res = |
| 26 static_cast<gfx::PluginWindowHandle>(++current_id_); | 26 static_cast<gfx::PluginWindowHandle>(++current_id_); |
| 27 plugin_window_to_container_map_.insert(std::make_pair(res, container)); | 27 plugin_window_to_container_map_.insert(std::make_pair(res, container)); |
| 28 if (root) { | 28 if (root) { |
| 29 root_container_ = container; | 29 root_container_ = container; |
| 30 root_container_handle_ = res; | 30 root_container_handle_ = res; |
| 31 } | 31 } |
| 32 return res; | 32 return res; |
| 33 } | 33 } |
| 34 | 34 |
| 35 void AcceleratedSurfaceContainerManagerMac::DestroyFakePluginWindowHandle( | 35 void AcceleratedSurfaceContainerManagerMac::DestroyFakePluginWindowHandle( |
| 36 gfx::PluginWindowHandle id) { | 36 gfx::PluginWindowHandle id) { |
| 37 AutoLock lock(lock_); | 37 base::AutoLock lock(lock_); |
| 38 | 38 |
| 39 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 39 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
| 40 if (container) { | 40 if (container) { |
| 41 if (container == root_container_) { | 41 if (container == root_container_) { |
| 42 root_container_ = NULL; | 42 root_container_ = NULL; |
| 43 root_container_handle_ = gfx::kNullPluginWindow; | 43 root_container_handle_ = gfx::kNullPluginWindow; |
| 44 } | 44 } |
| 45 delete container; | 45 delete container; |
| 46 } | 46 } |
| 47 plugin_window_to_container_map_.erase(id); | 47 plugin_window_to_container_map_.erase(id); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 58 if (gpu_rendering_active_ && !active) | 58 if (gpu_rendering_active_ && !active) |
| 59 SetRootSurfaceInvalid(); | 59 SetRootSurfaceInvalid(); |
| 60 gpu_rendering_active_ = active; | 60 gpu_rendering_active_ = active; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void AcceleratedSurfaceContainerManagerMac::SetSizeAndIOSurface( | 63 void AcceleratedSurfaceContainerManagerMac::SetSizeAndIOSurface( |
| 64 gfx::PluginWindowHandle id, | 64 gfx::PluginWindowHandle id, |
| 65 int32 width, | 65 int32 width, |
| 66 int32 height, | 66 int32 height, |
| 67 uint64 io_surface_identifier) { | 67 uint64 io_surface_identifier) { |
| 68 AutoLock lock(lock_); | 68 base::AutoLock lock(lock_); |
| 69 | 69 |
| 70 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 70 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
| 71 if (container) { | 71 if (container) { |
| 72 container->SetSizeAndIOSurface(width, height, io_surface_identifier); | 72 container->SetSizeAndIOSurface(width, height, io_surface_identifier); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 void AcceleratedSurfaceContainerManagerMac::SetSizeAndTransportDIB( | 76 void AcceleratedSurfaceContainerManagerMac::SetSizeAndTransportDIB( |
| 77 gfx::PluginWindowHandle id, | 77 gfx::PluginWindowHandle id, |
| 78 int32 width, | 78 int32 width, |
| 79 int32 height, | 79 int32 height, |
| 80 TransportDIB::Handle transport_dib) { | 80 TransportDIB::Handle transport_dib) { |
| 81 AutoLock lock(lock_); | 81 base::AutoLock lock(lock_); |
| 82 | 82 |
| 83 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 83 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
| 84 if (container) | 84 if (container) |
| 85 container->SetSizeAndTransportDIB(width, height, transport_dib); | 85 container->SetSizeAndTransportDIB(width, height, transport_dib); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void AcceleratedSurfaceContainerManagerMac::SetPluginContainerGeometry( | 88 void AcceleratedSurfaceContainerManagerMac::SetPluginContainerGeometry( |
| 89 const webkit::npapi::WebPluginGeometry& move) { | 89 const webkit::npapi::WebPluginGeometry& move) { |
| 90 AutoLock lock(lock_); | 90 base::AutoLock lock(lock_); |
| 91 | 91 |
| 92 AcceleratedSurfaceContainerMac* container = MapIDToContainer(move.window); | 92 AcceleratedSurfaceContainerMac* container = MapIDToContainer(move.window); |
| 93 if (container) | 93 if (container) |
| 94 container->SetGeometry(move); | 94 container->SetGeometry(move); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void AcceleratedSurfaceContainerManagerMac::Draw(CGLContextObj context, | 97 void AcceleratedSurfaceContainerManagerMac::Draw(CGLContextObj context, |
| 98 gfx::PluginWindowHandle id) { | 98 gfx::PluginWindowHandle id) { |
| 99 AutoLock lock(lock_); | 99 base::AutoLock lock(lock_); |
| 100 | 100 |
| 101 glColorMask(true, true, true, true); | 101 glColorMask(true, true, true, true); |
| 102 // Should match the clear color of RenderWidgetHostViewMac. | 102 // Should match the clear color of RenderWidgetHostViewMac. |
| 103 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); | 103 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
| 104 // TODO(thakis): Clearing the whole color buffer is wasteful, since most of | 104 // TODO(thakis): Clearing the whole color buffer is wasteful, since most of |
| 105 // it is overwritten by the surface. | 105 // it is overwritten by the surface. |
| 106 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 106 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 107 glDisable(GL_DEPTH_TEST); | 107 glDisable(GL_DEPTH_TEST); |
| 108 glDisable(GL_BLEND); | 108 glDisable(GL_BLEND); |
| 109 | 109 |
| 110 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 110 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 111 | 111 |
| 112 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 112 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
| 113 CHECK(container); | 113 CHECK(container); |
| 114 container->Draw(context); | 114 container->Draw(context); |
| 115 | 115 |
| 116 // Unbind any texture from the texture target to ensure that the | 116 // Unbind any texture from the texture target to ensure that the |
| 117 // next time through we will have to re-bind the texture and thereby | 117 // next time through we will have to re-bind the texture and thereby |
| 118 // pick up modifications from the other process. | 118 // pick up modifications from the other process. |
| 119 GLenum target = GL_TEXTURE_RECTANGLE_ARB; | 119 GLenum target = GL_TEXTURE_RECTANGLE_ARB; |
| 120 glBindTexture(target, 0); | 120 glBindTexture(target, 0); |
| 121 | 121 |
| 122 glFlush(); | 122 glFlush(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void AcceleratedSurfaceContainerManagerMac::ForceTextureReload() { | 125 void AcceleratedSurfaceContainerManagerMac::ForceTextureReload() { |
| 126 AutoLock lock(lock_); | 126 base::AutoLock lock(lock_); |
| 127 | 127 |
| 128 for (PluginWindowToContainerMap::const_iterator i = | 128 for (PluginWindowToContainerMap::const_iterator i = |
| 129 plugin_window_to_container_map_.begin(); | 129 plugin_window_to_container_map_.begin(); |
| 130 i != plugin_window_to_container_map_.end(); ++i) { | 130 i != plugin_window_to_container_map_.end(); ++i) { |
| 131 AcceleratedSurfaceContainerMac* container = i->second; | 131 AcceleratedSurfaceContainerMac* container = i->second; |
| 132 container->ForceTextureReload(); | 132 container->ForceTextureReload(); |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 void AcceleratedSurfaceContainerManagerMac::SetSurfaceWasPaintedTo( | 136 void AcceleratedSurfaceContainerManagerMac::SetSurfaceWasPaintedTo( |
| 137 gfx::PluginWindowHandle id, uint64 surface_id) { | 137 gfx::PluginWindowHandle id, uint64 surface_id) { |
| 138 AutoLock lock(lock_); | 138 base::AutoLock lock(lock_); |
| 139 | 139 |
| 140 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 140 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
| 141 if (container) | 141 if (container) |
| 142 container->set_was_painted_to(surface_id); | 142 container->set_was_painted_to(surface_id); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void AcceleratedSurfaceContainerManagerMac::SetRootSurfaceInvalid() { | 145 void AcceleratedSurfaceContainerManagerMac::SetRootSurfaceInvalid() { |
| 146 AutoLock lock(lock_); | 146 base::AutoLock lock(lock_); |
| 147 if (root_container_) | 147 if (root_container_) |
| 148 root_container_->set_surface_invalid(); | 148 root_container_->set_surface_invalid(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool AcceleratedSurfaceContainerManagerMac::SurfaceShouldBeVisible( | 151 bool AcceleratedSurfaceContainerManagerMac::SurfaceShouldBeVisible( |
| 152 gfx::PluginWindowHandle id) const { | 152 gfx::PluginWindowHandle id) const { |
| 153 AutoLock lock(lock_); | 153 base::AutoLock lock(lock_); |
| 154 | 154 |
| 155 if (IsRootContainer(id) && !gpu_rendering_active_) | 155 if (IsRootContainer(id) && !gpu_rendering_active_) |
| 156 return false; | 156 return false; |
| 157 | 157 |
| 158 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 158 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
| 159 return container && container->ShouldBeVisible(); | 159 return container && container->ShouldBeVisible(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 AcceleratedSurfaceContainerMac* | 162 AcceleratedSurfaceContainerMac* |
| 163 AcceleratedSurfaceContainerManagerMac::MapIDToContainer( | 163 AcceleratedSurfaceContainerManagerMac::MapIDToContainer( |
| 164 gfx::PluginWindowHandle id) const { | 164 gfx::PluginWindowHandle id) const { |
| 165 PluginWindowToContainerMap::const_iterator i = | 165 PluginWindowToContainerMap::const_iterator i = |
| 166 plugin_window_to_container_map_.find(id); | 166 plugin_window_to_container_map_.find(id); |
| 167 if (i != plugin_window_to_container_map_.end()) | 167 if (i != plugin_window_to_container_map_.end()) |
| 168 return i->second; | 168 return i->second; |
| 169 | 169 |
| 170 LOG(ERROR) << "Request for plugin container for unknown window id " << id; | 170 LOG(ERROR) << "Request for plugin container for unknown window id " << id; |
| 171 | 171 |
| 172 return NULL; | 172 return NULL; |
| 173 } | 173 } |
| OLD | NEW |