ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / common / gpu / image_transport_surface_calayer_mac.h
blobd8b8f0440feeed425c4e459bad6710c61ec87b71
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/gl_bindings.h"
12 #include "ui/gl/gpu_switching_observer.h"
13 #include "ui/gl/scoped_cgl.h"
15 @class ImageTransportLayer;
17 namespace content {
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;
27 // ImageTransportSurfaceFBO::StorageProvider implementation:
28 gfx::Size GetRoundedSize(gfx::Size size) override;
29 bool AllocateColorBufferStorage(CGLContextObj context,
30 GLuint texture,
31 gfx::Size pixel_size,
32 float scale_factor) override;
33 void FreeColorBufferStorage() override;
34 void SwapBuffers(const gfx::Size& size, float scale_factor) override;
35 void WillWriteToBackbuffer() override;
36 void DiscardBackbuffer() override;
37 void SwapBuffersAckedByBrowser(bool disable_throttling) override;
39 // Interface to ImageTransportLayer:
40 CGLContextObj LayerShareGroupContext();
41 bool LayerCanDraw();
42 void LayerDoDraw();
43 void LayerResetStorageProvider();
45 // ui::GpuSwitchingObserver implementation.
46 void OnGpuSwitched() override;
48 private:
49 void DrawImmediatelyAndUnblockBrowser();
51 // The browser will be blocked while there is a frame that was sent to it but
52 // hasn't drawn yet. This call will un-block the browser.
53 void UnblockBrowserIfNeeded();
55 ImageTransportSurfaceFBO* transport_surface_;
57 // Used to determine if we should use setNeedsDisplay or setAsynchronous to
58 // animate.
59 const bool gpu_vsync_disabled_;
61 // Used also to determine if we should wait for CoreAnimation to call our
62 // drawInCGLContext, or if we should force it with displayIfNeeded.
63 bool throttling_disabled_;
65 // Set when a new swap occurs, and un-set when |layer_| draws that frame.
66 bool has_pending_draw_;
68 // A counter that is incremented whenever LayerCanDraw returns false. If this
69 // reaches a threshold, then |layer_| is switched to synchronous drawing to
70 // save CPU work.
71 uint32 can_draw_returned_false_count_;
73 // The texture with the pixels to draw, and the share group it is allocated
74 // in.
75 base::ScopedTypeRef<CGLContextObj> share_group_context_;
76 GLuint fbo_texture_;
77 gfx::Size fbo_pixel_size_;
78 float fbo_scale_factor_;
80 // The CALayer that the current frame is being drawn into.
81 base::scoped_nsobject<CAContext> context_;
82 base::scoped_nsobject<ImageTransportLayer> layer_;
84 // When a CAContext is destroyed in the GPU process, it will become a blank
85 // CALayer in the browser process. Put retains on these contexts in this queue
86 // when they are discarded, and remove one item from the queue as each frame
87 // is acked.
88 std::list<base::scoped_nsobject<CAContext> > previously_discarded_contexts_;
90 // Indicates that the CALayer should be recreated at the next swap. This is
91 // to ensure that the CGLContext created for the CALayer be on the right GPU.
92 bool recreate_layer_after_gpu_switch_;
94 // Weak factory against which a timeout task for forcing a draw is created.
95 base::WeakPtrFactory<CALayerStorageProvider> pending_draw_weak_factory_;
97 DISALLOW_COPY_AND_ASSIGN(CALayerStorageProvider);
100 } // namespace content
102 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_