| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/containers/scoped_ptr_hash_map.h" |
| 11 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 13 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
| 14 #include "cc/output/copy_output_request.h" | 15 #include "cc/output/copy_output_request.h" |
| 15 #include "cc/quads/draw_quad.h" | 16 #include "cc/quads/draw_quad.h" |
| 16 #include "ui/gfx/rect_conversions.h" | 17 #include "ui/gfx/rect_conversions.h" |
| 17 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
| 18 | 19 |
| 19 static gfx::Transform OrthoProjectionMatrix(float left, | 20 static gfx::Transform OrthoProjectionMatrix(float left, |
| 20 float right, | 21 float right, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 const RenderPassList& render_passes_in_draw_order) { | 145 const RenderPassList& render_passes_in_draw_order) { |
| 145 if (!resource_provider_) | 146 if (!resource_provider_) |
| 146 return; | 147 return; |
| 147 | 148 |
| 148 base::hash_map<RenderPass::Id, const RenderPass*> render_passes_in_frame; | 149 base::hash_map<RenderPass::Id, const RenderPass*> render_passes_in_frame; |
| 149 for (size_t i = 0; i < render_passes_in_draw_order.size(); ++i) | 150 for (size_t i = 0; i < render_passes_in_draw_order.size(); ++i) |
| 150 render_passes_in_frame.insert(std::pair<RenderPass::Id, const RenderPass*>( | 151 render_passes_in_frame.insert(std::pair<RenderPass::Id, const RenderPass*>( |
| 151 render_passes_in_draw_order[i]->id, render_passes_in_draw_order[i])); | 152 render_passes_in_draw_order[i]->id, render_passes_in_draw_order[i])); |
| 152 | 153 |
| 153 std::vector<RenderPass::Id> passes_to_delete; | 154 std::vector<RenderPass::Id> passes_to_delete; |
| 154 ScopedPtrHashMap<RenderPass::Id, CachedResource>::const_iterator pass_iter; | 155 base::ScopedPtrHashMap<RenderPass::Id, CachedResource>::const_iterator |
| 156 pass_iter; |
| 155 for (pass_iter = render_pass_textures_.begin(); | 157 for (pass_iter = render_pass_textures_.begin(); |
| 156 pass_iter != render_pass_textures_.end(); | 158 pass_iter != render_pass_textures_.end(); |
| 157 ++pass_iter) { | 159 ++pass_iter) { |
| 158 base::hash_map<RenderPass::Id, const RenderPass*>::const_iterator it = | 160 base::hash_map<RenderPass::Id, const RenderPass*>::const_iterator it = |
| 159 render_passes_in_frame.find(pass_iter->first); | 161 render_passes_in_frame.find(pass_iter->first); |
| 160 if (it == render_passes_in_frame.end()) { | 162 if (it == render_passes_in_frame.end()) { |
| 161 passes_to_delete.push_back(pass_iter->first); | 163 passes_to_delete.push_back(pass_iter->first); |
| 162 continue; | 164 continue; |
| 163 } | 165 } |
| 164 | 166 |
| 165 const RenderPass* render_pass_in_frame = it->second; | 167 const RenderPass* render_pass_in_frame = it->second; |
| 166 gfx::Size required_size = RenderPassTextureSize(render_pass_in_frame); | 168 gfx::Size required_size = RenderPassTextureSize(render_pass_in_frame); |
| 167 GLenum required_format = RenderPassTextureFormat(render_pass_in_frame); | 169 GLenum required_format = RenderPassTextureFormat(render_pass_in_frame); |
| 168 CachedResource* texture = pass_iter->second; | 170 CachedResource* texture = pass_iter->second; |
| 169 DCHECK(texture); | 171 DCHECK(texture); |
| 170 | 172 |
| 171 bool size_appropriate = texture->size().width() >= required_size.width() && | 173 bool size_appropriate = texture->size().width() >= required_size.width() && |
| 172 texture->size().height() >= required_size.height(); | 174 texture->size().height() >= required_size.height(); |
| 173 if (texture->id() && | 175 if (texture->id() && |
| 174 (!size_appropriate || texture->format() != required_format)) | 176 (!size_appropriate || texture->format() != required_format)) |
| 175 texture->Free(); | 177 texture->Free(); |
| 176 } | 178 } |
| 177 | 179 |
| 178 // Delete RenderPass textures from the previous frame that will not be used | 180 // Delete RenderPass textures from the previous frame that will not be used |
| 179 // again. | 181 // again. |
| 180 for (size_t i = 0; i < passes_to_delete.size(); ++i) | 182 for (size_t i = 0; i < passes_to_delete.size(); ++i) |
| 181 render_pass_textures_.erase(passes_to_delete[i]); | 183 render_pass_textures_.erase(passes_to_delete[i]); |
| 182 | 184 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { | 381 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { |
| 380 return render_pass->output_rect.size(); | 382 return render_pass->output_rect.size(); |
| 381 } | 383 } |
| 382 | 384 |
| 383 // static | 385 // static |
| 384 GLenum DirectRenderer::RenderPassTextureFormat(const RenderPass* render_pass) { | 386 GLenum DirectRenderer::RenderPassTextureFormat(const RenderPass* render_pass) { |
| 385 return GL_RGBA; | 387 return GL_RGBA; |
| 386 } | 388 } |
| 387 | 389 |
| 388 } // namespace cc | 390 } // namespace cc |
| OLD | NEW |