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 "webkit/glue/plugins/mac_gpu_plugin_container.h" |
| 6 |
| 7 #include "webkit/glue/webplugin.h" |
| 8 #include "webkit/glue/plugins/mac_gpu_plugin_container_manager.h" |
| 9 #include "chrome/common/io_surface_support_mac.h" |
| 10 |
| 11 MacGPUPluginContainer::MacGPUPluginContainer() |
| 12 : x_(0), |
| 13 y_(0), |
| 14 surface_(NULL), |
| 15 width_(0), |
| 16 height_(0), |
| 17 texture_(0) { |
| 18 } |
| 19 |
| 20 MacGPUPluginContainer::~MacGPUPluginContainer() { |
| 21 ReleaseIOSurface(); |
| 22 } |
| 23 |
| 24 void MacGPUPluginContainer::ReleaseIOSurface() { |
| 25 if (surface_) { |
| 26 CFRelease(surface_); |
| 27 surface_ = NULL; |
| 28 } |
| 29 } |
| 30 |
| 31 void MacGPUPluginContainer::SetSizeAndBackingStore( |
| 32 int32 width, |
| 33 int32 height, |
| 34 uint64 io_surface_identifier, |
| 35 MacGPUPluginContainerManager* manager) { |
| 36 ReleaseIOSurface(); |
| 37 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
| 38 if (io_surface_support) { |
| 39 surface_ = io_surface_support->IOSurfaceLookup( |
| 40 static_cast<uint32>(io_surface_identifier)); |
| 41 EnqueueTextureForDeletion(manager); |
| 42 width_ = width; |
| 43 height_ = height; |
| 44 } |
| 45 } |
| 46 |
| 47 void MacGPUPluginContainer::MoveTo( |
| 48 const webkit_glue::WebPluginGeometry& geom) { |
| 49 // TODO(kbr): figure out whether additional information is necessary |
| 50 // to keep around. |
| 51 x_ = geom.window_rect.x(); |
| 52 y_ = geom.window_rect.y(); |
| 53 } |
| 54 |
| 55 void MacGPUPluginContainer::Draw(CGLContextObj context) { |
| 56 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
| 57 if (!io_surface_support) |
| 58 return; |
| 59 |
| 60 GLenum target = GL_TEXTURE_RECTANGLE_ARB; |
| 61 if (!texture_ && surface_) { |
| 62 glGenTextures(1, &texture_); |
| 63 glBindTexture(target, texture_); |
| 64 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 65 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 66 // Don't think we need to identify a plane. |
| 67 GLuint plane = 0; |
| 68 io_surface_support->CGLTexImageIOSurface2D(context, |
| 69 target, |
| 70 GL_RGBA, |
| 71 width_, |
| 72 height_, |
| 73 GL_BGRA, |
| 74 GL_UNSIGNED_INT_8_8_8_8_REV, |
| 75 surface_, |
| 76 plane); |
| 77 } |
| 78 |
| 79 if (texture_) { |
| 80 // TODO(kbr): convert this to use only OpenGL ES 2.0 functionality |
| 81 glBindTexture(target, texture_); |
| 82 glEnable(target); |
| 83 glBegin(GL_TRIANGLE_STRIP); |
| 84 int x = x_; |
| 85 int y = y_; |
| 86 glTexCoord2f(0, height_); |
| 87 glVertex3f(x, y, 0); |
| 88 glTexCoord2f(width_, height_); |
| 89 glVertex3f(x + width_, y, 0); |
| 90 glTexCoord2f(0, 0); |
| 91 glVertex3f(x, y + height_, 0); |
| 92 glTexCoord2f(width_, 0); |
| 93 glVertex3f(x + width_, y + height_, 0); |
| 94 glDisable(target); |
| 95 glEnd(); |
| 96 } |
| 97 } |
| 98 |
| 99 void MacGPUPluginContainer::EnqueueTextureForDeletion( |
| 100 MacGPUPluginContainerManager* manager) { |
| 101 manager->EnqueueTextureForDeletion(texture_); |
| 102 texture_ = 0; |
| 103 } |
| 104 |
OLD | NEW |