| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LAYER_MAC_H_ | 5 #ifndef UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_LAYER_H_ |
| 6 #define CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_LAYER_MAC_H_ | 6 #define UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_LAYER_H_ |
| 7 | 7 |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "ui/gfx/size.h" | 13 #include "ui/gfx/geometry/size.h" |
| 14 | 14 |
| 15 @class IOSurfaceLayer; | 15 @class IOSurfaceLayer; |
| 16 | 16 |
| 17 namespace content { | 17 namespace ui { |
| 18 |
| 18 class IOSurfaceTexture; | 19 class IOSurfaceTexture; |
| 19 class IOSurfaceContext; | 20 class IOSurfaceContext; |
| 20 | 21 |
| 21 // The interface through which the IOSurfaceLayer calls back into | 22 // The interface through which the IOSurfaceLayer calls back into |
| 22 // the structrue that created it (RenderWidgetHostViewMac or | 23 // the structrue that created it (RenderWidgetHostViewMac or |
| 23 // BrowserCompositorViewMac). | 24 // BrowserCompositorViewMac). |
| 24 class IOSurfaceLayerClient { | 25 class IOSurfaceLayerClient { |
| 25 public: | 26 public: |
| 26 // Used to indicate that the layer should attempt to draw immediately and | 27 // Used to indicate that the layer should attempt to draw immediately and |
| 27 // should (even if the draw is elided by the system), ack the frame | 28 // should (even if the draw is elided by the system), ack the frame |
| 28 // immediately. | 29 // immediately. |
| 29 virtual bool IOSurfaceLayerShouldAckImmediately() const = 0; | 30 virtual bool IOSurfaceLayerShouldAckImmediately() const = 0; |
| 30 | 31 |
| 31 // Called when a frame is drawn or when, because the layer is not visible, it | 32 // Called when a frame is drawn or when, because the layer is not visible, it |
| 32 // is known that the frame will never drawn. | 33 // is known that the frame will never drawn. |
| 33 virtual void IOSurfaceLayerDidDrawFrame() = 0; | 34 virtual void IOSurfaceLayerDidDrawFrame() = 0; |
| 34 | 35 |
| 35 // Called when an error prevents the frame from being drawn. | 36 // Called when an error prevents the frame from being drawn. |
| 36 virtual void IOSurfaceLayerHitError() = 0; | 37 virtual void IOSurfaceLayerHitError() = 0; |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 // IOSurfaceLayerHelper provides C++ functionality needed for the | 40 // IOSurfaceLayerHelper provides C++ functionality needed for the |
| 40 // IOSurfaceLayer class, and does most of the heavy lifting for the | 41 // IOSurfaceLayer class, and does most of the heavy lifting for the |
| 41 // class. | 42 // class. |
| 42 // TODO(ccameron): This class should own IOSurfaceLayer, rather than | 43 // TODO(ccameron): This class should own IOSurfaceLayer, rather than |
| 43 // vice versa. | 44 // vice versa. |
| 44 class IOSurfaceLayerHelper { | 45 class IOSurfaceLayerHelper { |
| 45 public: | 46 public: |
| 46 IOSurfaceLayerHelper(IOSurfaceLayerClient* client, | 47 IOSurfaceLayerHelper(IOSurfaceLayerClient* client, |
| 47 IOSurfaceLayer* layer); | 48 IOSurfaceLayer* layer); |
| 48 ~IOSurfaceLayerHelper(); | 49 ~IOSurfaceLayerHelper(); |
| 49 | 50 |
| 50 // Called when the IOSurfaceLayer gets a new frame. | 51 // Called when the IOSurfaceLayer gets a new frame. |
| 51 void GotNewFrame(); | 52 void GotNewFrame(); |
| 52 | 53 |
| 53 // Called whenever -[IOSurfaceLayer setNeedsDisplay] is called. | 54 // Called whenever -[IOSurfaceLayer setNeedsDisplay] is called. |
| 54 void SetNeedsDisplay(); | 55 void SetNeedsDisplay(); |
| 55 | 56 |
| 56 // Called whenever -[IOSurfaceLayer canDrawInCGLContext] is called, | 57 // Called whenever -[IOSurfaceLayer canDrawInCGLContext] is called, |
| 57 // to determine if a new frame should be drawn. | 58 // to determine if a new frame should be drawn. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 // Called whenever the frame provided in GotNewFrame should be acknowledged | 80 // Called whenever the frame provided in GotNewFrame should be acknowledged |
| 80 // (this may be because it was drawn, or it may be to unblock the | 81 // (this may be because it was drawn, or it may be to unblock the |
| 81 // compositor). | 82 // compositor). |
| 82 void AckPendingFrame(bool success); | 83 void AckPendingFrame(bool success); |
| 83 | 84 |
| 84 void TimerFired(); | 85 void TimerFired(); |
| 85 | 86 |
| 86 // The client that the owning layer was created with. | 87 // The client that the owning layer was created with. |
| 87 content::IOSurfaceLayerClient* const client_; | 88 IOSurfaceLayerClient* const client_; |
| 88 | 89 |
| 89 // The layer that owns this helper. | 90 // The layer that owns this helper. |
| 90 IOSurfaceLayer* const layer_; | 91 IOSurfaceLayer* const layer_; |
| 91 | 92 |
| 92 // Used to track when canDrawInCGLContext should return YES. This can be | 93 // Used to track when canDrawInCGLContext should return YES. This can be |
| 93 // in response to receiving a new compositor frame, or from any of the events | 94 // in response to receiving a new compositor frame, or from any of the events |
| 94 // that cause setNeedsDisplay to be called on the layer. | 95 // that cause setNeedsDisplay to be called on the layer. |
| 95 bool needs_display_; | 96 bool needs_display_; |
| 96 | 97 |
| 97 // This is set when a frame is received, and un-set when the frame is drawn. | 98 // This is set when a frame is received, and un-set when the frame is drawn. |
| 98 bool has_pending_frame_; | 99 bool has_pending_frame_; |
| 99 | 100 |
| 100 // Incremented every time that this layer is asked to draw but does not have | 101 // Incremented every time that this layer is asked to draw but does not have |
| 101 // new content to draw. | 102 // new content to draw. |
| 102 uint64 did_not_draw_counter_; | 103 uint64 did_not_draw_counter_; |
| 103 | 104 |
| 104 // Set when inside a BeginPumpingFrames/EndPumpingFrames block. | 105 // Set when inside a BeginPumpingFrames/EndPumpingFrames block. |
| 105 bool is_pumping_frames_; | 106 bool is_pumping_frames_; |
| 106 | 107 |
| 107 // The browser places back-pressure on the GPU by not acknowledging swap | 108 // The browser places back-pressure on the GPU by not acknowledging swap |
| 108 // calls until they appear on the screen. This can lead to hangs if the | 109 // calls until they appear on the screen. This can lead to hangs if the |
| 109 // view is moved offscreen (among other things). Prevent hangs by always | 110 // view is moved offscreen (among other things). Prevent hangs by always |
| 110 // acknowledging the frame after timeout of 1/6th of a second has passed. | 111 // acknowledging the frame after timeout of 1/6th of a second has passed. |
| 111 base::DelayTimer<IOSurfaceLayerHelper> timer_; | 112 base::DelayTimer<IOSurfaceLayerHelper> timer_; |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 } // namespace content | 115 } // namespace ui |
| 115 | 116 |
| 116 // The CoreAnimation layer for drawing accelerated content. | 117 // The CoreAnimation layer for drawing accelerated content. |
| 117 @interface IOSurfaceLayer : CAOpenGLLayer { | 118 @interface IOSurfaceLayer : CAOpenGLLayer { |
| 118 @private | 119 @private |
| 119 scoped_refptr<content::IOSurfaceTexture> iosurface_; | 120 scoped_refptr<ui::IOSurfaceTexture> iosurface_; |
| 120 scoped_refptr<content::IOSurfaceContext> context_; | 121 scoped_refptr<ui::IOSurfaceContext> context_; |
| 121 | 122 |
| 122 scoped_ptr<content::IOSurfaceLayerHelper> helper_; | 123 scoped_ptr<ui::IOSurfaceLayerHelper> helper_; |
| 123 } | 124 } |
| 124 | 125 |
| 125 - (id)initWithClient:(content::IOSurfaceLayerClient*)client | 126 - (id)initWithClient:(ui::IOSurfaceLayerClient*)client |
| 126 withScaleFactor:(float)scale_factor; | 127 withScaleFactor:(float)scale_factor |
| 128 needsGLFinishWorkaround:(bool)needs_gl_finish_workaround; |
| 127 | 129 |
| 128 - (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id | 130 - (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id |
| 129 withPixelSize:(gfx::Size)pixel_size | 131 withPixelSize:(gfx::Size)pixel_size |
| 130 withScaleFactor:(float)scale_factor; | 132 withScaleFactor:(float)scale_factor; |
| 131 | 133 |
| 132 // Context poison accessors. | 134 // Context poison accessors. |
| 133 - (void)poisonContextAndSharegroup; | 135 - (void)poisonContextAndSharegroup; |
| 134 - (bool)hasBeenPoisoned; | 136 - (bool)hasBeenPoisoned; |
| 135 | 137 |
| 136 - (float)scaleFactor; | 138 - (float)scaleFactor; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 151 | 153 |
| 152 // Force a draw immediately, but only if one was requested. | 154 // Force a draw immediately, but only if one was requested. |
| 153 - (void)displayIfNeededAndAck; | 155 - (void)displayIfNeededAndAck; |
| 154 | 156 |
| 155 // Mark a bracket in which new frames are being pumped in a restricted nested | 157 // Mark a bracket in which new frames are being pumped in a restricted nested |
| 156 // run loop. | 158 // run loop. |
| 157 - (void)beginPumpingFrames; | 159 - (void)beginPumpingFrames; |
| 158 - (void)endPumpingFrames; | 160 - (void)endPumpingFrames; |
| 159 @end | 161 @end |
| 160 | 162 |
| 161 #endif // CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_LAYER_MAC_H_ | 163 #endif // UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_LAYER_H_ |
| OLD | NEW |