| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_TEXTURE_MAC_H_ | |
| 6 #define CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_TEXTURE_MAC_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 #include <list> | |
| 10 #include <vector> | |
| 11 | |
| 12 #import <Cocoa/Cocoa.h> | |
| 13 #include <IOSurface/IOSurfaceAPI.h> | |
| 14 #include <QuartzCore/QuartzCore.h> | |
| 15 | |
| 16 #include "base/callback.h" | |
| 17 #include "base/lazy_instance.h" | |
| 18 #include "base/mac/scoped_cftyperef.h" | |
| 19 #include "base/memory/ref_counted.h" | |
| 20 #include "base/memory/scoped_ptr.h" | |
| 21 #include "base/time/time.h" | |
| 22 #include "media/base/video_frame.h" | |
| 23 #include "ui/gfx/native_widget_types.h" | |
| 24 #include "ui/gfx/rect.h" | |
| 25 #include "ui/gfx/rect_conversions.h" | |
| 26 #include "ui/gfx/size.h" | |
| 27 | |
| 28 class SkBitmap; | |
| 29 | |
| 30 namespace gfx { | |
| 31 class Rect; | |
| 32 } | |
| 33 | |
| 34 namespace content { | |
| 35 | |
| 36 class IOSurfaceContext; | |
| 37 class RenderWidgetHostViewFrameSubscriber; | |
| 38 class RenderWidgetHostViewMac; | |
| 39 | |
| 40 // This class manages an OpenGL context and IOSurfaceTexture for the accelerated | |
| 41 // compositing code path. The GL context is attached to | |
| 42 // RenderWidgetHostViewCocoa for blitting the IOSurfaceTexture. | |
| 43 class IOSurfaceTexture | |
| 44 : public base::RefCounted<IOSurfaceTexture> { | |
| 45 public: | |
| 46 // Returns NULL if IOSurfaceTexture or GL API calls fail. | |
| 47 static scoped_refptr<IOSurfaceTexture> Create(); | |
| 48 | |
| 49 // Set IOSurfaceTexture that will be drawn on the next NSView drawRect. | |
| 50 bool SetIOSurface( | |
| 51 IOSurfaceID io_surface_id, | |
| 52 const gfx::Size& pixel_size) WARN_UNUSED_RESULT; | |
| 53 | |
| 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 | |
| 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. | |
| 58 bool DrawIOSurface() WARN_UNUSED_RESULT; | |
| 59 | |
| 60 // Returns true if the offscreen context used by this surface has been | |
| 61 // poisoned. | |
| 62 bool HasBeenPoisoned() const; | |
| 63 | |
| 64 private: | |
| 65 friend class base::RefCounted<IOSurfaceTexture>; | |
| 66 | |
| 67 IOSurfaceTexture( | |
| 68 const scoped_refptr<IOSurfaceContext>& context); | |
| 69 ~IOSurfaceTexture(); | |
| 70 | |
| 71 // 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 void ReleaseIOSurfaceAndTexture(); | |
| 74 | |
| 75 // Check for GL errors and store the result in error_. Only return new | |
| 76 // errors | |
| 77 GLenum GetAndSaveGLError(); | |
| 78 | |
| 79 // Offscreen context used for all operations other than drawing to the | |
| 80 // screen. This is in the same share group as the contexts used for | |
| 81 // drawing, and is the same for all IOSurfaces in all windows. | |
| 82 scoped_refptr<IOSurfaceContext> offscreen_context_; | |
| 83 | |
| 84 // The IOSurface and its non-rounded size. | |
| 85 base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; | |
| 86 gfx::Size pixel_size_; | |
| 87 | |
| 88 // The "live" OpenGL texture referring to this IOSurfaceRef. Note | |
| 89 // that per the CGLTexImageIOSurface2D API we do not need to | |
| 90 // explicitly update this texture's contents once created. All we | |
| 91 // need to do is ensure it is re-bound before attempting to draw | |
| 92 // with it. | |
| 93 GLuint texture_; | |
| 94 | |
| 95 // Error saved by GetAndSaveGLError | |
| 96 GLint gl_error_; | |
| 97 | |
| 98 // Aggressive IOSurface eviction logic. When using CoreAnimation, IOSurfaces | |
| 99 // are used only transiently to transfer from the GPU process to the browser | |
| 100 // process. Once the IOSurface has been drawn to its CALayer, the CALayer | |
| 101 // will not need updating again until its view is hidden and re-shown. | |
| 102 // Aggressively evict surfaces when more than 8 (the number allowed by the | |
| 103 // memory manager for fast tab switching) are allocated. | |
| 104 enum { | |
| 105 kMaximumUnevictedSurfaces = 8, | |
| 106 }; | |
| 107 typedef std::list<IOSurfaceTexture*> EvictionQueue; | |
| 108 void EvictionMarkUpdated(); | |
| 109 void EvictionMarkEvicted(); | |
| 110 EvictionQueue::iterator eviction_queue_iterator_; | |
| 111 bool eviction_has_been_drawn_since_updated_; | |
| 112 | |
| 113 static void EvictionScheduleDoEvict(); | |
| 114 static void EvictionDoEvict(); | |
| 115 static base::LazyInstance<EvictionQueue> eviction_queue_; | |
| 116 static bool eviction_scheduled_; | |
| 117 }; | |
| 118 | |
| 119 } // namespace content | |
| 120 | |
| 121 #endif // CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_TEXTURE_MAC_H_ | |
| OLD | NEW |