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(quad_sink, shared_quad_state, append_quads_data); | 167 AppendDebugBorderQuad(render_pass, shared_quad_state, append_quads_data); |
165 | 168 |
166 int left, top, right, bottom; | 169 int left, top, right, bottom; |
167 tiler_->ContentRectToTileIndices(content_rect, &left, &top, &right, &bottom); | 170 tiler_->ContentRectToTileIndices(content_rect, &left, &top, &right, &bottom); |
168 | 171 |
169 if (ShowDebugBorders()) { | 172 if (ShowDebugBorders()) { |
170 for (int j = top; j <= bottom; ++j) { | 173 for (int j = top; j <= bottom; ++j) { |
171 for (int i = left; i <= right; ++i) { | 174 for (int i = left; i <= right; ++i) { |
172 DrawableTile* tile = TileAt(i, j); | 175 DrawableTile* tile = TileAt(i, j); |
173 gfx::Rect tile_rect = tiler_->tile_bounds(i, j); | 176 gfx::Rect tile_rect = tiler_->tile_bounds(i, j); |
174 gfx::Rect visible_tile_rect = tile_rect; | 177 gfx::Rect visible_tile_rect = tile_rect; |
175 SkColor border_color; | 178 SkColor border_color; |
176 float border_width; | 179 float border_width; |
177 | 180 |
178 if (skips_draw_ || !tile || !tile->resource_id()) { | 181 if (skips_draw_ || !tile || !tile->resource_id()) { |
179 border_color = DebugColors::MissingTileBorderColor(); | 182 border_color = DebugColors::MissingTileBorderColor(); |
180 border_width = DebugColors::MissingTileBorderWidth(layer_tree_impl()); | 183 border_width = DebugColors::MissingTileBorderWidth(layer_tree_impl()); |
181 } else { | 184 } else { |
182 border_color = DebugColors::HighResTileBorderColor(); | 185 border_color = DebugColors::HighResTileBorderColor(); |
183 border_width = DebugColors::HighResTileBorderWidth(layer_tree_impl()); | 186 border_width = DebugColors::HighResTileBorderWidth(layer_tree_impl()); |
184 } | 187 } |
185 scoped_ptr<DebugBorderDrawQuad> debug_border_quad = | 188 scoped_ptr<DebugBorderDrawQuad> debug_border_quad = |
186 DebugBorderDrawQuad::Create(); | 189 DebugBorderDrawQuad::Create(); |
187 debug_border_quad->SetNew(shared_quad_state, | 190 debug_border_quad->SetNew(shared_quad_state, |
188 tile_rect, | 191 tile_rect, |
189 visible_tile_rect, | 192 visible_tile_rect, |
190 border_color, | 193 border_color, |
191 border_width); | 194 border_width); |
192 quad_sink->Append(debug_border_quad.PassAs<DrawQuad>()); | 195 render_pass->AppendDrawQuad(debug_border_quad.PassAs<DrawQuad>()); |
193 } | 196 } |
194 } | 197 } |
195 } | 198 } |
196 | 199 |
197 if (skips_draw_) | 200 if (skips_draw_) |
198 return; | 201 return; |
199 | 202 |
200 for (int j = top; j <= bottom; ++j) { | 203 for (int j = top; j <= bottom; ++j) { |
201 for (int i = left; i <= right; ++i) { | 204 for (int i = left; i <= right; ++i) { |
202 DrawableTile* tile = TileAt(i, j); | 205 DrawableTile* tile = TileAt(i, j); |
203 gfx::Rect tile_rect = tiler_->tile_bounds(i, j); | 206 gfx::Rect tile_rect = tiler_->tile_bounds(i, j); |
204 gfx::Rect display_rect = tile_rect; | 207 gfx::Rect display_rect = tile_rect; |
205 tile_rect.Intersect(content_rect); | 208 tile_rect.Intersect(content_rect); |
206 | 209 |
207 // Skip empty tiles. | 210 // Skip empty tiles. |
208 if (tile_rect.IsEmpty()) | 211 if (tile_rect.IsEmpty()) |
209 continue; | 212 continue; |
210 | 213 |
211 gfx::Rect visible_tile_rect = | 214 gfx::Rect visible_tile_rect = occlusion_tracker.UnoccludedContentRect( |
212 quad_sink->UnoccludedContentRect(this, tile_rect, draw_transform()); | 215 this->render_target(), tile_rect, draw_transform()); |
213 if (visible_tile_rect.IsEmpty()) | 216 if (visible_tile_rect.IsEmpty()) |
214 continue; | 217 continue; |
215 | 218 |
216 if (!tile || !tile->resource_id()) { | 219 if (!tile || !tile->resource_id()) { |
217 SkColor checker_color; | 220 SkColor checker_color; |
218 if (ShowDebugBorders()) { | 221 if (ShowDebugBorders()) { |
219 checker_color = | 222 checker_color = |
220 tile ? DebugColors::InvalidatedTileCheckerboardColor() | 223 tile ? DebugColors::InvalidatedTileCheckerboardColor() |
221 : DebugColors::EvictedTileCheckerboardColor(); | 224 : DebugColors::EvictedTileCheckerboardColor(); |
222 } else { | 225 } else { |
223 checker_color = DebugColors::DefaultCheckerboardColor(); | 226 checker_color = DebugColors::DefaultCheckerboardColor(); |
224 } | 227 } |
225 | 228 |
226 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad = | 229 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad = |
227 CheckerboardDrawQuad::Create(); | 230 CheckerboardDrawQuad::Create(); |
228 checkerboard_quad->SetNew( | 231 checkerboard_quad->SetNew( |
229 shared_quad_state, tile_rect, visible_tile_rect, checker_color); | 232 shared_quad_state, tile_rect, visible_tile_rect, checker_color); |
230 quad_sink->Append(checkerboard_quad.PassAs<DrawQuad>()); | 233 render_pass->AppendDrawQuad(checkerboard_quad.PassAs<DrawQuad>()); |
231 append_quads_data->num_missing_tiles++; | 234 append_quads_data->num_missing_tiles++; |
232 continue; | 235 continue; |
233 } | 236 } |
234 | 237 |
235 gfx::Rect tile_opaque_rect = | 238 gfx::Rect tile_opaque_rect = |
236 contents_opaque() ? tile_rect : gfx::IntersectRects( | 239 contents_opaque() ? tile_rect : gfx::IntersectRects( |
237 tile->opaque_rect(), tile_rect); | 240 tile->opaque_rect(), tile_rect); |
238 | 241 |
239 // Keep track of how the top left has moved, so the texture can be | 242 // Keep track of how the top left has moved, so the texture can be |
240 // offset the same amount. | 243 // offset the same amount. |
241 gfx::Vector2d display_offset = tile_rect.origin() - display_rect.origin(); | 244 gfx::Vector2d display_offset = tile_rect.origin() - display_rect.origin(); |
242 gfx::Vector2d texture_offset = | 245 gfx::Vector2d texture_offset = |
243 tiler_->texture_offset(i, j) + display_offset; | 246 tiler_->texture_offset(i, j) + display_offset; |
244 gfx::RectF tex_coord_rect = gfx::RectF(tile_rect.size()) + texture_offset; | 247 gfx::RectF tex_coord_rect = gfx::RectF(tile_rect.size()) + texture_offset; |
245 | 248 |
246 float tile_width = static_cast<float>(tiler_->tile_size().width()); | 249 float tile_width = static_cast<float>(tiler_->tile_size().width()); |
247 float tile_height = static_cast<float>(tiler_->tile_size().height()); | 250 float tile_height = static_cast<float>(tiler_->tile_size().height()); |
248 gfx::Size texture_size(tile_width, tile_height); | 251 gfx::Size texture_size(tile_width, tile_height); |
249 | 252 |
250 scoped_ptr<TileDrawQuad> quad = TileDrawQuad::Create(); | 253 scoped_ptr<TileDrawQuad> quad = TileDrawQuad::Create(); |
251 quad->SetNew(shared_quad_state, | 254 quad->SetNew(shared_quad_state, |
252 tile_rect, | 255 tile_rect, |
253 tile_opaque_rect, | 256 tile_opaque_rect, |
254 visible_tile_rect, | 257 visible_tile_rect, |
255 tile->resource_id(), | 258 tile->resource_id(), |
256 tex_coord_rect, | 259 tex_coord_rect, |
257 texture_size, | 260 texture_size, |
258 tile->contents_swizzled()); | 261 tile->contents_swizzled()); |
259 quad_sink->Append(quad.PassAs<DrawQuad>()); | 262 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
260 } | 263 } |
261 } | 264 } |
262 } | 265 } |
263 | 266 |
264 void TiledLayerImpl::SetTilingData(const LayerTilingData& tiler) { | 267 void TiledLayerImpl::SetTilingData(const LayerTilingData& tiler) { |
265 if (tiler_) { | 268 if (tiler_) { |
266 tiler_->reset(); | 269 tiler_->reset(); |
267 } else { | 270 } else { |
268 tiler_ = LayerTilingData::Create(tiler.tile_size(), | 271 tiler_ = LayerTilingData::Create(tiler.tile_size(), |
269 tiler.has_border_texels() | 272 tiler.has_border_texels() |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 309 |
307 void TiledLayerImpl::ReleaseResources() { | 310 void TiledLayerImpl::ReleaseResources() { |
308 tiler_->reset(); | 311 tiler_->reset(); |
309 } | 312 } |
310 | 313 |
311 const char* TiledLayerImpl::LayerTypeAsString() const { | 314 const char* TiledLayerImpl::LayerTypeAsString() const { |
312 return "cc::TiledLayerImpl"; | 315 return "cc::TiledLayerImpl"; |
313 } | 316 } |
314 | 317 |
315 } // namespace cc | 318 } // namespace cc |
OLD | NEW |