| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #import <Cocoa/Cocoa.h> | 12 #import <Cocoa/Cocoa.h> |
| 13 #include <IOSurface/IOSurfaceAPI.h> |
| 13 #include <QuartzCore/QuartzCore.h> | 14 #include <QuartzCore/QuartzCore.h> |
| 14 | 15 |
| 15 #include "base/callback.h" | 16 #include "base/callback.h" |
| 16 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 17 #include "base/mac/scoped_cftyperef.h" | 18 #include "base/mac/scoped_cftyperef.h" |
| 18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "base/timer/timer.h" | 22 #include "base/timer/timer.h" |
| 22 #include "media/base/video_frame.h" | 23 #include "media/base/video_frame.h" |
| 23 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
| 24 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
| 25 #include "ui/gfx/rect_conversions.h" | 26 #include "ui/gfx/rect_conversions.h" |
| 26 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
| 27 | 28 |
| 28 class IOSurfaceSupport; | |
| 29 class SkBitmap; | 29 class SkBitmap; |
| 30 | 30 |
| 31 namespace gfx { | 31 namespace gfx { |
| 32 class Rect; | 32 class Rect; |
| 33 } | 33 } |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 | 36 |
| 37 class CompositingIOSurfaceContext; | 37 class CompositingIOSurfaceContext; |
| 38 class CompositingIOSurfaceShaderPrograms; | 38 class CompositingIOSurfaceShaderPrograms; |
| 39 class CompositingIOSurfaceTransformer; | 39 class CompositingIOSurfaceTransformer; |
| 40 class RenderWidgetHostViewFrameSubscriber; | 40 class RenderWidgetHostViewFrameSubscriber; |
| 41 class RenderWidgetHostViewMac; | 41 class RenderWidgetHostViewMac; |
| 42 | 42 |
| 43 // This class manages an OpenGL context and IOSurface for the accelerated | 43 // This class manages an OpenGL context and IOSurface for the accelerated |
| 44 // compositing code path. The GL context is attached to | 44 // compositing code path. The GL context is attached to |
| 45 // RenderWidgetHostViewCocoa for blitting the IOSurface. | 45 // RenderWidgetHostViewCocoa for blitting the IOSurface. |
| 46 class CompositingIOSurfaceMac | 46 class CompositingIOSurfaceMac |
| 47 : public base::RefCounted<CompositingIOSurfaceMac> { | 47 : public base::RefCounted<CompositingIOSurfaceMac> { |
| 48 public: | 48 public: |
| 49 // Returns NULL if IOSurface support is missing or GL APIs fail. | 49 // Returns NULL if IOSurface or GL API calls fail. |
| 50 static scoped_refptr<CompositingIOSurfaceMac> Create(); | 50 static scoped_refptr<CompositingIOSurfaceMac> Create(); |
| 51 | 51 |
| 52 // Set IOSurface that will be drawn on the next NSView drawRect. | 52 // Set IOSurface that will be drawn on the next NSView drawRect. |
| 53 bool SetIOSurfaceWithContextCurrent( | 53 bool SetIOSurfaceWithContextCurrent( |
| 54 scoped_refptr<CompositingIOSurfaceContext> current_context, | 54 scoped_refptr<CompositingIOSurfaceContext> current_context, |
| 55 uint64 io_surface_handle, | 55 uint64 io_surface_handle, |
| 56 const gfx::Size& size, | 56 const gfx::Size& size, |
| 57 float scale_factor) WARN_UNUSED_RESULT; | 57 float scale_factor) WARN_UNUSED_RESULT; |
| 58 | 58 |
| 59 // Get the CGL renderer ID currently associated with this context. | 59 // Get the CGL renderer ID currently associated with this context. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 gfx::Size output_texture_sizes[3]; | 197 gfx::Size output_texture_sizes[3]; |
| 198 GLuint frame_buffers[3]; | 198 GLuint frame_buffers[3]; |
| 199 GLuint pixel_buffers[3]; | 199 GLuint pixel_buffers[3]; |
| 200 GLuint fence; // When non-zero, doing an asynchronous copy. | 200 GLuint fence; // When non-zero, doing an asynchronous copy. |
| 201 int cycles_elapsed; | 201 int cycles_elapsed; |
| 202 base::Callback<bool(const void*, int)> map_buffer_callback; | 202 base::Callback<bool(const void*, int)> map_buffer_callback; |
| 203 base::Callback<void(bool)> done_callback; | 203 base::Callback<void(bool)> done_callback; |
| 204 }; | 204 }; |
| 205 | 205 |
| 206 CompositingIOSurfaceMac( | 206 CompositingIOSurfaceMac( |
| 207 IOSurfaceSupport* io_surface_support, | |
| 208 const scoped_refptr<CompositingIOSurfaceContext>& context); | 207 const scoped_refptr<CompositingIOSurfaceContext>& context); |
| 209 ~CompositingIOSurfaceMac(); | 208 ~CompositingIOSurfaceMac(); |
| 210 | 209 |
| 211 // If this IOSurface has moved to a different window, use that window's | 210 // If this IOSurface has moved to a different window, use that window's |
| 212 // GL context (if multiple visible windows are using the same GL context | 211 // GL context (if multiple visible windows are using the same GL context |
| 213 // then call to setView call can stall and prevent reaching 60fps). | 212 // then call to setView call can stall and prevent reaching 60fps). |
| 214 void SwitchToContextOnNewWindow(NSView* view, | 213 void SwitchToContextOnNewWindow(NSView* view, |
| 215 int window_number); | 214 int window_number); |
| 216 | 215 |
| 217 // Returns true if IOSurface is ready to render. False otherwise. | 216 // Returns true if IOSurface is ready to render. False otherwise. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 265 |
| 267 void FailAllCopies(); | 266 void FailAllCopies(); |
| 268 void DestroyAllCopyContextsWithinContext(); | 267 void DestroyAllCopyContextsWithinContext(); |
| 269 | 268 |
| 270 // Check for GL errors and store the result in error_. Only return new | 269 // Check for GL errors and store the result in error_. Only return new |
| 271 // errors | 270 // errors |
| 272 GLenum GetAndSaveGLError(); | 271 GLenum GetAndSaveGLError(); |
| 273 | 272 |
| 274 gfx::Rect IntersectWithIOSurface(const gfx::Rect& rect) const; | 273 gfx::Rect IntersectWithIOSurface(const gfx::Rect& rect) const; |
| 275 | 274 |
| 276 // Cached pointer to IOSurfaceSupport Singleton. | |
| 277 IOSurfaceSupport* io_surface_support_; | |
| 278 | |
| 279 // Offscreen context used for all operations other than drawing to the | 275 // Offscreen context used for all operations other than drawing to the |
| 280 // screen. This is in the same share group as the contexts used for | 276 // screen. This is in the same share group as the contexts used for |
| 281 // drawing, and is the same for all IOSurfaces in all windows. | 277 // drawing, and is the same for all IOSurfaces in all windows. |
| 282 scoped_refptr<CompositingIOSurfaceContext> offscreen_context_; | 278 scoped_refptr<CompositingIOSurfaceContext> offscreen_context_; |
| 283 | 279 |
| 284 // IOSurface data. | 280 // IOSurface data. |
| 285 uint64 io_surface_handle_; | 281 uint64 io_surface_handle_; |
| 286 base::ScopedCFTypeRef<CFTypeRef> io_surface_; | 282 base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; |
| 287 | 283 |
| 288 // The width and height of the io surface. | 284 // The width and height of the io surface. |
| 289 gfx::Size pixel_io_surface_size_; // In pixels. | 285 gfx::Size pixel_io_surface_size_; // In pixels. |
| 290 gfx::Size dip_io_surface_size_; // In view / density independent pixels. | 286 gfx::Size dip_io_surface_size_; // In view / density independent pixels. |
| 291 float scale_factor_; | 287 float scale_factor_; |
| 292 | 288 |
| 293 // The "live" OpenGL texture referring to this IOSurfaceRef. Note | 289 // The "live" OpenGL texture referring to this IOSurfaceRef. Note |
| 294 // that per the CGLTexImageIOSurface2D API we do not need to | 290 // that per the CGLTexImageIOSurface2D API we do not need to |
| 295 // explicitly update this texture's contents once created. All we | 291 // explicitly update this texture's contents once created. All we |
| 296 // need to do is ensure it is re-bound before attempting to draw | 292 // need to do is ensure it is re-bound before attempting to draw |
| (...skipping 30 matching lines...) Expand all Loading... |
| 327 | 323 |
| 328 static void EvictionScheduleDoEvict(); | 324 static void EvictionScheduleDoEvict(); |
| 329 static void EvictionDoEvict(); | 325 static void EvictionDoEvict(); |
| 330 static base::LazyInstance<EvictionQueue> eviction_queue_; | 326 static base::LazyInstance<EvictionQueue> eviction_queue_; |
| 331 static bool eviction_scheduled_; | 327 static bool eviction_scheduled_; |
| 332 }; | 328 }; |
| 333 | 329 |
| 334 } // namespace content | 330 } // namespace content |
| 335 | 331 |
| 336 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ | 332 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ |
| OLD | NEW |