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/plugins/webplugin.h" | 9 #include "webkit/glue/plugins/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_); |
| 22 |
21 AcceleratedSurfaceContainerMac* container = | 23 AcceleratedSurfaceContainerMac* container = |
22 new AcceleratedSurfaceContainerMac(this, opaque); | 24 new AcceleratedSurfaceContainerMac(this, opaque); |
23 gfx::PluginWindowHandle res = | 25 gfx::PluginWindowHandle res = |
24 static_cast<gfx::PluginWindowHandle>(++current_id_); | 26 static_cast<gfx::PluginWindowHandle>(++current_id_); |
25 plugin_window_to_container_map_.insert(std::make_pair(res, container)); | 27 plugin_window_to_container_map_.insert(std::make_pair(res, container)); |
26 if (root) { | 28 if (root) { |
27 root_container_ = container; | 29 root_container_ = container; |
28 root_container_handle_ = res; | 30 root_container_handle_ = res; |
29 } | 31 } |
30 return res; | 32 return res; |
31 } | 33 } |
32 | 34 |
33 void AcceleratedSurfaceContainerManagerMac::DestroyFakePluginWindowHandle( | 35 void AcceleratedSurfaceContainerManagerMac::DestroyFakePluginWindowHandle( |
34 gfx::PluginWindowHandle id) { | 36 gfx::PluginWindowHandle id) { |
| 37 AutoLock lock(lock_); |
| 38 |
35 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 39 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
36 if (container) { | 40 if (container) { |
37 if (container == root_container_) { | 41 if (container == root_container_) { |
38 root_container_ = NULL; | 42 root_container_ = NULL; |
39 root_container_handle_ = gfx::kNullPluginWindow; | 43 root_container_handle_ = gfx::kNullPluginWindow; |
40 } | 44 } |
41 delete container; | 45 delete container; |
42 } | 46 } |
43 plugin_window_to_container_map_.erase(id); | 47 plugin_window_to_container_map_.erase(id); |
44 } | 48 } |
45 | 49 |
46 bool AcceleratedSurfaceContainerManagerMac::IsRootContainer( | 50 bool AcceleratedSurfaceContainerManagerMac::IsRootContainer( |
47 gfx::PluginWindowHandle id) const { | 51 gfx::PluginWindowHandle id) const { |
48 return root_container_handle_ != gfx::kNullPluginWindow && | 52 return root_container_handle_ != gfx::kNullPluginWindow && |
49 root_container_handle_ == id; | 53 root_container_handle_ == id; |
50 } | 54 } |
51 | 55 |
52 void AcceleratedSurfaceContainerManagerMac::SetSizeAndIOSurface( | 56 void AcceleratedSurfaceContainerManagerMac::SetSizeAndIOSurface( |
53 gfx::PluginWindowHandle id, | 57 gfx::PluginWindowHandle id, |
54 int32 width, | 58 int32 width, |
55 int32 height, | 59 int32 height, |
56 uint64 io_surface_identifier) { | 60 uint64 io_surface_identifier) { |
| 61 AutoLock lock(lock_); |
| 62 |
57 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 63 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
58 if (container) { | 64 if (container) { |
59 container->SetSizeAndIOSurface(width, height, io_surface_identifier); | 65 container->SetSizeAndIOSurface(width, height, io_surface_identifier); |
60 } | 66 } |
61 } | 67 } |
62 | 68 |
63 void AcceleratedSurfaceContainerManagerMac::SetSizeAndTransportDIB( | 69 void AcceleratedSurfaceContainerManagerMac::SetSizeAndTransportDIB( |
64 gfx::PluginWindowHandle id, | 70 gfx::PluginWindowHandle id, |
65 int32 width, | 71 int32 width, |
66 int32 height, | 72 int32 height, |
67 TransportDIB::Handle transport_dib) { | 73 TransportDIB::Handle transport_dib) { |
| 74 AutoLock lock(lock_); |
| 75 |
68 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 76 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
69 if (container) | 77 if (container) |
70 container->SetSizeAndTransportDIB(width, height, transport_dib); | 78 container->SetSizeAndTransportDIB(width, height, transport_dib); |
71 } | 79 } |
72 | 80 |
73 void AcceleratedSurfaceContainerManagerMac::SetPluginContainerGeometry( | 81 void AcceleratedSurfaceContainerManagerMac::SetPluginContainerGeometry( |
74 const webkit_glue::WebPluginGeometry& move) { | 82 const webkit_glue::WebPluginGeometry& move) { |
| 83 AutoLock lock(lock_); |
| 84 |
75 AcceleratedSurfaceContainerMac* container = MapIDToContainer(move.window); | 85 AcceleratedSurfaceContainerMac* container = MapIDToContainer(move.window); |
76 if (container) | 86 if (container) |
77 container->SetGeometry(move); | 87 container->SetGeometry(move); |
78 } | 88 } |
79 | 89 |
80 void AcceleratedSurfaceContainerManagerMac::Draw(CGLContextObj context, | 90 void AcceleratedSurfaceContainerManagerMac::Draw(CGLContextObj context, |
81 gfx::PluginWindowHandle id) { | 91 gfx::PluginWindowHandle id) { |
| 92 AutoLock lock(lock_); |
| 93 |
82 glColorMask(true, true, true, true); | 94 glColorMask(true, true, true, true); |
83 glClearColor(0, 0, 0, 0); | 95 glClearColor(0, 0, 0, 0); |
84 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 96 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
85 glDisable(GL_DEPTH_TEST); | 97 glDisable(GL_DEPTH_TEST); |
86 glDisable(GL_BLEND); | 98 glDisable(GL_BLEND); |
87 | 99 |
88 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 100 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
89 | 101 |
90 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 102 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
91 CHECK(container); | 103 CHECK(container); |
92 container->Draw(context); | 104 container->Draw(context); |
93 | 105 |
94 // Unbind any texture from the texture target to ensure that the | 106 // Unbind any texture from the texture target to ensure that the |
95 // next time through we will have to re-bind the texture and thereby | 107 // next time through we will have to re-bind the texture and thereby |
96 // pick up modifications from the other process. | 108 // pick up modifications from the other process. |
97 GLenum target = GL_TEXTURE_RECTANGLE_ARB; | 109 GLenum target = GL_TEXTURE_RECTANGLE_ARB; |
98 glBindTexture(target, 0); | 110 glBindTexture(target, 0); |
99 | 111 |
100 glFlush(); | 112 glFlush(); |
101 } | 113 } |
102 | 114 |
103 void AcceleratedSurfaceContainerManagerMac::ForceTextureReload() { | 115 void AcceleratedSurfaceContainerManagerMac::ForceTextureReload() { |
| 116 AutoLock lock(lock_); |
| 117 |
104 for (PluginWindowToContainerMap::const_iterator i = | 118 for (PluginWindowToContainerMap::const_iterator i = |
105 plugin_window_to_container_map_.begin(); | 119 plugin_window_to_container_map_.begin(); |
106 i != plugin_window_to_container_map_.end(); ++i) { | 120 i != plugin_window_to_container_map_.end(); ++i) { |
107 AcceleratedSurfaceContainerMac* container = i->second; | 121 AcceleratedSurfaceContainerMac* container = i->second; |
108 container->ForceTextureReload(); | 122 container->ForceTextureReload(); |
109 } | 123 } |
110 } | 124 } |
111 | 125 |
112 void AcceleratedSurfaceContainerManagerMac::SetSurfaceWasPaintedTo( | 126 void AcceleratedSurfaceContainerManagerMac::SetSurfaceWasPaintedTo( |
113 gfx::PluginWindowHandle id) { | 127 gfx::PluginWindowHandle id) { |
| 128 AutoLock lock(lock_); |
| 129 |
114 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 130 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
115 if (container) | 131 if (container) |
116 container->set_was_painted_to(); | 132 container->set_was_painted_to(); |
117 } | 133 } |
118 | 134 |
119 bool AcceleratedSurfaceContainerManagerMac::SurfaceShouldBeVisible( | 135 bool AcceleratedSurfaceContainerManagerMac::SurfaceShouldBeVisible( |
120 gfx::PluginWindowHandle id) const { | 136 gfx::PluginWindowHandle id) const { |
| 137 AutoLock lock(lock_); |
| 138 |
121 if (IsRootContainer(id) && !gpu_rendering_active_) | 139 if (IsRootContainer(id) && !gpu_rendering_active_) |
122 return false; | 140 return false; |
123 | 141 |
124 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); | 142 AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); |
125 return container && container->should_be_visible(); | 143 return container && container->should_be_visible(); |
126 } | 144 } |
127 | 145 |
128 AcceleratedSurfaceContainerMac* | 146 AcceleratedSurfaceContainerMac* |
129 AcceleratedSurfaceContainerManagerMac::MapIDToContainer( | 147 AcceleratedSurfaceContainerManagerMac::MapIDToContainer( |
130 gfx::PluginWindowHandle id) const { | 148 gfx::PluginWindowHandle id) const { |
131 PluginWindowToContainerMap::const_iterator i = | 149 PluginWindowToContainerMap::const_iterator i = |
132 plugin_window_to_container_map_.find(id); | 150 plugin_window_to_container_map_.find(id); |
133 if (i != plugin_window_to_container_map_.end()) | 151 if (i != plugin_window_to_container_map_.end()) |
134 return i->second; | 152 return i->second; |
135 | 153 |
136 LOG(ERROR) << "Request for plugin container for unknown window id " << id; | 154 LOG(ERROR) << "Request for plugin container for unknown window id " << id; |
137 | 155 |
138 return NULL; | 156 return NULL; |
139 } | 157 } |
OLD | NEW |