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