OLD | NEW |
---|---|
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 "android_webview/browser/aw_gl_surface.h" | 7 #include "android_webview/browser/aw_gl_surface.h" |
8 #include "android_webview/browser/aw_render_thread_context_provider.h" | 8 #include "android_webview/browser/aw_render_thread_context_provider.h" |
9 #include "android_webview/browser/child_frame.h" | 9 #include "android_webview/browser/child_frame.h" |
10 #include "android_webview/browser/deferred_gpu_command_service.h" | 10 #include "android_webview/browser/deferred_gpu_command_service.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 surface_factory_.reset(); | 66 surface_factory_.reset(); |
67 | 67 |
68 // Reset draw constraints. | 68 // Reset draw constraints. |
69 shared_renderer_state_->PostExternalDrawConstraintsToChildCompositorOnRT( | 69 shared_renderer_state_->PostExternalDrawConstraintsToChildCompositorOnRT( |
70 ParentCompositorDrawConstraints()); | 70 ParentCompositorDrawConstraints()); |
71 } | 71 } |
72 | 72 |
73 void HardwareRenderer::CommitFrame() { | 73 void HardwareRenderer::CommitFrame() { |
74 TRACE_EVENT0("android_webview", "CommitFrame"); | 74 TRACE_EVENT0("android_webview", "CommitFrame"); |
75 scroll_offset_ = shared_renderer_state_->GetScrollOffsetOnRT(); | 75 scroll_offset_ = shared_renderer_state_->GetScrollOffsetOnRT(); |
76 { | 76 scoped_ptr<ChildFrame> child_frame = |
77 scoped_ptr<ChildFrame> child_frame = | 77 shared_renderer_state_->PassCompositorFrameOnRT(); |
78 shared_renderer_state_->PassCompositorFrameOnRT(); | 78 if (!child_frame.get()) |
79 if (!child_frame.get()) | 79 return; |
80 return; | 80 child_frame_ = child_frame.Pass(); |
81 child_frame_ = child_frame.Pass(); | |
82 } | |
83 | |
84 scoped_ptr<cc::CompositorFrame> frame = child_frame_->frame.Pass(); | |
85 DCHECK(frame.get()); | |
86 DCHECK(!frame->gl_frame_data); | |
87 | |
88 // On Android we put our browser layers in physical pixels and set our | |
89 // browser CC device_scale_factor to 1, so suppress the transform between | |
90 // DIP and pixels. | |
91 frame->delegated_frame_data->device_scale_factor = 1.0f; | |
92 | |
93 gfx::Size frame_size = | |
94 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); | |
95 bool size_changed = frame_size != frame_size_; | |
96 frame_size_ = frame_size; | |
97 if (child_id_.is_null() || size_changed) { | |
98 if (!child_id_.is_null()) | |
99 surface_factory_->Destroy(child_id_); | |
100 child_id_ = surface_id_allocator_->GenerateId(); | |
101 surface_factory_->Create(child_id_); | |
102 } | |
103 | |
104 surface_factory_->SubmitCompositorFrame(child_id_, frame.Pass(), | |
105 cc::SurfaceFactory::DrawCallback()); | |
106 } | 81 } |
107 | 82 |
108 void HardwareRenderer::DrawGL(bool stencil_enabled, | 83 void HardwareRenderer::DrawGL(bool stencil_enabled, |
109 AwDrawGLInfo* draw_info) { | 84 AwDrawGLInfo* draw_info) { |
110 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); | 85 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); |
111 | 86 |
112 // We need to watch if the current Android context has changed and enforce | 87 // We need to watch if the current Android context has changed and enforce |
113 // a clean-up in the compositor. | 88 // a clean-up in the compositor. |
114 EGLContext current_context = eglGetCurrentContext(); | 89 EGLContext current_context = eglGetCurrentContext(); |
115 DCHECK(current_context) << "DrawGL called without EGLContext"; | 90 DCHECK(current_context) << "DrawGL called without EGLContext"; |
116 | 91 |
117 // TODO(boliu): Handle context loss. | 92 // TODO(boliu): Handle context loss. |
118 if (last_egl_context_ != current_context) | 93 if (last_egl_context_ != current_context) |
119 DLOG(WARNING) << "EGLContextChanged"; | 94 DLOG(WARNING) << "EGLContextChanged"; |
120 | 95 |
96 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it | |
97 // during "kModeSync" stage (which does not allow GL) might result in extra | |
98 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid | |
99 // unnecessary kModeProcess. | |
100 if (child_frame_.get() && child_frame_->frame.get()) { | |
boliu
2015/09/15 00:02:40
Ehh, pass the whole child_frame_ below, then you d
hush (inactive)
2015/09/15 00:50:30
Done.
| |
101 scoped_ptr<cc::CompositorFrame> child_frame = child_frame_->frame.Pass(); | |
102 DCHECK(!child_frame->gl_frame_data); | |
103 | |
104 // On Android we put our browser layers in physical pixels and set our | |
105 // browser CC device_scale_factor to 1, so suppress the transform between | |
106 // DIP and pixels. | |
107 child_frame->delegated_frame_data->device_scale_factor = 1.0f; | |
108 | |
109 gfx::Size frame_size = | |
110 child_frame->delegated_frame_data->render_pass_list.back() | |
111 ->output_rect.size(); | |
112 bool size_changed = frame_size != frame_size_; | |
113 frame_size_ = frame_size; | |
114 if (child_id_.is_null() || size_changed) { | |
115 if (!child_id_.is_null()) | |
116 surface_factory_->Destroy(child_id_); | |
117 child_id_ = surface_id_allocator_->GenerateId(); | |
118 surface_factory_->Create(child_id_); | |
119 } | |
120 | |
121 surface_factory_->SubmitCompositorFrame(child_id_, child_frame.Pass(), | |
122 cc::SurfaceFactory::DrawCallback()); | |
123 } | |
124 | |
121 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 125 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
122 transform.matrix().setColMajorf(draw_info->transform); | 126 transform.matrix().setColMajorf(draw_info->transform); |
123 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); | 127 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); |
124 | 128 |
125 gfx::Size viewport(draw_info->width, draw_info->height); | 129 gfx::Size viewport(draw_info->width, draw_info->height); |
126 // Need to post the new transform matrix back to child compositor | 130 // Need to post the new transform matrix back to child compositor |
127 // because there is no onDraw during a Render Thread animation, and child | 131 // because there is no onDraw during a Render Thread animation, and child |
128 // compositor might not have the tiles rasterized as the animation goes on. | 132 // compositor might not have the tiles rasterized as the animation goes on. |
129 ParentCompositorDrawConstraints draw_constraints( | 133 ParentCompositorDrawConstraints draw_constraints( |
130 draw_info->is_layer, transform, viewport.IsEmpty()); | 134 draw_info->is_layer, transform, viewport.IsEmpty()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 const cc::ReturnedResourceArray& resources) { | 196 const cc::ReturnedResourceArray& resources) { |
193 shared_renderer_state_->InsertReturnedResourcesOnRT(resources); | 197 shared_renderer_state_->InsertReturnedResourcesOnRT(resources); |
194 } | 198 } |
195 | 199 |
196 void HardwareRenderer::SetBackingFrameBufferObject( | 200 void HardwareRenderer::SetBackingFrameBufferObject( |
197 int framebuffer_binding_ext) { | 201 int framebuffer_binding_ext) { |
198 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext); | 202 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext); |
199 } | 203 } |
200 | 204 |
201 } // namespace android_webview | 205 } // namespace android_webview |
OLD | NEW |