OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/output/direct_renderer.h" | 5 #include "cc/output/direct_renderer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <unordered_map> |
9 #include <utility> | 10 #include <utility> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/containers/hash_tables.h" | |
13 #include "base/containers/scoped_ptr_hash_map.h" | |
14 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
15 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
16 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
17 #include "cc/base/math_util.h" | 16 #include "cc/base/math_util.h" |
18 #include "cc/output/bsp_tree.h" | 17 #include "cc/output/bsp_tree.h" |
19 #include "cc/output/bsp_walk_action.h" | 18 #include "cc/output/bsp_walk_action.h" |
20 #include "cc/output/copy_output_request.h" | 19 #include "cc/output/copy_output_request.h" |
21 #include "cc/quads/draw_quad.h" | 20 #include "cc/quads/draw_quad.h" |
22 #include "ui/gfx/geometry/quad_f.h" | 21 #include "ui/gfx/geometry/quad_f.h" |
23 #include "ui/gfx/geometry/rect_conversions.h" | 22 #include "ui/gfx/geometry/rect_conversions.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 141 |
143 DirectRenderer::~DirectRenderer() {} | 142 DirectRenderer::~DirectRenderer() {} |
144 | 143 |
145 void DirectRenderer::SetEnlargePassTextureAmountForTesting( | 144 void DirectRenderer::SetEnlargePassTextureAmountForTesting( |
146 const gfx::Vector2d& amount) { | 145 const gfx::Vector2d& amount) { |
147 enlarge_pass_texture_amount_ = amount; | 146 enlarge_pass_texture_amount_ = amount; |
148 } | 147 } |
149 | 148 |
150 void DirectRenderer::DecideRenderPassAllocationsForFrame( | 149 void DirectRenderer::DecideRenderPassAllocationsForFrame( |
151 const RenderPassList& render_passes_in_draw_order) { | 150 const RenderPassList& render_passes_in_draw_order) { |
152 base::hash_map<RenderPassId, gfx::Size> render_passes_in_frame; | 151 std::unordered_map<RenderPassId, gfx::Size, RenderPassIdHash> |
| 152 render_passes_in_frame; |
153 for (size_t i = 0; i < render_passes_in_draw_order.size(); ++i) | 153 for (size_t i = 0; i < render_passes_in_draw_order.size(); ++i) |
154 render_passes_in_frame.insert(std::pair<RenderPassId, gfx::Size>( | 154 render_passes_in_frame.insert(std::pair<RenderPassId, gfx::Size>( |
155 render_passes_in_draw_order[i]->id, | 155 render_passes_in_draw_order[i]->id, |
156 RenderPassTextureSize(render_passes_in_draw_order[i].get()))); | 156 RenderPassTextureSize(render_passes_in_draw_order[i].get()))); |
157 | 157 |
158 std::vector<RenderPassId> passes_to_delete; | 158 std::vector<RenderPassId> passes_to_delete; |
159 for (auto pass_iter = render_pass_textures_.begin(); | 159 for (auto pass_iter = render_pass_textures_.begin(); |
160 pass_iter != render_pass_textures_.end(); ++pass_iter) { | 160 pass_iter != render_pass_textures_.end(); ++pass_iter) { |
161 base::hash_map<RenderPassId, gfx::Size>::const_iterator it = | 161 auto it = render_passes_in_frame.find(pass_iter->first); |
162 render_passes_in_frame.find(pass_iter->first); | |
163 if (it == render_passes_in_frame.end()) { | 162 if (it == render_passes_in_frame.end()) { |
164 passes_to_delete.push_back(pass_iter->first); | 163 passes_to_delete.push_back(pass_iter->first); |
165 continue; | 164 continue; |
166 } | 165 } |
167 | 166 |
168 gfx::Size required_size = it->second; | 167 gfx::Size required_size = it->second; |
169 ScopedResource* texture = pass_iter->second; | 168 ScopedResource* texture = pass_iter->second.get(); |
170 DCHECK(texture); | 169 DCHECK(texture); |
171 | 170 |
172 bool size_appropriate = texture->size().width() >= required_size.width() && | 171 bool size_appropriate = texture->size().width() >= required_size.width() && |
173 texture->size().height() >= required_size.height(); | 172 texture->size().height() >= required_size.height(); |
174 if (texture->id() && !size_appropriate) | 173 if (texture->id() && !size_appropriate) |
175 texture->Free(); | 174 texture->Free(); |
176 } | 175 } |
177 | 176 |
178 // Delete RenderPass textures from the previous frame that will not be used | 177 // Delete RenderPass textures from the previous frame that will not be used |
179 // again. | 178 // again. |
180 for (size_t i = 0; i < passes_to_delete.size(); ++i) | 179 for (size_t i = 0; i < passes_to_delete.size(); ++i) |
181 render_pass_textures_.erase(passes_to_delete[i]); | 180 render_pass_textures_.erase(passes_to_delete[i]); |
182 | 181 |
183 for (size_t i = 0; i < render_passes_in_draw_order.size(); ++i) { | 182 for (size_t i = 0; i < render_passes_in_draw_order.size(); ++i) { |
184 if (!render_pass_textures_.contains(render_passes_in_draw_order[i]->id)) { | 183 if (render_pass_textures_.count(render_passes_in_draw_order[i]->id) == 0) { |
185 scoped_ptr<ScopedResource> texture = | 184 scoped_ptr<ScopedResource> texture = |
186 ScopedResource::Create(resource_provider_); | 185 ScopedResource::Create(resource_provider_); |
187 render_pass_textures_.set(render_passes_in_draw_order[i]->id, | 186 render_pass_textures_[render_passes_in_draw_order[i]->id] = |
188 std::move(texture)); | 187 std::move(texture); |
189 } | 188 } |
190 } | 189 } |
191 } | 190 } |
192 | 191 |
193 void DirectRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order, | 192 void DirectRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order, |
194 float device_scale_factor, | 193 float device_scale_factor, |
195 const gfx::Rect& device_viewport_rect, | 194 const gfx::Rect& device_viewport_rect, |
196 const gfx::Rect& device_clip_rect, | 195 const gfx::Rect& device_clip_rect, |
197 bool disable_picture_quad_image_filtering) { | 196 bool disable_picture_quad_image_filtering) { |
198 TRACE_EVENT0("cc", "DirectRenderer::DrawFrame"); | 197 TRACE_EVENT0("cc", "DirectRenderer::DrawFrame"); |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 frame->current_texture = NULL; | 526 frame->current_texture = NULL; |
528 if (render_pass == frame->root_render_pass) { | 527 if (render_pass == frame->root_render_pass) { |
529 BindFramebufferToOutputSurface(frame); | 528 BindFramebufferToOutputSurface(frame); |
530 InitializeViewport(frame, | 529 InitializeViewport(frame, |
531 render_pass->output_rect, | 530 render_pass->output_rect, |
532 frame->device_viewport_rect, | 531 frame->device_viewport_rect, |
533 output_surface_->SurfaceSize()); | 532 output_surface_->SurfaceSize()); |
534 return true; | 533 return true; |
535 } | 534 } |
536 | 535 |
537 ScopedResource* texture = render_pass_textures_.get(render_pass->id); | 536 ScopedResource* texture = render_pass_textures_[render_pass->id].get(); |
538 DCHECK(texture); | 537 DCHECK(texture); |
539 | 538 |
540 gfx::Size size = RenderPassTextureSize(render_pass); | 539 gfx::Size size = RenderPassTextureSize(render_pass); |
541 size.Enlarge(enlarge_pass_texture_amount_.x(), | 540 size.Enlarge(enlarge_pass_texture_amount_.x(), |
542 enlarge_pass_texture_amount_.y()); | 541 enlarge_pass_texture_amount_.y()); |
543 if (!texture->id()) { | 542 if (!texture->id()) { |
544 texture->Allocate(size, | 543 texture->Allocate(size, |
545 ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER, | 544 ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER, |
546 resource_provider_->best_texture_format()); | 545 resource_provider_->best_texture_format()); |
547 } | 546 } |
548 DCHECK(texture->id()); | 547 DCHECK(texture->id()); |
549 | 548 |
550 if (BindFramebufferToTexture(frame, texture)) { | 549 if (BindFramebufferToTexture(frame, texture)) { |
551 InitializeViewport(frame, render_pass->output_rect, | 550 InitializeViewport(frame, render_pass->output_rect, |
552 gfx::Rect(render_pass->output_rect.size()), | 551 gfx::Rect(render_pass->output_rect.size()), |
553 render_pass->output_rect.size()); | 552 render_pass->output_rect.size()); |
554 return true; | 553 return true; |
555 } | 554 } |
556 | 555 |
557 return false; | 556 return false; |
558 } | 557 } |
559 | 558 |
560 bool DirectRenderer::HasAllocatedResourcesForTesting(RenderPassId id) const { | 559 bool DirectRenderer::HasAllocatedResourcesForTesting(RenderPassId id) const { |
561 ScopedResource* texture = render_pass_textures_.get(id); | 560 auto iter = render_pass_textures_.find(id); |
562 return texture && texture->id(); | 561 return iter != render_pass_textures_.end() && iter->second->id(); |
563 } | 562 } |
564 | 563 |
565 // static | 564 // static |
566 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { | 565 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { |
567 return render_pass->output_rect.size(); | 566 return render_pass->output_rect.size(); |
568 } | 567 } |
569 | 568 |
570 } // namespace cc | 569 } // namespace cc |
OLD | NEW |