| 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 #ifndef CHROME_BROWSER_RENDERER_HOST_GPU_PLUGIN_CONTAINER_MAC_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_GPU_PLUGIN_CONTAINER_MAC_H_ |
| 6 #define CHROME_BROWSER_RENDERER_HOST_GPU_PLUGIN_CONTAINER_MAC_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_GPU_PLUGIN_CONTAINER_MAC_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 // The "GPU plugin" is currently implemented as a special kind of | 9 // TODO(jam): remove this file when all files have been converted. |
| 10 // NPAPI plugin to provide high-performance on-screen 3D rendering for | 10 #include "content/browser/renderer_host/accelerated_surface_container_mac.h" |
| 11 // Pepper 3D. | |
| 12 // | |
| 13 // On Windows and X11 platforms the GPU plugin relies on cross-process | |
| 14 // parenting of windows, which is not supported via any public APIs in | |
| 15 // the Mac OS X window system. | |
| 16 // | |
| 17 // To achieve full hardware acceleration we use the new IOSurface APIs | |
| 18 // introduced in Mac OS X 10.6. The GPU plugin's process produces an | |
| 19 // IOSurface and renders into it using OpenGL. It uses the | |
| 20 // IOSurfaceGetID and IOSurfaceLookup APIs to pass a reference to this | |
| 21 // surface to the browser process for on-screen rendering. The GPU | |
| 22 // plugin essentially looks like a windowless plugin; the browser | |
| 23 // process gets all of the mouse events, because the plugin process | |
| 24 // does not have an on-screen window. | |
| 25 // | |
| 26 // This class encapsulates some of the management of these data | |
| 27 // structures, in conjunction with the AcceleratedSurfaceContainerManagerMac. | |
| 28 | |
| 29 #include <CoreFoundation/CoreFoundation.h> | |
| 30 #include <OpenGL/OpenGL.h> | |
| 31 | |
| 32 #include "app/surface/transport_dib.h" | |
| 33 #include "base/basictypes.h" | |
| 34 #include "base/mac/scoped_cftyperef.h" | |
| 35 #include "base/scoped_ptr.h" | |
| 36 #include "ui/gfx/native_widget_types.h" | |
| 37 #include "ui/gfx/rect.h" | |
| 38 | |
| 39 namespace webkit { | |
| 40 namespace npapi { | |
| 41 struct WebPluginGeometry; | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 class AcceleratedSurfaceContainerManagerMac; | |
| 46 | |
| 47 class AcceleratedSurfaceContainerMac { | |
| 48 public: | |
| 49 AcceleratedSurfaceContainerMac( | |
| 50 AcceleratedSurfaceContainerManagerMac* manager, | |
| 51 bool opaque); | |
| 52 virtual ~AcceleratedSurfaceContainerMac(); | |
| 53 | |
| 54 // Sets the backing store and size of this accelerated surface container. | |
| 55 // There are two versions: the IOSurface version is used on systems where the | |
| 56 // IOSurface API is supported (Mac OS X 10.6 and later); the TransportDIB is | |
| 57 // used on Mac OS X 10.5 and earlier. | |
| 58 void SetSizeAndIOSurface(int32 width, | |
| 59 int32 height, | |
| 60 uint64 io_surface_identifier); | |
| 61 void SetSizeAndTransportDIB(int32 width, | |
| 62 int32 height, | |
| 63 TransportDIB::Handle transport_dib); | |
| 64 | |
| 65 // Tells the accelerated surface container that its geometry has changed, | |
| 66 // for example because of a scroll event. (Note that the container | |
| 67 // currently only pays attention to the clip width and height, since the | |
| 68 // view in which it is hosted is responsible for positioning it on the | |
| 69 // page.) | |
| 70 void SetGeometry(const webkit::npapi::WebPluginGeometry& geom); | |
| 71 | |
| 72 // Draws this accelerated surface's contents, texture mapped onto a quad in | |
| 73 // the given OpenGL context. TODO(kbr): figure out and define exactly how the | |
| 74 // coordinate system will work out. | |
| 75 void Draw(CGLContextObj context); | |
| 76 | |
| 77 // Causes the next Draw call to trigger a texture upload. Should be called any | |
| 78 // time the drawing context has changed. | |
| 79 void ForceTextureReload() { texture_needs_upload_ = true; } | |
| 80 | |
| 81 // Returns if the surface should be shown. | |
| 82 bool ShouldBeVisible() const; | |
| 83 | |
| 84 // Notifies the the container that its surface was painted to. | |
| 85 void set_was_painted_to(uint64 surface_id); | |
| 86 | |
| 87 // Notifies the container that its surface is invalid. | |
| 88 void set_surface_invalid() { was_painted_to_ = false; } | |
| 89 private: | |
| 90 // The manager of this accelerated surface container. | |
| 91 AcceleratedSurfaceContainerManagerMac* manager_; | |
| 92 | |
| 93 // Whether this accelerated surface's content is supposed to be opaque. | |
| 94 bool opaque_; | |
| 95 | |
| 96 // The IOSurfaceRef, if any, that has been handed from the GPU | |
| 97 // plugin process back to the browser process for drawing. | |
| 98 // This is held as a CFTypeRef because we can't refer to the | |
| 99 // IOSurfaceRef type when building on 10.5. | |
| 100 base::mac::ScopedCFTypeRef<CFTypeRef> surface_; | |
| 101 | |
| 102 // The id of |surface_|, or 0 if |surface_| is NULL. | |
| 103 uint64 surface_id_; | |
| 104 | |
| 105 // The width and height of the io surface. During resizing, this is different | |
| 106 // from |width_| and |height_|. | |
| 107 int32 surface_width_; | |
| 108 int32 surface_height_; | |
| 109 | |
| 110 // The TransportDIB which is used in pre-10.6 systems where the IOSurface | |
| 111 // API is not supported. This is a weak reference to the actual TransportDIB | |
| 112 // whic is owned by the GPU process. | |
| 113 scoped_ptr<TransportDIB> transport_dib_; | |
| 114 | |
| 115 // The width and height of the container. | |
| 116 int32 width_; | |
| 117 int32 height_; | |
| 118 | |
| 119 // The clip rectangle, relative to the (x_, y_) origin. | |
| 120 gfx::Rect clip_rect_; | |
| 121 | |
| 122 // The "live" OpenGL texture referring to this IOSurfaceRef. Note | |
| 123 // that per the CGLTexImageIOSurface2D API we do not need to | |
| 124 // explicitly update this texture's contents once created. All we | |
| 125 // need to do is ensure it is re-bound before attempting to draw | |
| 126 // with it. | |
| 127 GLuint texture_; | |
| 128 | |
| 129 // True if we need to upload the texture again during the next draw. | |
| 130 bool texture_needs_upload_; | |
| 131 | |
| 132 // This may refer to an old version of the texture if the container is | |
| 133 // resized, for example. | |
| 134 GLuint texture_pending_deletion_; | |
| 135 | |
| 136 // Stores if the plugin has a visible state. | |
| 137 bool visible_; | |
| 138 | |
| 139 // Stores if the plugin's IOSurface has been swapped before. Used to not show | |
| 140 // it before it hasn't been painted to at least once. | |
| 141 bool was_painted_to_; | |
| 142 | |
| 143 // Releases the IOSurface reference, if any, retained by this object. | |
| 144 void ReleaseIOSurface(); | |
| 145 | |
| 146 // Enqueue our texture for later deletion. | |
| 147 void EnqueueTextureForDeletion(); | |
| 148 | |
| 149 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceContainerMac); | |
| 150 }; | |
| 151 | 11 |
| 152 #endif // CHROME_BROWSER_RENDERER_HOST_GPU_PLUGIN_CONTAINER_MAC_H_ | 12 #endif // CHROME_BROWSER_RENDERER_HOST_GPU_PLUGIN_CONTAINER_MAC_H_ |
| 153 | |
| OLD | NEW |