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

Side by Side Diff: cc/output/direct_renderer.cc

Issue 2944523002: Improving flat containers interface. (Closed)
Patch Set: Minimizing target_auto_attacher diff Created 3 years, 5 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 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 <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 if (const TileDrawQuad* tile_quad = CanPassBeDrawnDirectly(pass.get())) { 185 if (const TileDrawQuad* tile_quad = CanPassBeDrawnDirectly(pass.get())) {
186 // If the render pass is drawn directly, it will not be drawn from as 186 // If the render pass is drawn directly, it will not be drawn from as
187 // a render pass so it's not added to the map. 187 // a render pass so it's not added to the map.
188 render_pass_bypass_quads_[pass->id] = *tile_quad; 188 render_pass_bypass_quads_[pass->id] = *tile_quad;
189 continue; 189 continue;
190 } 190 }
191 } 191 }
192 render_passes_in_frame[pass->id] = RenderPassTextureSize(pass.get()); 192 render_passes_in_frame[pass->id] = RenderPassTextureSize(pass.get());
193 } 193 }
194 194
195 std::vector<int> passes_to_delete; 195 base::EraseIf(render_pass_textures_,
196 for (const auto& pair : render_pass_textures_) { 196 [&](const std::pair<RenderPassId,
danakj 2017/07/20 16:12:20 can you put the lambda in an auto var first, rathe
dyaroshev 2017/07/20 16:33:02 Just reverted and fixed compilation.
197 auto it = render_passes_in_frame.find(pair.first); 197 std::unique_ptr<ScopedResource>>& pair) {
198 if (it == render_passes_in_frame.end()) { 198 auto it = render_passes_in_frame.find(pair.first);
199 passes_to_delete.push_back(pair.first);
200 continue;
201 }
202 199
203 gfx::Size required_size = it->second; 200 // Delete RenderPass textures from the previous frame that
204 ScopedResource* texture = pair.second.get(); 201 // will not be used again.
205 DCHECK(texture); 202 if (it == render_passes_in_frame.end())
203 return true;
206 204
207 bool size_appropriate = texture->size().width() >= required_size.width() && 205 gfx::Size required_size = it->second;
208 texture->size().height() >= required_size.height(); 206 ScopedResource* texture = pair.second.get();
209 if (texture->id() && !size_appropriate) 207 DCHECK(texture);
210 texture->Free();
211 }
212 208
213 // Delete RenderPass textures from the previous frame that will not be used 209 bool size_appropriate =
214 // again. 210 texture->size().width() >= required_size.width() &&
215 for (size_t i = 0; i < passes_to_delete.size(); ++i) 211 texture->size().height() >= required_size.height();
216 render_pass_textures_.erase(passes_to_delete[i]); 212 if (texture->id() && !size_appropriate)
213 texture->Free();
214
215 return false;
216 });
217 217
218 for (auto& pass : render_passes_in_draw_order) { 218 for (auto& pass : render_passes_in_draw_order) {
219 auto& resource = render_pass_textures_[pass->id]; 219 auto& resource = render_pass_textures_[pass->id];
220 if (!resource) 220 if (!resource)
221 resource = base::MakeUnique<ScopedResource>(resource_provider_); 221 resource = base::MakeUnique<ScopedResource>(resource_provider_);
222 } 222 }
223 } 223 }
224 224
225 void DirectRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order, 225 void DirectRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order,
226 float device_scale_factor, 226 float device_scale_factor,
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 if (BindFramebufferToTexture(texture)) { 630 if (BindFramebufferToTexture(texture)) {
631 InitializeViewport(current_frame(), render_pass->output_rect, 631 InitializeViewport(current_frame(), render_pass->output_rect,
632 gfx::Rect(render_pass->output_rect.size()), 632 gfx::Rect(render_pass->output_rect.size()),
633 texture->size()); 633 texture->size());
634 return true; 634 return true;
635 } 635 }
636 636
637 return false; 637 return false;
638 } 638 }
639 639
640 bool DirectRenderer::HasAllocatedResourcesForTesting(int render_pass_id) const { 640 bool DirectRenderer::HasAllocatedResourcesForTesting(
641 RenderPassId render_pass_id) const {
641 auto iter = render_pass_textures_.find(render_pass_id); 642 auto iter = render_pass_textures_.find(render_pass_id);
642 return iter != render_pass_textures_.end() && iter->second->id(); 643 return iter != render_pass_textures_.end() && iter->second->id();
643 } 644 }
644 645
645 // static 646 // static
646 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { 647 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) {
647 return render_pass->output_rect.size(); 648 return render_pass->output_rect.size();
648 } 649 }
649 650
650 void DirectRenderer::SetCurrentFrameForTesting(const DrawingFrame& frame) { 651 void DirectRenderer::SetCurrentFrameForTesting(const DrawingFrame& frame) {
651 current_frame_valid_ = true; 652 current_frame_valid_ = true;
652 current_frame_ = frame; 653 current_frame_ = frame;
653 } 654 }
654 655
655 } // namespace cc 656 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698