Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / common / gpu / image_transport_surface_calayer_mac.h
blob43cd2afb4f133ecaf65cf21d1daed6fa2a77d156
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.
5 #ifndef CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_
6 #define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_
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"
14 @class ImageTransportLayer;
16 namespace content {
18 // Allocate CAOpenGLLayer-backed storage for an FBO image transport surface.
19 class CALayerStorageProvider
20 : public ImageTransportSurfaceFBO::StorageProvider,
21 public ui::GpuSwitchingObserver {
22 public:
23 CALayerStorageProvider(ImageTransportSurfaceFBO* transport_surface);
24 ~CALayerStorageProvider() override;
26 // ImageTransportSurfaceFBO::StorageProvider implementation:
27 gfx::Size GetRoundedSize(gfx::Size size) override;
28 bool AllocateColorBufferStorage(
29 CGLContextObj context, const base::Closure& context_dirtied_callback,
30 GLuint texture, gfx::Size pixel_size, float scale_factor) override;
31 void FreeColorBufferStorage() override;
32 void FrameSizeChanged(
33 const gfx::Size& pixel_size, float scale_factor) override;
34 void SwapBuffers() override;
35 void WillWriteToBackbuffer() override;
36 void DiscardBackbuffer() override;
37 void SwapBuffersAckedByBrowser(bool disable_throttling) override;
39 // Interface to ImageTransportLayer:
40 CGLContextObj LayerShareGroupContext();
41 base::Closure LayerShareGroupContextDirtiedCallback();
42 bool LayerCanDraw();
43 void LayerDoDraw();
44 void LayerResetStorageProvider();
46 // ui::GpuSwitchingObserver implementation.
47 void OnGpuSwitched() override;
49 private:
50 void DrawImmediatelyAndUnblockBrowser();
52 // The browser will be blocked while there is a frame that was sent to it but
53 // hasn't drawn yet. This call will un-block the browser.
54 void UnblockBrowserIfNeeded();
56 ImageTransportSurfaceFBO* transport_surface_;
58 // Used to determine if we should use setNeedsDisplay or setAsynchronous to
59 // animate. If the last swap time happened very recently, then
60 // setAsynchronous is used (which allows smooth animation, but comes with the
61 // penalty of the canDrawInCGLContext function waking up the process every
62 // vsync).
63 base::TimeTicks last_synchronous_swap_time_;
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_;
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_;
74 // Set when a new swap occurs, and un-set when |layer_| draws that frame.
75 bool has_pending_draw_;
77 // A counter that is incremented whenever LayerCanDraw returns false. If this
78 // reaches a threshold, then |layer_| is switched to synchronous drawing to
79 // save CPU work.
80 uint32 can_draw_returned_false_count_;
82 // The texture with the pixels to draw, and the share group it is allocated
83 // in.
84 base::ScopedTypeRef<CGLContextObj> share_group_context_;
85 base::Closure share_group_context_dirtied_callback_;
86 GLuint fbo_texture_;
87 gfx::Size fbo_pixel_size_;
88 float fbo_scale_factor_;
90 // State for the Core Profile code path.
91 GLuint program_;
92 GLuint vertex_shader_;
93 GLuint fragment_shader_;
94 GLuint position_location_;
95 GLuint tex_location_;
96 GLuint vertex_buffer_;
97 GLuint vertex_array_;
99 // The CALayer that the current frame is being drawn into.
100 base::scoped_nsobject<CAContext> context_;
101 base::scoped_nsobject<ImageTransportLayer> layer_;
103 // When a CAContext is destroyed in the GPU process, it will become a blank
104 // CALayer in the browser process. Put retains on these contexts in this queue
105 // when they are discarded, and remove one item from the queue as each frame
106 // is acked.
107 std::list<base::scoped_nsobject<CAContext> > previously_discarded_contexts_;
109 // Indicates that the CALayer should be recreated at the next swap. This is
110 // to ensure that the CGLContext created for the CALayer be on the right GPU.
111 bool recreate_layer_after_gpu_switch_;
113 // Weak factory against which a timeout task for forcing a draw is created.
114 base::WeakPtrFactory<CALayerStorageProvider> pending_draw_weak_factory_;
116 DISALLOW_COPY_AND_ASSIGN(CALayerStorageProvider);
119 } // namespace content
121 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_