| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layers/tiled_layer_impl.h" | 5 #include "cc/layers/tiled_layer_impl.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/debug/debug_colors.h" | 10 #include "cc/debug/debug_colors.h" |
| 11 #include "cc/layers/append_quads_data.h" | 11 #include "cc/layers/append_quads_data.h" |
| 12 #include "cc/layers/quad_sink.h" | |
| 13 #include "cc/quads/checkerboard_draw_quad.h" | 12 #include "cc/quads/checkerboard_draw_quad.h" |
| 14 #include "cc/quads/debug_border_draw_quad.h" | 13 #include "cc/quads/debug_border_draw_quad.h" |
| 15 #include "cc/quads/solid_color_draw_quad.h" | 14 #include "cc/quads/solid_color_draw_quad.h" |
| 16 #include "cc/quads/tile_draw_quad.h" | 15 #include "cc/quads/tile_draw_quad.h" |
| 17 #include "cc/resources/layer_tiling_data.h" | 16 #include "cc/resources/layer_tiling_data.h" |
| 17 #include "cc/trees/occlusion_tracker.h" |
| 18 #include "third_party/khronos/GLES2/gl2.h" | 18 #include "third_party/khronos/GLES2/gl2.h" |
| 19 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
| 20 #include "ui/gfx/quad_f.h" | 20 #include "ui/gfx/quad_f.h" |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 | 23 |
| 24 class DrawableTile : public LayerTilingData::Tile { | 24 class DrawableTile : public LayerTilingData::Tile { |
| 25 public: | 25 public: |
| 26 static scoped_ptr<DrawableTile> Create() { | 26 static scoped_ptr<DrawableTile> Create() { |
| 27 return make_scoped_ptr(new DrawableTile()); | 27 return make_scoped_ptr(new DrawableTile()); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 bool TiledLayerImpl::WillDraw(DrawMode draw_mode, | 145 bool TiledLayerImpl::WillDraw(DrawMode draw_mode, |
| 146 ResourceProvider* resource_provider) { | 146 ResourceProvider* resource_provider) { |
| 147 if (!tiler_ || tiler_->has_empty_bounds() || | 147 if (!tiler_ || tiler_->has_empty_bounds() || |
| 148 visible_content_rect().IsEmpty() || | 148 visible_content_rect().IsEmpty() || |
| 149 draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) | 149 draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) |
| 150 return false; | 150 return false; |
| 151 return LayerImpl::WillDraw(draw_mode, resource_provider); | 151 return LayerImpl::WillDraw(draw_mode, resource_provider); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void TiledLayerImpl::AppendQuads(QuadSink* quad_sink, | 154 void TiledLayerImpl::AppendQuads( |
| 155 AppendQuadsData* append_quads_data) { | 155 RenderPass* render_pass, |
| 156 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
| 157 AppendQuadsData* append_quads_data) { |
| 156 DCHECK(tiler_); | 158 DCHECK(tiler_); |
| 157 DCHECK(!tiler_->has_empty_bounds()); | 159 DCHECK(!tiler_->has_empty_bounds()); |
| 158 DCHECK(!visible_content_rect().IsEmpty()); | 160 DCHECK(!visible_content_rect().IsEmpty()); |
| 159 | 161 |
| 160 gfx::Rect content_rect = visible_content_rect(); | 162 gfx::Rect content_rect = visible_content_rect(); |
| 161 SharedQuadState* shared_quad_state = quad_sink->CreateSharedQuadState(); | 163 SharedQuadState* shared_quad_state = |
| 164 render_pass->CreateAndAppendSharedQuadState(); |
| 162 PopulateSharedQuadState(shared_quad_state); | 165 PopulateSharedQuadState(shared_quad_state); |
| 163 | 166 |
| 164 AppendDebugBorderQuad( | 167 AppendDebugBorderQuad( |
| 165 quad_sink, content_bounds(), shared_quad_state, append_quads_data); | 168 render_pass, content_bounds(), shared_quad_state, append_quads_data); |
| 166 | 169 |
| 167 int left, top, right, bottom; | 170 int left, top, right, bottom; |
| 168 tiler_->ContentRectToTileIndices(content_rect, &left, &top, &right, &bottom); | 171 tiler_->ContentRectToTileIndices(content_rect, &left, &top, &right, &bottom); |
| 169 | 172 |
| 170 if (ShowDebugBorders()) { | 173 if (ShowDebugBorders()) { |
| 171 for (int j = top; j <= bottom; ++j) { | 174 for (int j = top; j <= bottom; ++j) { |
| 172 for (int i = left; i <= right; ++i) { | 175 for (int i = left; i <= right; ++i) { |
| 173 DrawableTile* tile = TileAt(i, j); | 176 DrawableTile* tile = TileAt(i, j); |
| 174 gfx::Rect tile_rect = tiler_->tile_bounds(i, j); | 177 gfx::Rect tile_rect = tiler_->tile_bounds(i, j); |
| 175 gfx::Rect visible_tile_rect = tile_rect; | 178 gfx::Rect visible_tile_rect = tile_rect; |
| 176 SkColor border_color; | 179 SkColor border_color; |
| 177 float border_width; | 180 float border_width; |
| 178 | 181 |
| 179 if (skips_draw_ || !tile || !tile->resource_id()) { | 182 if (skips_draw_ || !tile || !tile->resource_id()) { |
| 180 border_color = DebugColors::MissingTileBorderColor(); | 183 border_color = DebugColors::MissingTileBorderColor(); |
| 181 border_width = DebugColors::MissingTileBorderWidth(layer_tree_impl()); | 184 border_width = DebugColors::MissingTileBorderWidth(layer_tree_impl()); |
| 182 } else { | 185 } else { |
| 183 border_color = DebugColors::HighResTileBorderColor(); | 186 border_color = DebugColors::HighResTileBorderColor(); |
| 184 border_width = DebugColors::HighResTileBorderWidth(layer_tree_impl()); | 187 border_width = DebugColors::HighResTileBorderWidth(layer_tree_impl()); |
| 185 } | 188 } |
| 186 scoped_ptr<DebugBorderDrawQuad> debug_border_quad = | 189 scoped_ptr<DebugBorderDrawQuad> debug_border_quad = |
| 187 DebugBorderDrawQuad::Create(); | 190 DebugBorderDrawQuad::Create(); |
| 188 debug_border_quad->SetNew(shared_quad_state, | 191 debug_border_quad->SetNew(shared_quad_state, |
| 189 tile_rect, | 192 tile_rect, |
| 190 visible_tile_rect, | 193 visible_tile_rect, |
| 191 border_color, | 194 border_color, |
| 192 border_width); | 195 border_width); |
| 193 quad_sink->Append(debug_border_quad.PassAs<DrawQuad>()); | 196 render_pass->AppendDrawQuad(debug_border_quad.PassAs<DrawQuad>()); |
| 194 } | 197 } |
| 195 } | 198 } |
| 196 } | 199 } |
| 197 | 200 |
| 198 if (skips_draw_) | 201 if (skips_draw_) |
| 199 return; | 202 return; |
| 200 | 203 |
| 201 for (int j = top; j <= bottom; ++j) { | 204 for (int j = top; j <= bottom; ++j) { |
| 202 for (int i = left; i <= right; ++i) { | 205 for (int i = left; i <= right; ++i) { |
| 203 DrawableTile* tile = TileAt(i, j); | 206 DrawableTile* tile = TileAt(i, j); |
| 204 gfx::Rect tile_rect = tiler_->tile_bounds(i, j); | 207 gfx::Rect tile_rect = tiler_->tile_bounds(i, j); |
| 205 gfx::Rect display_rect = tile_rect; | 208 gfx::Rect display_rect = tile_rect; |
| 206 tile_rect.Intersect(content_rect); | 209 tile_rect.Intersect(content_rect); |
| 207 | 210 |
| 208 // Skip empty tiles. | 211 // Skip empty tiles. |
| 209 if (tile_rect.IsEmpty()) | 212 if (tile_rect.IsEmpty()) |
| 210 continue; | 213 continue; |
| 211 | 214 |
| 212 gfx::Rect visible_tile_rect = | 215 gfx::Rect visible_tile_rect = |
| 213 quad_sink->UnoccludedContentRect(tile_rect, draw_transform()); | 216 occlusion_tracker.UnoccludedContentRect(tile_rect, draw_transform()); |
| 214 if (visible_tile_rect.IsEmpty()) | 217 if (visible_tile_rect.IsEmpty()) |
| 215 continue; | 218 continue; |
| 216 | 219 |
| 217 if (!tile || !tile->resource_id()) { | 220 if (!tile || !tile->resource_id()) { |
| 218 SkColor checker_color; | 221 SkColor checker_color; |
| 219 if (ShowDebugBorders()) { | 222 if (ShowDebugBorders()) { |
| 220 checker_color = | 223 checker_color = |
| 221 tile ? DebugColors::InvalidatedTileCheckerboardColor() | 224 tile ? DebugColors::InvalidatedTileCheckerboardColor() |
| 222 : DebugColors::EvictedTileCheckerboardColor(); | 225 : DebugColors::EvictedTileCheckerboardColor(); |
| 223 } else { | 226 } else { |
| 224 checker_color = DebugColors::DefaultCheckerboardColor(); | 227 checker_color = DebugColors::DefaultCheckerboardColor(); |
| 225 } | 228 } |
| 226 | 229 |
| 227 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad = | 230 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad = |
| 228 CheckerboardDrawQuad::Create(); | 231 CheckerboardDrawQuad::Create(); |
| 229 checkerboard_quad->SetNew( | 232 checkerboard_quad->SetNew( |
| 230 shared_quad_state, tile_rect, visible_tile_rect, checker_color); | 233 shared_quad_state, tile_rect, visible_tile_rect, checker_color); |
| 231 quad_sink->Append(checkerboard_quad.PassAs<DrawQuad>()); | 234 render_pass->AppendDrawQuad(checkerboard_quad.PassAs<DrawQuad>()); |
| 232 append_quads_data->num_missing_tiles++; | 235 append_quads_data->num_missing_tiles++; |
| 233 continue; | 236 continue; |
| 234 } | 237 } |
| 235 | 238 |
| 236 gfx::Rect tile_opaque_rect = | 239 gfx::Rect tile_opaque_rect = |
| 237 contents_opaque() ? tile_rect : gfx::IntersectRects( | 240 contents_opaque() ? tile_rect : gfx::IntersectRects( |
| 238 tile->opaque_rect(), tile_rect); | 241 tile->opaque_rect(), tile_rect); |
| 239 | 242 |
| 240 // Keep track of how the top left has moved, so the texture can be | 243 // Keep track of how the top left has moved, so the texture can be |
| 241 // offset the same amount. | 244 // offset the same amount. |
| 242 gfx::Vector2d display_offset = tile_rect.origin() - display_rect.origin(); | 245 gfx::Vector2d display_offset = tile_rect.origin() - display_rect.origin(); |
| 243 gfx::Vector2d texture_offset = | 246 gfx::Vector2d texture_offset = |
| 244 tiler_->texture_offset(i, j) + display_offset; | 247 tiler_->texture_offset(i, j) + display_offset; |
| 245 gfx::RectF tex_coord_rect = gfx::RectF(tile_rect.size()) + texture_offset; | 248 gfx::RectF tex_coord_rect = gfx::RectF(tile_rect.size()) + texture_offset; |
| 246 | 249 |
| 247 float tile_width = static_cast<float>(tiler_->tile_size().width()); | 250 float tile_width = static_cast<float>(tiler_->tile_size().width()); |
| 248 float tile_height = static_cast<float>(tiler_->tile_size().height()); | 251 float tile_height = static_cast<float>(tiler_->tile_size().height()); |
| 249 gfx::Size texture_size(tile_width, tile_height); | 252 gfx::Size texture_size(tile_width, tile_height); |
| 250 | 253 |
| 251 scoped_ptr<TileDrawQuad> quad = TileDrawQuad::Create(); | 254 scoped_ptr<TileDrawQuad> quad = TileDrawQuad::Create(); |
| 252 quad->SetNew(shared_quad_state, | 255 quad->SetNew(shared_quad_state, |
| 253 tile_rect, | 256 tile_rect, |
| 254 tile_opaque_rect, | 257 tile_opaque_rect, |
| 255 visible_tile_rect, | 258 visible_tile_rect, |
| 256 tile->resource_id(), | 259 tile->resource_id(), |
| 257 tex_coord_rect, | 260 tex_coord_rect, |
| 258 texture_size, | 261 texture_size, |
| 259 tile->contents_swizzled()); | 262 tile->contents_swizzled()); |
| 260 quad_sink->Append(quad.PassAs<DrawQuad>()); | 263 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
| 261 } | 264 } |
| 262 } | 265 } |
| 263 } | 266 } |
| 264 | 267 |
| 265 void TiledLayerImpl::SetTilingData(const LayerTilingData& tiler) { | 268 void TiledLayerImpl::SetTilingData(const LayerTilingData& tiler) { |
| 266 if (tiler_) { | 269 if (tiler_) { |
| 267 tiler_->reset(); | 270 tiler_->reset(); |
| 268 } else { | 271 } else { |
| 269 tiler_ = LayerTilingData::Create(tiler.tile_size(), | 272 tiler_ = LayerTilingData::Create(tiler.tile_size(), |
| 270 tiler.has_border_texels() | 273 tiler.has_border_texels() |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 310 |
| 308 void TiledLayerImpl::ReleaseResources() { | 311 void TiledLayerImpl::ReleaseResources() { |
| 309 tiler_->reset(); | 312 tiler_->reset(); |
| 310 } | 313 } |
| 311 | 314 |
| 312 const char* TiledLayerImpl::LayerTypeAsString() const { | 315 const char* TiledLayerImpl::LayerTypeAsString() const { |
| 313 return "cc::TiledLayerImpl"; | 316 return "cc::TiledLayerImpl"; |
| 314 } | 317 } |
| 315 | 318 |
| 316 } // namespace cc | 319 } // namespace cc |
| OLD | NEW |