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

Side by Side Diff: ui/compositor/compositor.cc

Issue 10689108: Aura: Have ui::Layer implement WebKit::WebExternalTextureLayerClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address reviewer comments, remove dead code, plumb through context. Created 8 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 | Annotate | Revision Log
OLDNEW
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
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);
176
177 // Stop all outstanding draws before telling the ContextFactory to tear
178 // down any contexts that the host_ may rely upon.
179 host_.reset();
180
173 if (!test_compositor_enabled) 181 if (!test_compositor_enabled)
174 ContextFactory::GetInstance()->RemoveCompositor(this); 182 ContextFactory::GetInstance()->RemoveCompositor(this);
175 } 183 }
176 184
177 void Compositor::Initialize(bool use_thread) { 185 void Compositor::Initialize(bool use_thread) {
178 #if defined(WEBCOMPOSITOR_OWNS_SETTINGS) 186 #if defined(WEBCOMPOSITOR_OWNS_SETTINGS)
179 CommandLine* command_line = CommandLine::ForCurrentProcess(); 187 CommandLine* command_line = CommandLine::ForCurrentProcess();
180 // These settings must be applied before we initialize the compositor. 188 // These settings must be applied before we initialize the compositor.
181 WebKit::WebCompositor::setPartialSwapEnabled( 189 WebKit::WebCompositor::setPartialSwapEnabled(
182 command_line->HasSwitch(switches::kUIEnablePartialSwap)); 190 command_line->HasSwitch(switches::kUIEnablePartialSwap));
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 test_context->Initialize(); 343 test_context->Initialize();
336 return test_context; 344 return test_context;
337 } else { 345 } else {
338 return ContextFactory::GetInstance()->CreateContext(this); 346 return ContextFactory::GetInstance()->CreateContext(this);
339 } 347 }
340 } 348 }
341 349
342 void Compositor::didRebindGraphicsContext(bool success) { 350 void Compositor::didRebindGraphicsContext(bool success) {
343 } 351 }
344 352
353 // Called once per draw in single-threaded compositor mode and potentially
354 // many times between draws in the multi-threaded compositor mode.
355 void Compositor::didCommit() {
356 for (std::vector< base::Callback<void(Compositor*)> >::const_iterator
357 it = did_commit_callbacks_.begin();
358 it != did_commit_callbacks_.end(); ++it) {
359 it->Run(this);
piman 2012/07/12 00:18:09 btw, you run the risk of the closure modifying did
360 }
361 did_commit_callbacks_.clear();
362 }
363
345 void Compositor::didCommitAndDrawFrame() { 364 void Compositor::didCommitAndDrawFrame() {
346 // TODO(backer): Plumb through an earlier impl side will start. 365 // TODO(backer): Plumb through an earlier impl side will start.
347 if (g_compositor_thread) 366 if (g_compositor_thread)
348 FOR_EACH_OBSERVER(CompositorObserver, 367 FOR_EACH_OBSERVER(CompositorObserver,
349 observer_list_, 368 observer_list_,
350 OnCompositingWillStart(this)); 369 OnCompositingWillStart(this));
351 370
352 FOR_EACH_OBSERVER(CompositorObserver, 371 FOR_EACH_OBSERVER(CompositorObserver,
353 observer_list_, 372 observer_list_,
354 OnCompositingStarted(this)); 373 OnCompositingStarted(this));
355 } 374 }
356 375
357 void Compositor::didCompleteSwapBuffers() { 376 void Compositor::didCompleteSwapBuffers() {
358 NotifyEnd(); 377 NotifyEnd();
359 } 378 }
360 379
361 void Compositor::scheduleComposite() { 380 void Compositor::scheduleComposite() {
362 if (!disable_schedule_composite_) 381 if (!disable_schedule_composite_)
363 ScheduleDraw(); 382 ScheduleDraw();
364 } 383 }
365 384
385 void Compositor::AddDidCommitCallback(
386 const base::Callback<void(ui::Compositor*)>& callback) {
387 did_commit_callbacks_.push_back(callback);
388 }
389
366 void Compositor::SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, 390 void Compositor::SwizzleRGBAToBGRAAndFlip(unsigned char* pixels,
367 const gfx::Size& image_size) { 391 const gfx::Size& image_size) {
368 // Swizzle from RGBA to BGRA 392 // Swizzle from RGBA to BGRA
369 size_t bitmap_size = 4 * image_size.width() * image_size.height(); 393 size_t bitmap_size = 4 * image_size.width() * image_size.height();
370 for (size_t i = 0; i < bitmap_size; i += 4) 394 for (size_t i = 0; i < bitmap_size; i += 4)
371 std::swap(pixels[i], pixels[i + 2]); 395 std::swap(pixels[i], pixels[i + 2]);
372 396
373 // Vertical flip to transform from GL co-ords 397 // Vertical flip to transform from GL co-ords
374 size_t row_size = 4 * image_size.width(); 398 size_t row_size = 4 * image_size.width();
375 scoped_array<unsigned char> tmp_row(new unsigned char[row_size]); 399 scoped_array<unsigned char> tmp_row(new unsigned char[row_size]);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 432
409 COMPOSITOR_EXPORT void DisableTestCompositor() { 433 COMPOSITOR_EXPORT void DisableTestCompositor() {
410 test_compositor_enabled = false; 434 test_compositor_enabled = false;
411 } 435 }
412 436
413 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { 437 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() {
414 return test_compositor_enabled; 438 return test_compositor_enabled;
415 } 439 }
416 440
417 } // namespace ui 441 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698