[go: nahoru, domu]

blob: a6836bff329c0cb6a0ed05b11c76fbd0c957fab6 [file] [log] [blame]
boliu@chromium.org23063762014-02-26 01:01:561// 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
dcheng08daa072016-04-01 01:47:218#include <memory>
9
boliud6a2655c2016-11-09 17:45:2310#include "android_webview/browser/child_frame.h"
hush284add62016-06-17 20:47:3311#include "android_webview/browser/compositor_id.h"
avide7d5c22015-12-20 05:48:4412#include "base/macros.h"
boliu8b58fe52016-06-29 17:48:1313#include "base/memory/ref_counted.h"
samans89cf97b2017-03-02 22:30:1114#include "cc/surfaces/compositor_frame_sink_support_client.h"
fsamuelb6acafa2016-10-04 03:21:5215#include "cc/surfaces/frame_sink_id.h"
jbaumana783bb02015-06-05 00:57:3516#include "cc/surfaces/surface_id.h"
boliu@chromium.org23063762014-02-26 01:01:5617
18struct AwDrawGLInfo;
19
boliu@chromium.org8705654b2014-05-24 01:16:1920namespace cc {
samans89cf97b2017-03-02 22:30:1121class CompositorFrameSinkSupport;
xing.xu1a9aa94c2017-02-23 21:04:3222class LocalSurfaceIdAllocator;
boliu@chromium.org8705654b2014-05-24 01:16:1923}
24
boliu@chromium.org23063762014-02-26 01:01:5625namespace android_webview {
26
boliub887d3272015-03-19 00:29:2627class ChildFrame;
boliu8b58fe52016-06-29 17:48:1328class RenderThreadManager;
boliu8b58fe52016-06-29 17:48:1329class SurfacesInstance;
boliu@chromium.org23063762014-02-26 01:01:5630
samans89cf97b2017-03-02 22:30:1131class HardwareRenderer : public cc::CompositorFrameSinkSupportClient {
boliu@chromium.org23063762014-02-26 01:01:5632 public:
boliud6a2655c2016-11-09 17:45:2333 // 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
tobiasjs1c63c2f2016-04-05 11:30:0345 explicit HardwareRenderer(RenderThreadManager* state);
dcheng996c125c2015-02-04 02:25:4946 ~HardwareRenderer() override;
boliu@chromium.org23063762014-02-26 01:01:5647
boliucf473172016-09-26 17:07:3248 void DrawGL(AwDrawGLInfo* draw_info);
boliu@chromium.org33e9e4312014-07-25 22:30:2149 void CommitFrame();
boliu@chromium.org8705654b2014-05-24 01:16:1950
boliu@chromium.org23063762014-02-26 01:01:5651 private:
samans89cf97b2017-03-02 22:30:1152 // cc::CompositorFrameSinkSupportClient implementation.
samans8d3604f2017-04-11 22:15:3053 void DidReceiveCompositorFrameAck(
54 const cc::ReturnedResourceArray& resources) override;
samans89cf97b2017-03-02 22:30:1155 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;
jbaumana783bb02015-06-05 00:57:3559
boliud6a2655c2016-11-09 17:45:2360 void ReturnChildFrame(std::unique_ptr<ChildFrame> child_frame);
hush45918a82015-12-17 03:50:5961 void ReturnResourcesToCompositor(const cc::ReturnedResourceArray& resources,
hush284add62016-06-17 20:47:3362 const CompositorID& compositor_id,
danakjc7afae52017-06-20 21:12:4163 uint32_t layer_tree_frame_sink_id);
hush198d3522015-10-01 00:42:1064
boliu8b58fe52016-06-29 17:48:1365 void AllocateSurface();
66 void DestroySurface();
67
samans89cf97b2017-03-02 22:30:1168 void CreateNewCompositorFrameSinkSupport();
69
tobiasjs1c63c2f2016-04-05 11:30:0370 RenderThreadManager* render_thread_manager_;
boliu@chromium.org23063762014-02-26 01:01:5671
72 typedef void* EGLContext;
73 EGLContext last_egl_context_;
74
boliu@chromium.org8705654b2014-05-24 01:16:1975 // Information about last delegated frame.
samanscf887b6f2017-05-24 18:14:2976 gfx::Size surface_size_;
77 float device_scale_factor_ = 0;
boliu6439a532014-10-07 06:00:0178
79 // Infromation from UI on last commit.
boliu@chromium.org8705654b2014-05-24 01:16:1980 gfx::Vector2d scroll_offset_;
81
boliu299d4c382016-11-12 00:16:4482 ChildFrameQueue child_frame_queue_;
83
boliu6486a482015-10-16 01:46:1884 // This holds the last ChildFrame received. Contains the frame info of the
boliu299d4c382016-11-12 00:16:4485 // last frame. The |frame| member is always null since frame has already
86 // been submitted.
87 std::unique_ptr<ChildFrame> child_frame_;
boliub887d3272015-03-19 00:29:2688
boliu8b58fe52016-06-29 17:48:1389 const scoped_refptr<SurfacesInstance> surfaces_;
fsamuelb6acafa2016-10-04 03:21:5290 cc::FrameSinkId frame_sink_id_;
xing.xu1a9aa94c2017-02-23 21:04:3291 const std::unique_ptr<cc::LocalSurfaceIdAllocator>
92 local_surface_id_allocator_;
samans89cf97b2017-03-02 22:30:1193 std::unique_ptr<cc::CompositorFrameSinkSupport> support_;
samans5258bfb2017-01-27 21:16:2694 cc::LocalSurfaceId child_id_;
hush284add62016-06-17 20:47:3395 CompositorID compositor_id_;
boliuf4e574852016-03-22 19:33:1796 // HardwareRenderer guarantees resources are returned in the order of
danakjc7afae52017-06-20 21:12:4197 // layer_tree_frame_sink_id, and resources for old output surfaces are
danakj1120f4c2016-09-15 02:05:3298 // dropped.
danakjc7afae52017-06-20 21:12:4199 uint32_t last_committed_layer_tree_frame_sink_id_;
100 uint32_t last_submitted_layer_tree_frame_sink_id_;
boliu@chromium.org8705654b2014-05-24 01:16:19101
boliu@chromium.org23063762014-02-26 01:01:56102 DISALLOW_COPY_AND_ASSIGN(HardwareRenderer);
103};
104
boliu@chromium.org23063762014-02-26 01:01:56105} // namespace android_webview
106
107#endif // ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_