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(); | 81 DCHECK(child_frame_->frame.get()); |
82 } | 82 DCHECK(!child_frame_->frame->gl_frame_data); |
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 } | 83 } |
107 | 84 |
108 void HardwareRenderer::DrawGL(bool stencil_enabled, | 85 void HardwareRenderer::DrawGL(bool stencil_enabled, |
109 AwDrawGLInfo* draw_info) { | 86 AwDrawGLInfo* draw_info) { |
110 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); | 87 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); |
111 | 88 |
112 // We need to watch if the current Android context has changed and enforce | 89 // We need to watch if the current Android context has changed and enforce |
113 // a clean-up in the compositor. | 90 // a clean-up in the compositor. |
114 EGLContext current_context = eglGetCurrentContext(); | 91 EGLContext current_context = eglGetCurrentContext(); |
115 DCHECK(current_context) << "DrawGL called without EGLContext"; | 92 DCHECK(current_context) << "DrawGL called without EGLContext"; |
116 | 93 |
117 // TODO(boliu): Handle context loss. | 94 // TODO(boliu): Handle context loss. |
118 if (last_egl_context_ != current_context) | 95 if (last_egl_context_ != current_context) |
119 DLOG(WARNING) << "EGLContextChanged"; | 96 DLOG(WARNING) << "EGLContextChanged"; |
120 | 97 |
| 98 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it |
| 99 // during "kModeSync" stage (which does not allow GL) might result in extra |
| 100 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid |
| 101 // unnecessary kModeProcess. |
| 102 scoped_ptr<ChildFrame> child_frame = child_frame_.Pass(); |
| 103 if (child_frame.get()) { |
| 104 scoped_ptr<cc::CompositorFrame> child_compositor_frame = |
| 105 child_frame->frame.Pass(); |
| 106 |
| 107 // On Android we put our browser layers in physical pixels and set our |
| 108 // browser CC device_scale_factor to 1, so suppress the transform between |
| 109 // DIP and pixels. |
| 110 child_compositor_frame->delegated_frame_data->device_scale_factor = 1.0f; |
| 111 |
| 112 gfx::Size frame_size = |
| 113 child_compositor_frame->delegated_frame_data->render_pass_list.back() |
| 114 ->output_rect.size(); |
| 115 bool size_changed = frame_size != frame_size_; |
| 116 frame_size_ = frame_size; |
| 117 if (child_id_.is_null() || size_changed) { |
| 118 if (!child_id_.is_null()) |
| 119 surface_factory_->Destroy(child_id_); |
| 120 child_id_ = surface_id_allocator_->GenerateId(); |
| 121 surface_factory_->Create(child_id_); |
| 122 } |
| 123 |
| 124 surface_factory_->SubmitCompositorFrame(child_id_, |
| 125 child_compositor_frame.Pass(), |
| 126 cc::SurfaceFactory::DrawCallback()); |
| 127 } |
| 128 |
121 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 129 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
122 transform.matrix().setColMajorf(draw_info->transform); | 130 transform.matrix().setColMajorf(draw_info->transform); |
123 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); | 131 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); |
124 | 132 |
125 gfx::Size viewport(draw_info->width, draw_info->height); | 133 gfx::Size viewport(draw_info->width, draw_info->height); |
126 // Need to post the new transform matrix back to child compositor | 134 // Need to post the new transform matrix back to child compositor |
127 // because there is no onDraw during a Render Thread animation, and child | 135 // 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. | 136 // compositor might not have the tiles rasterized as the animation goes on. |
129 ParentCompositorDrawConstraints draw_constraints( | 137 ParentCompositorDrawConstraints draw_constraints( |
130 draw_info->is_layer, transform, viewport.IsEmpty()); | 138 draw_info->is_layer, transform, viewport.IsEmpty()); |
131 if (!child_frame_.get() || draw_constraints.NeedUpdate(*child_frame_)) { | 139 if (!child_frame.get() || draw_constraints.NeedUpdate(*child_frame)) { |
132 shared_renderer_state_->PostExternalDrawConstraintsToChildCompositorOnRT( | 140 shared_renderer_state_->PostExternalDrawConstraintsToChildCompositorOnRT( |
133 draw_constraints); | 141 draw_constraints); |
134 } | 142 } |
135 | 143 |
136 if (child_id_.is_null()) | 144 if (child_id_.is_null()) |
137 return; | 145 return; |
138 | 146 |
139 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top, | 147 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top, |
140 draw_info->clip_right - draw_info->clip_left, | 148 draw_info->clip_right - draw_info->clip_left, |
141 draw_info->clip_bottom - draw_info->clip_top); | 149 draw_info->clip_bottom - draw_info->clip_top); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 const cc::ReturnedResourceArray& resources) { | 200 const cc::ReturnedResourceArray& resources) { |
193 shared_renderer_state_->InsertReturnedResourcesOnRT(resources); | 201 shared_renderer_state_->InsertReturnedResourcesOnRT(resources); |
194 } | 202 } |
195 | 203 |
196 void HardwareRenderer::SetBackingFrameBufferObject( | 204 void HardwareRenderer::SetBackingFrameBufferObject( |
197 int framebuffer_binding_ext) { | 205 int framebuffer_binding_ext) { |
198 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext); | 206 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext); |
199 } | 207 } |
200 | 208 |
201 } // namespace android_webview | 209 } // namespace android_webview |
OLD | NEW |