| 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 surface_(NULL), | 17 surface_(NULL), |
| 18 width_(0), | 18 width_(0), |
| 19 height_(0), | 19 height_(0), |
| 20 texture_(0), | 20 texture_(0), |
| 21 texture_needs_upload_(true) { | 21 texture_needs_upload_(true), |
| 22 texture_pending_deletion_(0) { |
| 22 } | 23 } |
| 23 | 24 |
| 24 AcceleratedSurfaceContainerMac::~AcceleratedSurfaceContainerMac() { | 25 AcceleratedSurfaceContainerMac::~AcceleratedSurfaceContainerMac() { |
| 25 EnqueueTextureForDeletion(); | |
| 26 ReleaseIOSurface(); | 26 ReleaseIOSurface(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void AcceleratedSurfaceContainerMac::ReleaseIOSurface() { | 29 void AcceleratedSurfaceContainerMac::ReleaseIOSurface() { |
| 30 if (surface_) { | 30 if (surface_) { |
| 31 CFRelease(surface_); | 31 CFRelease(surface_); |
| 32 surface_ = NULL; | 32 surface_ = NULL; |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 53 int32 height, | 53 int32 height, |
| 54 TransportDIB::Handle transport_dib) { | 54 TransportDIB::Handle transport_dib) { |
| 55 if (TransportDIB::is_valid(transport_dib)) { | 55 if (TransportDIB::is_valid(transport_dib)) { |
| 56 transport_dib_.reset(TransportDIB::Map(transport_dib)); | 56 transport_dib_.reset(TransportDIB::Map(transport_dib)); |
| 57 EnqueueTextureForDeletion(); | 57 EnqueueTextureForDeletion(); |
| 58 width_ = width; | 58 width_ = width; |
| 59 height_ = height; | 59 height_ = height; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 void AcceleratedSurfaceContainerMac::MoveTo( | 63 void AcceleratedSurfaceContainerMac::SetGeometry( |
| 64 const webkit_glue::WebPluginGeometry& geom) { | 64 const webkit_glue::WebPluginGeometry& geom) { |
| 65 // TODO(kbr): may need to pay attention to cutout rects. | 65 // TODO(kbr): may need to pay attention to cutout rects. |
| 66 if (geom.visible) | 66 if (geom.visible) |
| 67 clipRect_ = geom.clip_rect; | 67 clipRect_ = geom.clip_rect; |
| 68 else | 68 else |
| 69 clipRect_ = gfx::Rect(); | 69 clipRect_ = gfx::Rect(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void AcceleratedSurfaceContainerMac::Draw(CGLContextObj context) { | 72 void AcceleratedSurfaceContainerMac::Draw(CGLContextObj context) { |
| 73 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); | 73 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
| 74 GLenum target = GL_TEXTURE_RECTANGLE_ARB; | 74 GLenum target = GL_TEXTURE_RECTANGLE_ARB; |
| 75 if (texture_pending_deletion_) { |
| 76 // Clean up an old texture object. This is essentially a pre-emptive |
| 77 // cleanup, as the resources will be released when the OpenGL context |
| 78 // associated with our containing NSView is destroyed. However, if we |
| 79 // resize a plugin often, we might generate a lot of textures, so we |
| 80 // should try to eagerly reclaim their resources. Note also that the |
| 81 // OpenGL context must be current when performing the deletion, and it |
| 82 // seems risky to make the OpenGL context current at an arbitrary point |
| 83 // in time, which is why the deletion does not occur in the container's |
| 84 // destructor. |
| 85 glDeleteTextures(1, &texture_pending_deletion_); |
| 86 texture_pending_deletion_ = 0; |
| 87 } |
| 75 if (!texture_) { | 88 if (!texture_) { |
| 76 if ((io_surface_support && !surface_) || | 89 if ((io_surface_support && !surface_) || |
| 77 (!io_surface_support && !transport_dib_.get())) | 90 (!io_surface_support && !transport_dib_.get())) |
| 78 return; | 91 return; |
| 79 glGenTextures(1, &texture_); | 92 glGenTextures(1, &texture_); |
| 80 glBindTexture(target, texture_); | 93 glBindTexture(target, texture_); |
| 81 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 94 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 82 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 95 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 83 if (io_surface_support) { | 96 if (io_surface_support) { |
| 84 texture_needs_upload_ = true; | 97 texture_needs_upload_ = true; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 glTexCoord2f(clipX + clipWidth, height_ - clipY - clipHeight); | 197 glTexCoord2f(clipX + clipWidth, height_ - clipY - clipHeight); |
| 185 glVertex3f(clipWidth, clipHeight, 0); | 198 glVertex3f(clipWidth, clipHeight, 0); |
| 186 | 199 |
| 187 glEnd(); | 200 glEnd(); |
| 188 glDisable(target); | 201 glDisable(target); |
| 189 } | 202 } |
| 190 } | 203 } |
| 191 | 204 |
| 192 void AcceleratedSurfaceContainerMac::EnqueueTextureForDeletion() { | 205 void AcceleratedSurfaceContainerMac::EnqueueTextureForDeletion() { |
| 193 if (texture_) { | 206 if (texture_) { |
| 194 manager_->EnqueueTextureForDeletion(texture_); | 207 DCHECK(texture_pending_deletion_ == 0); |
| 208 texture_pending_deletion_ = texture_; |
| 195 texture_ = 0; | 209 texture_ = 0; |
| 196 } | 210 } |
| 197 } | 211 } |
| 198 | 212 |
| OLD | NEW |