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_mac.h" | 5 #include "chrome/browser/renderer_host/accelerated_surface_container_mac.h" |
6 | 6 |
7 #include "app/surface/io_surface_support_mac.h" | 7 #include "app/surface/io_surface_support_mac.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/renderer_host/accelerated_surface_container_manager_mac .h" | 9 #include "chrome/browser/renderer_host/accelerated_surface_container_manager_mac .h" |
10 #include "webkit/glue/plugins/webplugin.h" | 10 #include "webkit/glue/plugins/webplugin.h" |
11 | 11 |
12 AcceleratedSurfaceContainerMac::AcceleratedSurfaceContainerMac( | 12 AcceleratedSurfaceContainerMac::AcceleratedSurfaceContainerMac( |
13 AcceleratedSurfaceContainerManagerMac* manager, | 13 AcceleratedSurfaceContainerManagerMac* manager, |
14 bool opaque) | 14 bool opaque) |
15 : manager_(manager), | 15 : manager_(manager), |
16 opaque_(opaque), | 16 opaque_(opaque), |
17 x_(0), | |
18 y_(0), | |
19 surface_(NULL), | 17 surface_(NULL), |
20 width_(0), | 18 width_(0), |
21 height_(0), | 19 height_(0), |
22 texture_(0), | 20 texture_(0), |
23 texture_needs_upload_(true) { | 21 texture_needs_upload_(true) { |
24 } | 22 } |
25 | 23 |
26 AcceleratedSurfaceContainerMac::~AcceleratedSurfaceContainerMac() { | 24 AcceleratedSurfaceContainerMac::~AcceleratedSurfaceContainerMac() { |
27 EnqueueTextureForDeletion(); | 25 EnqueueTextureForDeletion(); |
28 ReleaseIOSurface(); | 26 ReleaseIOSurface(); |
(...skipping 26 matching lines...) Expand all Loading... | |
55 int32 height, | 53 int32 height, |
56 TransportDIB::Handle transport_dib) { | 54 TransportDIB::Handle transport_dib) { |
57 if (TransportDIB::is_valid(transport_dib)) { | 55 if (TransportDIB::is_valid(transport_dib)) { |
58 transport_dib_.reset(TransportDIB::Map(transport_dib)); | 56 transport_dib_.reset(TransportDIB::Map(transport_dib)); |
59 EnqueueTextureForDeletion(); | 57 EnqueueTextureForDeletion(); |
60 width_ = width; | 58 width_ = width; |
61 height_ = height; | 59 height_ = height; |
62 } | 60 } |
63 } | 61 } |
64 | 62 |
65 void AcceleratedSurfaceContainerMac::MoveTo( | 63 void AcceleratedSurfaceContainerMac::MoveTo( |
stuartmorgan
2010/08/11 16:40:44
MoveTo is a poor name for this function at this po
Ken Russell (switch to Gerrit)
2010/08/14 02:12:11
Will rename.
| |
66 const webkit_glue::WebPluginGeometry& geom) { | 64 const webkit_glue::WebPluginGeometry& geom) { |
67 x_ = geom.window_rect.x(); | |
68 y_ = geom.window_rect.y(); | |
69 // TODO(kbr): may need to pay attention to cutout rects. | 65 // TODO(kbr): may need to pay attention to cutout rects. |
70 if (geom.visible) | 66 if (geom.visible) |
71 clipRect_ = geom.clip_rect; | 67 clipRect_ = geom.clip_rect; |
72 else | 68 else |
73 clipRect_ = gfx::Rect(); | 69 clipRect_ = gfx::Rect(); |
74 } | 70 } |
75 | 71 |
76 void AcceleratedSurfaceContainerMac::Draw(CGLContextObj context) { | 72 void AcceleratedSurfaceContainerMac::Draw(CGLContextObj context) { |
77 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); | 73 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
78 GLenum target = GL_TEXTURE_RECTANGLE_ARB; | 74 GLenum target = GL_TEXTURE_RECTANGLE_ARB; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 } | 134 } |
139 | 135 |
140 if (texture_) { | 136 if (texture_) { |
141 // TODO(kbr): convert this to use only OpenGL ES 2.0 functionality. | 137 // TODO(kbr): convert this to use only OpenGL ES 2.0 functionality. |
142 | 138 |
143 // TODO(kbr): may need to pay attention to cutout rects. | 139 // TODO(kbr): may need to pay attention to cutout rects. |
144 int clipX = clipRect_.x(); | 140 int clipX = clipRect_.x(); |
145 int clipY = clipRect_.y(); | 141 int clipY = clipRect_.y(); |
146 int clipWidth = clipRect_.width(); | 142 int clipWidth = clipRect_.width(); |
147 int clipHeight = clipRect_.height(); | 143 int clipHeight = clipRect_.height(); |
148 int x = x_ + clipX; | |
149 int y = y_ + clipY; | |
150 | 144 |
151 if (opaque_) { | 145 if (opaque_) { |
152 // Pepper 3D's output is currently considered opaque even if the | 146 // Pepper 3D's output is currently considered opaque even if the |
153 // program draws pixels with alpha less than 1. In order to have | 147 // program draws pixels with alpha less than 1. In order to have |
154 // this effect, we need to drop the alpha channel of the input, | 148 // this effect, we need to drop the alpha channel of the input, |
155 // replacing it with alpha = 1. | 149 // replacing it with alpha = 1. |
156 | 150 |
157 // First fill the rectangle with alpha=1. | 151 // First fill the rectangle with alpha=1. |
158 glColorMask(false, false, false, true); | 152 glColorMask(false, false, false, true); |
159 glColor4f(0.0f, 0.0f, 0.0f, 1.0f); | 153 glColor4f(0.0f, 0.0f, 0.0f, 1.0f); |
160 glBegin(GL_TRIANGLE_STRIP); | 154 glBegin(GL_TRIANGLE_STRIP); |
161 glVertex3f(x, y, 0); | 155 glVertex3f(0, 0, 0); |
162 glVertex3f(x + clipWidth, y, 0); | 156 glVertex3f(clipWidth, 0, 0); |
163 glVertex3f(x, y + clipHeight, 0); | 157 glVertex3f(0, clipHeight, 0); |
164 glVertex3f(x + clipWidth, y + clipHeight, 0); | 158 glVertex3f(clipWidth, clipHeight, 0); |
165 glEnd(); | 159 glEnd(); |
166 | 160 |
167 // Now draw the color channels from the incoming texture. | 161 // Now draw the color channels from the incoming texture. |
168 glColorMask(true, true, true, false); | 162 glColorMask(true, true, true, false); |
169 // This call shouldn't be necessary -- we are using the GL_REPLACE | 163 // This call shouldn't be necessary -- we are using the GL_REPLACE |
170 // texture environment mode -- but it appears to be. | 164 // texture environment mode -- but it appears to be. |
171 glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | 165 glColor4f(1.0f, 1.0f, 1.0f, 1.0f); |
172 } else { | 166 } else { |
173 glColorMask(true, true, true, true); | 167 glColorMask(true, true, true, true); |
174 } | 168 } |
175 | 169 |
176 // Draw the color channels from the incoming texture. | 170 // Draw the color channels from the incoming texture. |
177 glBindTexture(target, texture_); | 171 glBindTexture(target, texture_); |
178 glEnable(target); | 172 glEnable(target); |
179 glBegin(GL_TRIANGLE_STRIP); | 173 glBegin(GL_TRIANGLE_STRIP); |
180 glTexCoord2f(clipX, height_ - clipY); | 174 |
181 glVertex3f(x, y, 0); | 175 glTexCoord2f(clipX, height_ - clipY); |
182 glTexCoord2f(clipX + clipWidth, height_ - clipY); | 176 glVertex3f(0, 0, 0); |
183 glVertex3f(x + clipWidth, y, 0); | 177 |
184 glTexCoord2f(clipX, height_ - clipY - clipHeight); | 178 glTexCoord2f(clipX + clipWidth, height_ - clipY); |
185 glVertex3f(x, y + clipHeight, 0); | 179 glVertex3f(clipWidth, 0, 0); |
186 glTexCoord2f(clipX + clipWidth, height_ - clipY - clipHeight); | 180 |
187 glVertex3f(x + clipWidth, y + clipHeight, 0); | 181 glTexCoord2f(clipX, height_ - clipY - clipHeight); |
182 glVertex3f(0, clipHeight, 0); | |
183 | |
184 glTexCoord2f(clipX + clipWidth, height_ - clipY - clipHeight); | |
185 glVertex3f(clipWidth, clipHeight, 0); | |
186 | |
188 glEnd(); | 187 glEnd(); |
189 glDisable(target); | 188 glDisable(target); |
190 } | 189 } |
191 } | 190 } |
192 | 191 |
193 void AcceleratedSurfaceContainerMac::EnqueueTextureForDeletion() { | 192 void AcceleratedSurfaceContainerMac::EnqueueTextureForDeletion() { |
194 if (texture_) { | 193 if (texture_) { |
195 manager_->EnqueueTextureForDeletion(texture_); | 194 manager_->EnqueueTextureForDeletion(texture_); |
196 texture_ = 0; | 195 texture_ = 0; |
197 } | 196 } |
198 } | 197 } |
199 | 198 |
OLD | NEW |