| 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_COMPOSITOR_IO_SURFACE_TEXTURE_MAC_H_ | 5 #ifndef UI_COMPOSITOR_MAC_IO_SURFACE_TEXTURE_MAC_H_ |
| 6 #define CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_TEXTURE_MAC_H_ | 6 #define UI_COMPOSITOR_MAC_IO_SURFACE_TEXTURE_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 <IOSurface/IOSurfaceAPI.h> |
| 14 #include <QuartzCore/QuartzCore.h> | 14 #include <QuartzCore/QuartzCore.h> |
| 15 | 15 |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 18 #include "base/mac/scoped_cftyperef.h" | 18 #include "base/mac/scoped_cftyperef.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "media/base/video_frame.h" | |
| 23 #include "ui/gfx/native_widget_types.h" | 22 #include "ui/gfx/native_widget_types.h" |
| 24 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
| 25 #include "ui/gfx/rect_conversions.h" | 24 #include "ui/gfx/rect_conversions.h" |
| 26 #include "ui/gfx/size.h" | 25 #include "ui/gfx/size.h" |
| 27 | 26 |
| 28 class SkBitmap; | 27 class SkBitmap; |
| 29 | 28 |
| 30 namespace gfx { | 29 namespace gfx { |
| 31 class Rect; | 30 class Rect; |
| 32 } | 31 } |
| 33 | 32 |
| 34 namespace content { | 33 namespace ui { |
| 35 | 34 |
| 36 class IOSurfaceContext; | 35 class IOSurfaceContext; |
| 37 class RenderWidgetHostViewFrameSubscriber; | 36 class RenderWidgetHostViewFrameSubscriber; |
| 38 class RenderWidgetHostViewMac; | 37 class RenderWidgetHostViewMac; |
| 39 | 38 |
| 40 // This class manages an OpenGL context and IOSurfaceTexture for the accelerated | 39 // This class manages an OpenGL context and IOSurfaceTexture for the accelerated |
| 41 // compositing code path. The GL context is attached to | 40 // compositing code path. The GL context is attached to |
| 42 // RenderWidgetHostViewCocoa for blitting the IOSurfaceTexture. | 41 // RenderWidgetHostViewCocoa for blitting the IOSurfaceTexture. |
| 43 class IOSurfaceTexture | 42 class IOSurfaceTexture |
| 44 : public base::RefCounted<IOSurfaceTexture> { | 43 : public base::RefCounted<IOSurfaceTexture> { |
| 45 public: | 44 public: |
| 46 // Returns NULL if IOSurfaceTexture or GL API calls fail. | 45 // Returns NULL if IOSurfaceTexture or GL API calls fail. |
| 47 static scoped_refptr<IOSurfaceTexture> Create(); | 46 static scoped_refptr<IOSurfaceTexture> Create( |
| 47 bool needs_gl_finish_workaround); |
| 48 | 48 |
| 49 // Set IOSurfaceTexture that will be drawn on the next NSView drawRect. | 49 // Set IOSurfaceTexture that will be drawn on the next NSView drawRect. |
| 50 bool SetIOSurface( | 50 bool SetIOSurface( |
| 51 IOSurfaceID io_surface_id, | 51 IOSurfaceID io_surface_id, |
| 52 const gfx::Size& pixel_size) WARN_UNUSED_RESULT; | 52 const gfx::Size& pixel_size) WARN_UNUSED_RESULT; |
| 53 | 53 |
| 54 // Blit the IOSurface to the rectangle specified by |window_rect| in DIPs, | 54 // Blit the IOSurface to the rectangle specified by |window_rect| in DIPs, |
| 55 // with the origin in the lower left corner. If the window rect's size is | 55 // with the origin in the lower left corner. If the window rect's size is |
| 56 // larger than the IOSurface, the remaining right and bottom edges will be | 56 // larger than the IOSurface, the remaining right and bottom edges will be |
| 57 // white. |window_scale_factor| is 1 in normal views, 2 in HiDPI views. | 57 // white. |window_scale_factor| is 1 in normal views, 2 in HiDPI views. |
| 58 bool DrawIOSurface() WARN_UNUSED_RESULT; | 58 bool DrawIOSurface() WARN_UNUSED_RESULT; |
| 59 | 59 |
| 60 // Returns true if the offscreen context used by this surface has been | 60 // Returns true if the offscreen context used by this surface has been |
| 61 // poisoned. | 61 // poisoned. |
| 62 bool HasBeenPoisoned() const; | 62 bool HasBeenPoisoned() const; |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 friend class base::RefCounted<IOSurfaceTexture>; | 65 friend class base::RefCounted<IOSurfaceTexture>; |
| 66 | 66 |
| 67 IOSurfaceTexture( | 67 IOSurfaceTexture( |
| 68 const scoped_refptr<IOSurfaceContext>& context); | 68 const scoped_refptr<IOSurfaceContext>& context, |
| 69 bool needs_gl_finish_workaround); |
| 69 ~IOSurfaceTexture(); | 70 ~IOSurfaceTexture(); |
| 70 | 71 |
| 71 // Unref the IOSurfaceTexture and delete the associated GL texture. If the GPU | 72 // Unref the IOSurfaceTexture and delete the associated GL texture. If the GPU |
| 72 // process is no longer referencing it, this will delete the IOSurface. | 73 // process is no longer referencing it, this will delete the IOSurface. |
| 73 void ReleaseIOSurfaceAndTexture(); | 74 void ReleaseIOSurfaceAndTexture(); |
| 74 | 75 |
| 75 // Check for GL errors and store the result in error_. Only return new | 76 // Check for GL errors and store the result in error_. Only return new |
| 76 // errors | 77 // errors |
| 77 GLenum GetAndSaveGLError(); | 78 GLenum GetAndSaveGLError(); |
| 78 | 79 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 102 // Aggressively evict surfaces when more than 8 (the number allowed by the | 103 // Aggressively evict surfaces when more than 8 (the number allowed by the |
| 103 // memory manager for fast tab switching) are allocated. | 104 // memory manager for fast tab switching) are allocated. |
| 104 enum { | 105 enum { |
| 105 kMaximumUnevictedSurfaces = 8, | 106 kMaximumUnevictedSurfaces = 8, |
| 106 }; | 107 }; |
| 107 typedef std::list<IOSurfaceTexture*> EvictionQueue; | 108 typedef std::list<IOSurfaceTexture*> EvictionQueue; |
| 108 void EvictionMarkUpdated(); | 109 void EvictionMarkUpdated(); |
| 109 void EvictionMarkEvicted(); | 110 void EvictionMarkEvicted(); |
| 110 EvictionQueue::iterator eviction_queue_iterator_; | 111 EvictionQueue::iterator eviction_queue_iterator_; |
| 111 bool eviction_has_been_drawn_since_updated_; | 112 bool eviction_has_been_drawn_since_updated_; |
| 113 const bool needs_gl_finish_workaround_; |
| 112 | 114 |
| 113 static void EvictionScheduleDoEvict(); | 115 static void EvictionScheduleDoEvict(); |
| 114 static void EvictionDoEvict(); | 116 static void EvictionDoEvict(); |
| 115 static base::LazyInstance<EvictionQueue> eviction_queue_; | 117 static base::LazyInstance<EvictionQueue> eviction_queue_; |
| 116 static bool eviction_scheduled_; | 118 static bool eviction_scheduled_; |
| 117 }; | 119 }; |
| 118 | 120 |
| 119 } // namespace content | 121 } // namespace ui |
| 120 | 122 |
| 121 #endif // CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_TEXTURE_MAC_H_ | 123 #endif // UI_COMPOSITOR_MAC_IO_SURFACE_TEXTURE_MAC_H_ |
| OLD | NEW |