boliu@chromium.org | 2306376 | 2014-02-26 01:01:56 | [diff] [blame] | 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 ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ |
| 6 | #define ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ |
| 7 | |
dcheng | 08daa07 | 2016-04-01 01:47:21 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
boliu | d6a2655c | 2016-11-09 17:45:23 | [diff] [blame] | 10 | #include "android_webview/browser/child_frame.h" |
hush | 284add6 | 2016-06-17 20:47:33 | [diff] [blame] | 11 | #include "android_webview/browser/compositor_id.h" |
avi | de7d5c2 | 2015-12-20 05:48:44 | [diff] [blame] | 12 | #include "base/macros.h" |
boliu | 8b58fe5 | 2016-06-29 17:48:13 | [diff] [blame] | 13 | #include "base/memory/ref_counted.h" |
samans | 89cf97b | 2017-03-02 22:30:11 | [diff] [blame] | 14 | #include "cc/surfaces/compositor_frame_sink_support_client.h" |
fsamuel | b6acafa | 2016-10-04 03:21:52 | [diff] [blame] | 15 | #include "cc/surfaces/frame_sink_id.h" |
jbauman | a783bb0 | 2015-06-05 00:57:35 | [diff] [blame] | 16 | #include "cc/surfaces/surface_id.h" |
boliu@chromium.org | 2306376 | 2014-02-26 01:01:56 | [diff] [blame] | 17 | |
| 18 | struct AwDrawGLInfo; |
| 19 | |
boliu@chromium.org | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 20 | namespace cc { |
samans | 89cf97b | 2017-03-02 22:30:11 | [diff] [blame] | 21 | class CompositorFrameSinkSupport; |
xing.xu | 1a9aa94c | 2017-02-23 21:04:32 | [diff] [blame] | 22 | class LocalSurfaceIdAllocator; |
boliu@chromium.org | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 23 | } |
| 24 | |
boliu@chromium.org | 2306376 | 2014-02-26 01:01:56 | [diff] [blame] | 25 | namespace android_webview { |
| 26 | |
boliu | b887d327 | 2015-03-19 00:29:26 | [diff] [blame] | 27 | class ChildFrame; |
boliu | 8b58fe5 | 2016-06-29 17:48:13 | [diff] [blame] | 28 | class RenderThreadManager; |
boliu | 8b58fe5 | 2016-06-29 17:48:13 | [diff] [blame] | 29 | class SurfacesInstance; |
boliu@chromium.org | 2306376 | 2014-02-26 01:01:56 | [diff] [blame] | 30 | |
samans | 89cf97b | 2017-03-02 22:30:11 | [diff] [blame] | 31 | class HardwareRenderer : public cc::CompositorFrameSinkSupportClient { |
boliu@chromium.org | 2306376 | 2014-02-26 01:01:56 | [diff] [blame] | 32 | public: |
boliu | d6a2655c | 2016-11-09 17:45:23 | [diff] [blame] | 33 | // Two rules: |
| 34 | // 1) Never wait on |new_frame| on the UI thread, or in kModeSync. Otherwise |
| 35 | // this defeats the purpose of having a future. |
| 36 | // 2) Never replace a non-empty frames with an empty frame. |
| 37 | // The only way to do both is to hold up to two frames here. This is a helper |
| 38 | // method to do this. General pattern is call this method to prune existing |
| 39 | // queue, and then append the new frame. Wait on all frames in queue. Then |
| 40 | // remove all except the latest non-empty frame. If all frames are empty, |
| 41 | // then the deque is cleared. Return any non-empty frames that are pruned. |
| 42 | // Return value does not guarantee relative order is maintained. |
| 43 | static ChildFrameQueue WaitAndPruneFrameQueue(ChildFrameQueue* child_frames); |
| 44 | |
tobiasjs | 1c63c2f | 2016-04-05 11:30:03 | [diff] [blame] | 45 | explicit HardwareRenderer(RenderThreadManager* state); |
dcheng | 996c125c | 2015-02-04 02:25:49 | [diff] [blame] | 46 | ~HardwareRenderer() override; |
boliu@chromium.org | 2306376 | 2014-02-26 01:01:56 | [diff] [blame] | 47 | |
boliu | cf47317 | 2016-09-26 17:07:32 | [diff] [blame] | 48 | void DrawGL(AwDrawGLInfo* draw_info); |
boliu@chromium.org | 33e9e431 | 2014-07-25 22:30:21 | [diff] [blame] | 49 | void CommitFrame(); |
boliu@chromium.org | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 50 | |
boliu@chromium.org | 2306376 | 2014-02-26 01:01:56 | [diff] [blame] | 51 | private: |
samans | 89cf97b | 2017-03-02 22:30:11 | [diff] [blame] | 52 | // cc::CompositorFrameSinkSupportClient implementation. |
samans | 8d3604f | 2017-04-11 22:15:30 | [diff] [blame] | 53 | void DidReceiveCompositorFrameAck( |
| 54 | const cc::ReturnedResourceArray& resources) override; |
samans | 89cf97b | 2017-03-02 22:30:11 | [diff] [blame] | 55 | void OnBeginFrame(const cc::BeginFrameArgs& args) override; |
| 56 | void ReclaimResources(const cc::ReturnedResourceArray& resources) override; |
| 57 | void WillDrawSurface(const cc::LocalSurfaceId& local_surface_id, |
| 58 | const gfx::Rect& damage_rect) override; |
jbauman | a783bb0 | 2015-06-05 00:57:35 | [diff] [blame] | 59 | |
boliu | d6a2655c | 2016-11-09 17:45:23 | [diff] [blame] | 60 | void ReturnChildFrame(std::unique_ptr<ChildFrame> child_frame); |
hush | 45918a8 | 2015-12-17 03:50:59 | [diff] [blame] | 61 | void ReturnResourcesToCompositor(const cc::ReturnedResourceArray& resources, |
hush | 284add6 | 2016-06-17 20:47:33 | [diff] [blame] | 62 | const CompositorID& compositor_id, |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 63 | uint32_t layer_tree_frame_sink_id); |
hush | 198d352 | 2015-10-01 00:42:10 | [diff] [blame] | 64 | |
boliu | 8b58fe5 | 2016-06-29 17:48:13 | [diff] [blame] | 65 | void AllocateSurface(); |
| 66 | void DestroySurface(); |
| 67 | |
samans | 89cf97b | 2017-03-02 22:30:11 | [diff] [blame] | 68 | void CreateNewCompositorFrameSinkSupport(); |
| 69 | |
tobiasjs | 1c63c2f | 2016-04-05 11:30:03 | [diff] [blame] | 70 | RenderThreadManager* render_thread_manager_; |
boliu@chromium.org | 2306376 | 2014-02-26 01:01:56 | [diff] [blame] | 71 | |
| 72 | typedef void* EGLContext; |
| 73 | EGLContext last_egl_context_; |
| 74 | |
boliu@chromium.org | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 75 | // Information about last delegated frame. |
samans | cf887b6f | 2017-05-24 18:14:29 | [diff] [blame] | 76 | gfx::Size surface_size_; |
| 77 | float device_scale_factor_ = 0; |
boliu | 6439a53 | 2014-10-07 06:00:01 | [diff] [blame] | 78 | |
| 79 | // Infromation from UI on last commit. |
boliu@chromium.org | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 80 | gfx::Vector2d scroll_offset_; |
| 81 | |
boliu | 299d4c38 | 2016-11-12 00:16:44 | [diff] [blame] | 82 | ChildFrameQueue child_frame_queue_; |
| 83 | |
boliu | 6486a48 | 2015-10-16 01:46:18 | [diff] [blame] | 84 | // This holds the last ChildFrame received. Contains the frame info of the |
boliu | 299d4c38 | 2016-11-12 00:16:44 | [diff] [blame] | 85 | // last frame. The |frame| member is always null since frame has already |
| 86 | // been submitted. |
| 87 | std::unique_ptr<ChildFrame> child_frame_; |
boliu | b887d327 | 2015-03-19 00:29:26 | [diff] [blame] | 88 | |
boliu | 8b58fe5 | 2016-06-29 17:48:13 | [diff] [blame] | 89 | const scoped_refptr<SurfacesInstance> surfaces_; |
fsamuel | b6acafa | 2016-10-04 03:21:52 | [diff] [blame] | 90 | cc::FrameSinkId frame_sink_id_; |
xing.xu | 1a9aa94c | 2017-02-23 21:04:32 | [diff] [blame] | 91 | const std::unique_ptr<cc::LocalSurfaceIdAllocator> |
| 92 | local_surface_id_allocator_; |
samans | 89cf97b | 2017-03-02 22:30:11 | [diff] [blame] | 93 | std::unique_ptr<cc::CompositorFrameSinkSupport> support_; |
samans | 5258bfb | 2017-01-27 21:16:26 | [diff] [blame] | 94 | cc::LocalSurfaceId child_id_; |
hush | 284add6 | 2016-06-17 20:47:33 | [diff] [blame] | 95 | CompositorID compositor_id_; |
boliu | f4e57485 | 2016-03-22 19:33:17 | [diff] [blame] | 96 | // HardwareRenderer guarantees resources are returned in the order of |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 97 | // layer_tree_frame_sink_id, and resources for old output surfaces are |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 98 | // dropped. |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 99 | uint32_t last_committed_layer_tree_frame_sink_id_; |
| 100 | uint32_t last_submitted_layer_tree_frame_sink_id_; |
boliu@chromium.org | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 101 | |
boliu@chromium.org | 2306376 | 2014-02-26 01:01:56 | [diff] [blame] | 102 | DISALLOW_COPY_AND_ASSIGN(HardwareRenderer); |
| 103 | }; |
| 104 | |
boliu@chromium.org | 2306376 | 2014-02-26 01:01:56 | [diff] [blame] | 105 | } // namespace android_webview |
| 106 | |
| 107 | #endif // ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ |