Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/renderer_host/accelerated_surface_container_mac.h" | 5 #include "content/browser/renderer_host/accelerated_surface_container_mac.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/browser/renderer_host/accelerated_surface_container_manager_ma c.h" | 8 #include "content/browser/renderer_host/accelerated_surface_container_manager_ma c.h" |
| 9 #include "ui/gfx/surface/io_surface_support_mac.h" | 9 #include "ui/gfx/surface/io_surface_support_mac.h" |
| 10 #include "webkit/plugins/npapi/webplugin.h" | 10 #include "webkit/plugins/npapi/webplugin.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 surface_width_, | 111 surface_width_, |
| 112 surface_height_, | 112 surface_height_, |
| 113 GL_BGRA, | 113 GL_BGRA, |
| 114 GL_UNSIGNED_INT_8_8_8_8_REV, | 114 GL_UNSIGNED_INT_8_8_8_8_REV, |
| 115 surface_.get(), | 115 surface_.get(), |
| 116 plane); | 116 plane); |
| 117 texture_needs_upload_ = false; | 117 texture_needs_upload_ = false; |
| 118 } | 118 } |
| 119 // If using TransportDIBs, the texture needs to be uploaded every frame. | 119 // If using TransportDIBs, the texture needs to be uploaded every frame. |
| 120 if (transport_dib_.get() != NULL) { | 120 if (transport_dib_.get() != NULL) { |
| 121 void* pixel_memory = transport_dib_->memory(); | 121 unsigned char* pixel_memory = |
| 122 static_cast<unsigned char*>(transport_dib_->memory()); | |
| 122 if (pixel_memory) { | 123 if (pixel_memory) { |
| 123 glBindTexture(target, texture_); | 124 glBindTexture(target, texture_); |
| 124 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Needed for NPOT textures. | 125 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Needed for NPOT textures. |
| 125 glTexSubImage2D(target, | 126 if (update_rect_.IsEmpty()) { |
| 126 0, // mipmap level 0 | 127 glTexSubImage2D(target, |
| 127 0, // x-offset | 128 0, // mipmap level 0 |
| 128 0, // y-offset | 129 0, // x-offset |
| 129 width_, | 130 0, // y-offset |
| 130 height_, | 131 width_, |
| 131 GL_BGRA, // The GPU plugin gave us BGRA pixels | 132 height_, |
| 132 GL_UNSIGNED_INT_8_8_8_8_REV, | 133 GL_BGRA, // The GPU plugin gave us BGRA pixels |
| 133 pixel_memory); | 134 GL_UNSIGNED_INT_8_8_8_8_REV, |
| 135 pixel_memory); | |
| 136 } else { | |
| 137 glPixelStorei(GL_UNPACK_ROW_LENGTH, width_); | |
| 138 glTexSubImage2D(target, | |
| 139 0, // mipmap level 0 | |
| 140 update_rect_.x(), // x-offset | |
| 141 update_rect_.y(), // y-offset | |
| 142 update_rect_.width(), | |
| 143 update_rect_.height(), | |
| 144 GL_BGRA, // The GPU plugin gave us BGRA pixels | |
| 145 GL_UNSIGNED_INT_8_8_8_8_REV, | |
| 146 &pixel_memory[(update_rect_.x() + | |
| 147 update_rect_.y() * width_) * 4]); | |
| 148 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); | |
| 149 } | |
| 134 } | 150 } |
| 135 } | 151 } |
| 152 update_rect_ = gfx::Rect(); | |
| 136 | 153 |
| 137 if (texture_) { | 154 if (texture_) { |
| 138 int texture_width = io_surface_support ? surface_width_ : width_; | 155 int texture_width = io_surface_support ? surface_width_ : width_; |
| 139 int texture_height = io_surface_support ? surface_height_ : height_; | 156 int texture_height = io_surface_support ? surface_height_ : height_; |
| 140 | 157 |
| 141 // TODO(kbr): convert this to use only OpenGL ES 2.0 functionality. | 158 // TODO(kbr): convert this to use only OpenGL ES 2.0 functionality. |
| 142 | 159 |
| 143 // TODO(kbr): may need to pay attention to cutout rects. | 160 // TODO(kbr): may need to pay attention to cutout rects. |
| 144 int clipX = clip_rect_.x(); | 161 int clipX = clip_rect_.x(); |
| 145 int clipY = clip_rect_.y(); | 162 int clipY = clip_rect_.y(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 | 212 |
| 196 glEnd(); | 213 glEnd(); |
| 197 glDisable(target); | 214 glDisable(target); |
| 198 } | 215 } |
| 199 } | 216 } |
| 200 | 217 |
| 201 bool AcceleratedSurfaceContainerMac::ShouldBeVisible() const { | 218 bool AcceleratedSurfaceContainerMac::ShouldBeVisible() const { |
| 202 return visible_ && was_painted_to_ && !clip_rect_.IsEmpty(); | 219 return visible_ && was_painted_to_ && !clip_rect_.IsEmpty(); |
| 203 } | 220 } |
| 204 | 221 |
| 205 void AcceleratedSurfaceContainerMac::set_was_painted_to(uint64 surface_id) { | 222 void AcceleratedSurfaceContainerMac::set_was_painted_to_common( |
| 223 uint64 surface_id) { | |
| 206 if (surface_id && (!surface_ || surface_id != surface_id_)) { | 224 if (surface_id && (!surface_ || surface_id != surface_id_)) { |
| 207 // Keep the surface that was most recently painted to around. | 225 // Keep the surface that was most recently painted to around. |
| 208 if (IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize()) { | 226 if (IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize()) { |
| 209 CFTypeRef surface = io_surface_support->IOSurfaceLookup( | 227 CFTypeRef surface = io_surface_support->IOSurfaceLookup( |
| 210 static_cast<uint32>(surface_id)); | 228 static_cast<uint32>(surface_id)); |
| 211 // Can fail if IOSurface with that ID was already released by the | 229 // Can fail if IOSurface with that ID was already released by the |
| 212 // gpu process or the plugin process. We will get a |set_was_painted_to()| | 230 // gpu process or the plugin process. We will get a |set_was_painted_to()| |
| 213 // message with a new surface soon in that case. | 231 // message with a new surface soon in that case. |
| 214 if (surface) { | 232 if (surface) { |
| 215 surface_.reset(surface); | 233 surface_.reset(surface); |
| 216 surface_id_ = surface_id; | 234 surface_id_ = surface_id; |
| 217 surface_width_ = io_surface_support->IOSurfaceGetWidth(surface_); | 235 surface_width_ = io_surface_support->IOSurfaceGetWidth(surface_); |
| 218 surface_height_ = io_surface_support->IOSurfaceGetHeight(surface_); | 236 surface_height_ = io_surface_support->IOSurfaceGetHeight(surface_); |
| 219 EnqueueTextureForDeletion(); | 237 EnqueueTextureForDeletion(); |
| 220 } | 238 } |
| 221 } | 239 } |
| 222 } | 240 } |
| 223 was_painted_to_ = true; | 241 was_painted_to_ = true; |
| 224 } | 242 } |
| 225 | 243 |
| 244 void AcceleratedSurfaceContainerMac::set_was_painted_to(uint64 surface_id) { | |
|
sky
2011/12/06 19:40:39
nit: position should match header.
jonathan.backer
2011/12/06 20:24:41
Done.
| |
| 245 set_was_painted_to_common(surface_id); | |
| 246 update_rect_ = gfx::Rect(); | |
| 247 } | |
| 248 | |
| 249 void AcceleratedSurfaceContainerMac::set_was_painted_to( | |
| 250 uint64 surface_id, | |
| 251 const gfx::Rect& update_rect) { | |
| 252 set_was_painted_to_common(surface_id); | |
| 253 update_rect_ = update_rect_.Union(update_rect); | |
| 254 } | |
| 255 | |
| 226 void AcceleratedSurfaceContainerMac::EnqueueTextureForDeletion() { | 256 void AcceleratedSurfaceContainerMac::EnqueueTextureForDeletion() { |
| 227 if (texture_) { | 257 if (texture_) { |
| 228 DCHECK(texture_pending_deletion_ == 0); | 258 DCHECK(texture_pending_deletion_ == 0); |
| 229 texture_pending_deletion_ = texture_; | 259 texture_pending_deletion_ = texture_; |
| 230 texture_ = 0; | 260 texture_ = 0; |
| 231 } | 261 } |
| 232 } | 262 } |
| 233 | 263 |
| OLD | NEW |