Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: android_webview/browser/hardware_renderer.cc

Issue 2347563003: Added FrameFuture class (Closed)
Patch Set: Code review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/browser/hardware_renderer.h" 5 #include "android_webview/browser/hardware_renderer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "android_webview/browser/aw_gl_surface.h" 9 #include "android_webview/browser/aw_gl_surface.h"
10 #include "android_webview/browser/aw_render_thread_context_provider.h" 10 #include "android_webview/browser/aw_render_thread_context_provider.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 57
58 void HardwareRenderer::CommitFrame() { 58 void HardwareRenderer::CommitFrame() {
59 TRACE_EVENT0("android_webview", "CommitFrame"); 59 TRACE_EVENT0("android_webview", "CommitFrame");
60 scroll_offset_ = render_thread_manager_->GetScrollOffsetOnRT(); 60 scroll_offset_ = render_thread_manager_->GetScrollOffsetOnRT();
61 std::unique_ptr<ChildFrame> child_frame = 61 std::unique_ptr<ChildFrame> child_frame =
62 render_thread_manager_->PassFrameOnRT(); 62 render_thread_manager_->PassFrameOnRT();
63 if (!child_frame.get()) 63 if (!child_frame.get())
64 return; 64 return;
65 65
66 last_committed_compositor_frame_sink_id_ = 66 // Wait for frame, then extract CompositorFrame and
boliu 2016/09/20 00:27:56 I think HardwareRenderer do not need to be aware o
ojars 2016/09/22 18:21:38 Done.
67 child_frame->compositor_frame_sink_id; 67 // compositor_frame_sink_id_.
68 child_frame->frame_future->Wait();
69 frame_ = std::move(child_frame->frame_future->getFrame()->frame);
70 compositor_frame_sink_id_ =
71 child_frame->frame_future->getFrame()->compositor_frame_sink_id;
72
73 last_committed_compositor_frame_sink_id_ = compositor_frame_sink_id_;
68 ReturnResourcesInChildFrame(); 74 ReturnResourcesInChildFrame();
69 child_frame_ = std::move(child_frame); 75 child_frame_ = std::move(child_frame);
70 DCHECK(child_frame_->frame.get()); 76 DCHECK(frame_.get());
71 DCHECK(!child_frame_->frame->gl_frame_data); 77 DCHECK(!frame_->gl_frame_data);
72 } 78 }
73 79
74 void HardwareRenderer::DrawGL(AwDrawGLInfo* draw_info, 80 void HardwareRenderer::DrawGL(AwDrawGLInfo* draw_info,
75 const ScopedAppGLStateRestore& gl_state) { 81 const ScopedAppGLStateRestore& gl_state) {
76 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); 82 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL");
77 83
78 // We need to watch if the current Android context has changed and enforce 84 // We need to watch if the current Android context has changed and enforce
79 // a clean-up in the compositor. 85 // a clean-up in the compositor.
80 EGLContext current_context = eglGetCurrentContext(); 86 EGLContext current_context = eglGetCurrentContext();
81 DCHECK(current_context) << "DrawGL called without EGLContext"; 87 DCHECK(current_context) << "DrawGL called without EGLContext";
82 88
83 // TODO(boliu): Handle context loss. 89 // TODO(boliu): Handle context loss.
84 if (last_egl_context_ != current_context) 90 if (last_egl_context_ != current_context)
85 DLOG(WARNING) << "EGLContextChanged"; 91 DLOG(WARNING) << "EGLContextChanged";
86 92
87 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it 93 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it
88 // during "kModeSync" stage (which does not allow GL) might result in extra 94 // during "kModeSync" stage (which does not allow GL) might result in extra
89 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid 95 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid
90 // unnecessary kModeProcess. 96 // unnecessary kModeProcess.
91 if (child_frame_.get() && child_frame_->frame.get()) { 97 if (child_frame_.get() && frame_.get()) {
92 if (!compositor_id_.Equals(child_frame_->compositor_id) || 98 if (!compositor_id_.Equals(child_frame_->compositor_id) ||
93 last_submitted_compositor_frame_sink_id_ != 99 last_submitted_compositor_frame_sink_id_ != compositor_frame_sink_id_) {
94 child_frame_->compositor_frame_sink_id) {
95 if (!child_id_.is_null()) 100 if (!child_id_.is_null())
96 DestroySurface(); 101 DestroySurface();
97 102
98 // This will return all the resources to the previous compositor. 103 // This will return all the resources to the previous compositor.
99 surface_factory_.reset(); 104 surface_factory_.reset();
100 compositor_id_ = child_frame_->compositor_id; 105 compositor_id_ = child_frame_->compositor_id;
101 last_submitted_compositor_frame_sink_id_ = 106 last_submitted_compositor_frame_sink_id_ = compositor_frame_sink_id_;
102 child_frame_->compositor_frame_sink_id;
103 surface_factory_.reset( 107 surface_factory_.reset(
104 new cc::SurfaceFactory(surfaces_->GetSurfaceManager(), this)); 108 new cc::SurfaceFactory(surfaces_->GetSurfaceManager(), this));
105 } 109 }
106 110
107 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = 111 std::unique_ptr<cc::CompositorFrame> child_compositor_frame =
108 std::move(child_frame_->frame); 112 std::move(frame_);
109 113
110 gfx::Size frame_size = 114 gfx::Size frame_size =
111 child_compositor_frame->delegated_frame_data->render_pass_list.back() 115 child_compositor_frame->delegated_frame_data->render_pass_list.back()
112 ->output_rect.size(); 116 ->output_rect.size();
113 bool size_changed = frame_size != frame_size_; 117 bool size_changed = frame_size != frame_size_;
114 frame_size_ = frame_size; 118 frame_size_ = frame_size;
115 if (child_id_.is_null() || size_changed) { 119 if (child_id_.is_null() || size_changed) {
116 if (!child_id_.is_null()) 120 if (!child_id_.is_null())
117 DestroySurface(); 121 DestroySurface();
118 AllocateSurface(); 122 AllocateSurface();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 cc::BeginFrameSource* begin_frame_source) { 178 cc::BeginFrameSource* begin_frame_source) {
175 // TODO(tansell): Hook this up. 179 // TODO(tansell): Hook this up.
176 } 180 }
177 181
178 void HardwareRenderer::SetBackingFrameBufferObject( 182 void HardwareRenderer::SetBackingFrameBufferObject(
179 int framebuffer_binding_ext) { 183 int framebuffer_binding_ext) {
180 surfaces_->SetBackingFrameBufferObject(framebuffer_binding_ext); 184 surfaces_->SetBackingFrameBufferObject(framebuffer_binding_ext);
181 } 185 }
182 186
183 void HardwareRenderer::ReturnResourcesInChildFrame() { 187 void HardwareRenderer::ReturnResourcesInChildFrame() {
184 if (child_frame_.get() && child_frame_->frame.get()) { 188 if (child_frame_.get() && frame_.get()) {
185 cc::ReturnedResourceArray resources_to_return; 189 cc::ReturnedResourceArray resources_to_return;
186 cc::TransferableResource::ReturnResources( 190 cc::TransferableResource::ReturnResources(
187 child_frame_->frame->delegated_frame_data->resource_list, 191 frame_->delegated_frame_data->resource_list, &resources_to_return);
188 &resources_to_return);
189 192
190 // The child frame's compositor id is not necessarily same as 193 // The child frame's compositor id is not necessarily same as
191 // compositor_id_. 194 // compositor_id_.
192 ReturnResourcesToCompositor(resources_to_return, 195 ReturnResourcesToCompositor(resources_to_return,
193 child_frame_->compositor_id, 196 child_frame_->compositor_id,
194 child_frame_->compositor_frame_sink_id); 197 compositor_frame_sink_id_);
195 } 198 }
196 child_frame_.reset(); 199 child_frame_.reset();
197 } 200 }
198 201
199 void HardwareRenderer::ReturnResourcesToCompositor( 202 void HardwareRenderer::ReturnResourcesToCompositor(
200 const cc::ReturnedResourceArray& resources, 203 const cc::ReturnedResourceArray& resources,
201 const CompositorID& compositor_id, 204 const CompositorID& compositor_id,
202 uint32_t compositor_frame_sink_id) { 205 uint32_t compositor_frame_sink_id) {
203 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_) 206 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_)
204 return; 207 return;
205 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, 208 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id,
206 compositor_frame_sink_id); 209 compositor_frame_sink_id);
207 } 210 }
208 211
209 } // namespace android_webview 212 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698