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

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

Issue 2425923003: Replaced is_null() with is_valid in SurfaceId and related classes. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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
« no previous file with comments | « no previous file | android_webview/browser/surfaces_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 25 matching lines...) Expand all
36 last_submitted_compositor_frame_sink_id_(0u) { 36 last_submitted_compositor_frame_sink_id_(0u) {
37 DCHECK(last_egl_context_); 37 DCHECK(last_egl_context_);
38 surfaces_->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); 38 surfaces_->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
39 surfaces_->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, 39 surfaces_->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_,
40 this); 40 this);
41 } 41 }
42 42
43 HardwareRenderer::~HardwareRenderer() { 43 HardwareRenderer::~HardwareRenderer() {
44 // Must reset everything before |surface_factory_| to ensure all 44 // Must reset everything before |surface_factory_| to ensure all
45 // resources are returned before resetting. 45 // resources are returned before resetting.
46 if (!child_id_.is_null()) 46 if (child_id_.is_valid())
47 DestroySurface(); 47 DestroySurface();
48 surface_factory_.reset(); 48 surface_factory_.reset();
49 surfaces_->GetSurfaceManager()->UnregisterSurfaceFactoryClient( 49 surfaces_->GetSurfaceManager()->UnregisterSurfaceFactoryClient(
50 frame_sink_id_); 50 frame_sink_id_);
51 surfaces_->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); 51 surfaces_->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
52 52
53 // Reset draw constraints. 53 // Reset draw constraints.
54 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( 54 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT(
55 ParentCompositorDrawConstraints()); 55 ParentCompositorDrawConstraints());
56 for (auto& child_frame : child_frames_) { 56 for (auto& child_frame : child_frames_) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 DLOG(WARNING) << "EGLContextChanged"; 105 DLOG(WARNING) << "EGLContextChanged";
106 106
107 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it 107 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it
108 // during "kModeSync" stage (which does not allow GL) might result in extra 108 // during "kModeSync" stage (which does not allow GL) might result in extra
109 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid 109 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid
110 // unnecessary kModeProcess. 110 // unnecessary kModeProcess.
111 if (child_frame.get() && child_frame->frame.get()) { 111 if (child_frame.get() && child_frame->frame.get()) {
112 if (!compositor_id_.Equals(child_frame->compositor_id) || 112 if (!compositor_id_.Equals(child_frame->compositor_id) ||
113 last_submitted_compositor_frame_sink_id_ != 113 last_submitted_compositor_frame_sink_id_ !=
114 child_frame->compositor_frame_sink_id) { 114 child_frame->compositor_frame_sink_id) {
115 if (!child_id_.is_null()) 115 if (child_id_.is_valid())
116 DestroySurface(); 116 DestroySurface();
117 117
118 // This will return all the resources to the previous compositor. 118 // This will return all the resources to the previous compositor.
119 surface_factory_->Reset(); 119 surface_factory_->Reset();
120 compositor_id_ = child_frame->compositor_id; 120 compositor_id_ = child_frame->compositor_id;
121 last_submitted_compositor_frame_sink_id_ = 121 last_submitted_compositor_frame_sink_id_ =
122 child_frame->compositor_frame_sink_id; 122 child_frame->compositor_frame_sink_id;
123 } 123 }
124 124
125 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = 125 std::unique_ptr<cc::CompositorFrame> child_compositor_frame =
126 std::move(child_frame->frame); 126 std::move(child_frame->frame);
127 127
128 gfx::Size frame_size = 128 gfx::Size frame_size =
129 child_compositor_frame->render_pass_list.back()->output_rect.size(); 129 child_compositor_frame->render_pass_list.back()->output_rect.size();
130 bool size_changed = frame_size != frame_size_; 130 bool size_changed = frame_size != frame_size_;
131 frame_size_ = frame_size; 131 frame_size_ = frame_size;
132 if (child_id_.is_null() || size_changed) { 132 if (!child_id_.is_valid() || size_changed) {
133 if (!child_id_.is_null()) 133 if (child_id_.is_valid())
134 DestroySurface(); 134 DestroySurface();
135 AllocateSurface(); 135 AllocateSurface();
136 } 136 }
137 137
138 surface_factory_->SubmitCompositorFrame(child_id_, 138 surface_factory_->SubmitCompositorFrame(child_id_,
139 std::move(*child_compositor_frame), 139 std::move(*child_compositor_frame),
140 cc::SurfaceFactory::DrawCallback()); 140 cc::SurfaceFactory::DrawCallback());
141 } 141 }
142 142
143 gfx::Transform transform(gfx::Transform::kSkipInitialization); 143 gfx::Transform transform(gfx::Transform::kSkipInitialization);
144 transform.matrix().setColMajorf(draw_info->transform); 144 transform.matrix().setColMajorf(draw_info->transform);
145 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); 145 transform.Translate(scroll_offset_.x(), scroll_offset_.y());
146 146
147 gfx::Size viewport(draw_info->width, draw_info->height); 147 gfx::Size viewport(draw_info->width, draw_info->height);
148 // Need to post the new transform matrix back to child compositor 148 // Need to post the new transform matrix back to child compositor
149 // because there is no onDraw during a Render Thread animation, and child 149 // because there is no onDraw during a Render Thread animation, and child
150 // compositor might not have the tiles rasterized as the animation goes on. 150 // compositor might not have the tiles rasterized as the animation goes on.
151 ParentCompositorDrawConstraints draw_constraints( 151 ParentCompositorDrawConstraints draw_constraints(
152 draw_info->is_layer, transform, viewport.IsEmpty()); 152 draw_info->is_layer, transform, viewport.IsEmpty());
153 if (!child_frame.get() || draw_constraints.NeedUpdate(*child_frame)) { 153 if (!child_frame.get() || draw_constraints.NeedUpdate(*child_frame)) {
154 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( 154 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT(
155 draw_constraints); 155 draw_constraints);
156 } 156 }
157 157
158 if (child_id_.is_null()) 158 if (!child_id_.is_valid())
159 return; 159 return;
160 160
161 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top, 161 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top,
162 draw_info->clip_right - draw_info->clip_left, 162 draw_info->clip_right - draw_info->clip_left,
163 draw_info->clip_bottom - draw_info->clip_top); 163 draw_info->clip_bottom - draw_info->clip_top);
164 surfaces_->DrawAndSwap(viewport, clip, transform, frame_size_, 164 surfaces_->DrawAndSwap(viewport, clip, transform, frame_size_,
165 cc::SurfaceId(frame_sink_id_, child_id_)); 165 cc::SurfaceId(frame_sink_id_, child_id_));
166 } 166 }
167 167
168 void HardwareRenderer::AllocateSurface() { 168 void HardwareRenderer::AllocateSurface() {
169 DCHECK(child_id_.is_null()); 169 DCHECK(!child_id_.is_valid());
170 child_id_ = surface_id_allocator_->GenerateId(); 170 child_id_ = surface_id_allocator_->GenerateId();
171 surface_factory_->Create(child_id_); 171 surface_factory_->Create(child_id_);
172 surfaces_->AddChildId(cc::SurfaceId(frame_sink_id_, child_id_)); 172 surfaces_->AddChildId(cc::SurfaceId(frame_sink_id_, child_id_));
173 } 173 }
174 174
175 void HardwareRenderer::DestroySurface() { 175 void HardwareRenderer::DestroySurface() {
176 DCHECK(!child_id_.is_null()); 176 DCHECK(child_id_.is_valid());
177 177
178 // Submit an empty frame to force any existing resources to be returned. 178 // Submit an empty frame to force any existing resources to be returned.
179 surface_factory_->SubmitCompositorFrame(child_id_, cc::CompositorFrame(), 179 surface_factory_->SubmitCompositorFrame(child_id_, cc::CompositorFrame(),
180 cc::SurfaceFactory::DrawCallback()); 180 cc::SurfaceFactory::DrawCallback());
181 181
182 surfaces_->RemoveChildId(cc::SurfaceId(frame_sink_id_, child_id_)); 182 surfaces_->RemoveChildId(cc::SurfaceId(frame_sink_id_, child_id_));
183 surface_factory_->Destroy(child_id_); 183 surface_factory_->Destroy(child_id_);
184 child_id_ = cc::LocalFrameId(); 184 child_id_ = cc::LocalFrameId();
185 } 185 }
186 186
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 const cc::ReturnedResourceArray& resources, 251 const cc::ReturnedResourceArray& resources,
252 const CompositorID& compositor_id, 252 const CompositorID& compositor_id,
253 uint32_t compositor_frame_sink_id) { 253 uint32_t compositor_frame_sink_id) {
254 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_) 254 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_)
255 return; 255 return;
256 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, 256 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id,
257 compositor_frame_sink_id); 257 compositor_frame_sink_id);
258 } 258 }
259 259
260 } // namespace android_webview 260 } // namespace android_webview
OLDNEW
« no previous file with comments | « no previous file | android_webview/browser/surfaces_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698