| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_ | |
| 6 #define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_ | |
| 7 | |
| 8 #include "base/mac/scoped_nsobject.h" | |
| 9 #include "content/common/gpu/image_transport_surface_fbo_mac.h" | |
| 10 #include "ui/base/cocoa/remote_layer_api.h" | |
| 11 #include "ui/gl/gpu_switching_observer.h" | |
| 12 #include "ui/gl/scoped_cgl.h" | |
| 13 | |
| 14 @class ImageTransportCAOpenGLLayer; | |
| 15 @class ImageTransportIOSurface; | |
| 16 | |
| 17 namespace content { | |
| 18 | |
| 19 // Allocate CAOpenGLLayer-backed storage for an FBO image transport surface. | |
| 20 class CALayerStorageProvider | |
| 21 : public ImageTransportSurfaceFBO::StorageProvider, | |
| 22 public ui::GpuSwitchingObserver { | |
| 23 public: | |
| 24 CALayerStorageProvider(ImageTransportSurfaceFBO* transport_surface); | |
| 25 ~CALayerStorageProvider() override; | |
| 26 | |
| 27 // ImageTransportSurfaceFBO::StorageProvider implementation: | |
| 28 gfx::Size GetRoundedSize(gfx::Size size) override; | |
| 29 bool AllocateColorBufferStorage( | |
| 30 CGLContextObj context, const base::Closure& context_dirtied_callback, | |
| 31 GLuint texture, gfx::Size pixel_size, float scale_factor) override; | |
| 32 void FreeColorBufferStorage() override; | |
| 33 void FrameSizeChanged( | |
| 34 const gfx::Size& pixel_size, float scale_factor) override; | |
| 35 void SwapBuffers(const gfx::Rect& dirty_rect) override; | |
| 36 void WillWriteToBackbuffer() override; | |
| 37 void DiscardBackbuffer() override; | |
| 38 void SwapBuffersAckedByBrowser(bool disable_throttling) override; | |
| 39 | |
| 40 // Interface to the CALayer. | |
| 41 CGLContextObj LayerShareGroupContext(); | |
| 42 base::Closure LayerShareGroupContextDirtiedCallback(); | |
| 43 bool LayerHasPendingDraw() const; | |
| 44 void LayerDoDraw(const gfx::Rect& dirty_rect, bool flipped); | |
| 45 void LayerUnblockBrowserIfNeeded(); | |
| 46 CAContext* LayerCAContext() { return context_.get(); } | |
| 47 | |
| 48 // ui::GpuSwitchingObserver implementation. | |
| 49 void OnGpuSwitched() override; | |
| 50 | |
| 51 private: | |
| 52 void CreateLayerAndRequestDraw(bool should_draw_immediately, | |
| 53 const gfx::Rect& dirty_rect); | |
| 54 void DrawImmediatelyAndUnblockBrowser(); | |
| 55 | |
| 56 // The browser will be blocked while there is a frame that was sent to it but | |
| 57 // hasn't drawn yet. This call will un-block the browser. | |
| 58 void UnblockBrowserIfNeeded(); | |
| 59 | |
| 60 // Inform the layer that it is no longer being used, and reset the layer. | |
| 61 void ResetLayer(); | |
| 62 | |
| 63 ImageTransportSurfaceFBO* transport_surface_; | |
| 64 | |
| 65 // Used to determine if we should use setNeedsDisplay or setAsynchronous to | |
| 66 // animate. If vsync is disabled, an immediate setNeedsDisplay and | |
| 67 // displayIfNeeded are called. | |
| 68 const bool gpu_vsync_disabled_; | |
| 69 | |
| 70 // Used also to determine if we should wait for CoreAnimation to call our | |
| 71 // drawInCGLContext, or if we should force it with displayIfNeeded. | |
| 72 bool throttling_disabled_; | |
| 73 | |
| 74 // Set when a new swap occurs, and un-set when the frame is acked to the | |
| 75 // browser. This is when the CAOpenGLLayer draws or when then IOSurface | |
| 76 // is committed. | |
| 77 bool has_pending_ack_; | |
| 78 | |
| 79 // The texture with the pixels to draw, and the share group it is allocated | |
| 80 // in. | |
| 81 base::ScopedTypeRef<CGLContextObj> share_group_context_; | |
| 82 base::Closure share_group_context_dirtied_callback_; | |
| 83 GLuint fbo_texture_; | |
| 84 gfx::Size fbo_pixel_size_; | |
| 85 float fbo_scale_factor_; | |
| 86 | |
| 87 // State for the Core Profile code path. | |
| 88 GLuint program_; | |
| 89 GLuint vertex_shader_; | |
| 90 GLuint fragment_shader_; | |
| 91 GLuint position_location_; | |
| 92 GLuint tex_location_; | |
| 93 GLuint vertex_buffer_; | |
| 94 GLuint vertex_array_; | |
| 95 | |
| 96 // The CALayer that the current frame is being drawn into. | |
| 97 base::scoped_nsobject<CAContext> context_; | |
| 98 base::scoped_nsobject<ImageTransportCAOpenGLLayer> ca_opengl_layer_; | |
| 99 | |
| 100 // When a CAContext is destroyed in the GPU process, it will become a blank | |
| 101 // CALayer in the browser process. Put retains on these contexts in this queue | |
| 102 // when they are discarded, and remove one item from the queue as each frame | |
| 103 // is acked. | |
| 104 std::list<base::scoped_nsobject<CAContext>> previously_discarded_contexts_; | |
| 105 | |
| 106 // Indicates that the CALayer should be recreated at the next swap. This is | |
| 107 // to ensure that the CGLContext created for the CALayer be on the right GPU. | |
| 108 bool recreate_layer_after_gpu_switch_; | |
| 109 | |
| 110 // Weak factory against which a timeout task for forcing a draw is created. | |
| 111 base::WeakPtrFactory<CALayerStorageProvider> pending_draw_weak_factory_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(CALayerStorageProvider); | |
| 114 }; | |
| 115 | |
| 116 } // namespace content | |
| 117 | |
| 118 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_ | |
| OLD | NEW |