OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/compositor/compositor.h" | 5 #include "ui/compositor/compositor.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 settings.perTilePainting = | 155 settings.perTilePainting = |
156 command_line->HasSwitch(switches::kUIEnablePerTilePainting); | 156 command_line->HasSwitch(switches::kUIEnablePerTilePainting); |
157 #endif | 157 #endif |
158 | 158 |
159 host_.initialize(this, root_web_layer_, settings); | 159 host_.initialize(this, root_web_layer_, settings); |
160 host_.setSurfaceReady(); | 160 host_.setSurfaceReady(); |
161 root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 161 root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
162 } | 162 } |
163 | 163 |
164 Compositor::~Compositor() { | 164 Compositor::~Compositor() { |
165 // Clear out any pending callbacks. | |
166 didCommit(); | |
167 | |
165 // Don't call |CompositorDelegate::ScheduleDraw| from this point. | 168 // Don't call |CompositorDelegate::ScheduleDraw| from this point. |
166 delegate_ = NULL; | 169 delegate_ = NULL; |
167 // There's a cycle between |root_web_layer_| and |host_|, which results in | 170 // There's a cycle between |root_web_layer_| and |host_|, which results in |
168 // leaking and/or crashing. Explicitly set the root layer to NULL so the cycle | 171 // leaking and/or crashing. Explicitly set the root layer to NULL so the cycle |
169 // is broken. | 172 // is broken. |
170 host_.setRootLayer(NULL); | 173 host_.setRootLayer(NULL); |
171 if (root_layer_) | 174 if (root_layer_) |
172 root_layer_->SetCompositor(NULL); | 175 root_layer_->SetCompositor(NULL); |
173 if (!test_compositor_enabled) | 176 if (!test_compositor_enabled) |
174 ContextFactory::GetInstance()->RemoveCompositor(this); | 177 ContextFactory::GetInstance()->RemoveCompositor(this); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 test_context->Initialize(); | 338 test_context->Initialize(); |
336 return test_context; | 339 return test_context; |
337 } else { | 340 } else { |
338 return ContextFactory::GetInstance()->CreateContext(this); | 341 return ContextFactory::GetInstance()->CreateContext(this); |
339 } | 342 } |
340 } | 343 } |
341 | 344 |
342 void Compositor::didRebindGraphicsContext(bool success) { | 345 void Compositor::didRebindGraphicsContext(bool success) { |
343 } | 346 } |
344 | 347 |
348 void Compositor::didCommit() { | |
piman
2012/07/09 22:40:01
Can you add a comment that this is only called in
jonathan.backer
2012/07/11 21:02:03
I was wrong. It's not. But it's only called during
| |
349 for (std::vector< base::Callback<void(Compositor*)> >::const_iterator | |
350 it = did_commit_callbacks_.begin(); | |
351 it != did_commit_callbacks_.end(); ++it) { | |
352 it->Run(this); | |
353 } | |
354 did_commit_callbacks_.clear(); | |
355 } | |
356 | |
345 void Compositor::didCommitAndDrawFrame() { | 357 void Compositor::didCommitAndDrawFrame() { |
346 // TODO(backer): Plumb through an earlier impl side will start. | 358 // TODO(backer): Plumb through an earlier impl side will start. |
347 if (g_compositor_thread) | 359 if (g_compositor_thread) |
348 FOR_EACH_OBSERVER(CompositorObserver, | 360 FOR_EACH_OBSERVER(CompositorObserver, |
349 observer_list_, | 361 observer_list_, |
350 OnCompositingWillStart(this)); | 362 OnCompositingWillStart(this)); |
351 | 363 |
352 FOR_EACH_OBSERVER(CompositorObserver, | 364 FOR_EACH_OBSERVER(CompositorObserver, |
353 observer_list_, | 365 observer_list_, |
354 OnCompositingStarted(this)); | 366 OnCompositingStarted(this)); |
355 } | 367 } |
356 | 368 |
357 void Compositor::didCompleteSwapBuffers() { | 369 void Compositor::didCompleteSwapBuffers() { |
358 NotifyEnd(); | 370 NotifyEnd(); |
359 } | 371 } |
360 | 372 |
361 void Compositor::scheduleComposite() { | 373 void Compositor::scheduleComposite() { |
362 if (!disable_schedule_composite_) | 374 if (!disable_schedule_composite_) |
363 ScheduleDraw(); | 375 ScheduleDraw(); |
364 } | 376 } |
365 | 377 |
378 void Compositor::AddDidCommitCallback( | |
379 const base::Callback<void(ui::Compositor*)>& callback) { | |
380 if (g_compositor_thread) | |
381 did_commit_callbacks_.push_back(callback); | |
382 else | |
383 callback.Run(this); | |
384 } | |
385 | |
366 void Compositor::SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, | 386 void Compositor::SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, |
367 const gfx::Size& image_size) { | 387 const gfx::Size& image_size) { |
368 // Swizzle from RGBA to BGRA | 388 // Swizzle from RGBA to BGRA |
369 size_t bitmap_size = 4 * image_size.width() * image_size.height(); | 389 size_t bitmap_size = 4 * image_size.width() * image_size.height(); |
370 for (size_t i = 0; i < bitmap_size; i += 4) | 390 for (size_t i = 0; i < bitmap_size; i += 4) |
371 std::swap(pixels[i], pixels[i + 2]); | 391 std::swap(pixels[i], pixels[i + 2]); |
372 | 392 |
373 // Vertical flip to transform from GL co-ords | 393 // Vertical flip to transform from GL co-ords |
374 size_t row_size = 4 * image_size.width(); | 394 size_t row_size = 4 * image_size.width(); |
375 scoped_array<unsigned char> tmp_row(new unsigned char[row_size]); | 395 scoped_array<unsigned char> tmp_row(new unsigned char[row_size]); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 | 428 |
409 COMPOSITOR_EXPORT void DisableTestCompositor() { | 429 COMPOSITOR_EXPORT void DisableTestCompositor() { |
410 test_compositor_enabled = false; | 430 test_compositor_enabled = false; |
411 } | 431 } |
412 | 432 |
413 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 433 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
414 return test_compositor_enabled; | 434 return test_compositor_enabled; |
415 } | 435 } |
416 | 436 |
417 } // namespace ui | 437 } // namespace ui |
OLD | NEW |