Chromium Code Reviews| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoin t.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoin t.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 Texture::~Texture() { | 124 Texture::~Texture() { |
| 125 } | 125 } |
| 126 | 126 |
| 127 Compositor::Compositor(CompositorDelegate* delegate, | 127 Compositor::Compositor(CompositorDelegate* delegate, |
| 128 gfx::AcceleratedWidget widget) | 128 gfx::AcceleratedWidget widget) |
| 129 : delegate_(delegate), | 129 : delegate_(delegate), |
| 130 root_layer_(NULL), | 130 root_layer_(NULL), |
| 131 widget_(widget), | 131 widget_(widget), |
| 132 root_web_layer_(WebKit::WebLayer::create()), | 132 root_web_layer_(WebKit::WebLayer::create()), |
| 133 swap_posted_(false), | 133 swap_posted_(false), |
| 134 device_scale_factor_(0.0f) { | 134 device_scale_factor_(0.0f), |
| 135 last_started_frame_(0), | |
| 136 last_ended_frame_(0), | |
| 137 disable_schedule_composite_(false) { | |
| 135 WebKit::WebLayerTreeView::Settings settings; | 138 WebKit::WebLayerTreeView::Settings settings; |
| 136 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 139 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 137 settings.showFPSCounter = | 140 settings.showFPSCounter = |
| 138 command_line->HasSwitch(switches::kUIShowFPSCounter); | 141 command_line->HasSwitch(switches::kUIShowFPSCounter); |
| 139 settings.showPlatformLayerTree = | 142 settings.showPlatformLayerTree = |
| 140 command_line->HasSwitch(switches::kUIShowLayerTree); | 143 command_line->HasSwitch(switches::kUIShowLayerTree); |
| 141 settings.refreshRate = test_compositor_enabled ? | 144 settings.refreshRate = test_compositor_enabled ? |
| 142 kTestRefreshRate : kDefaultRefreshRate; | 145 kTestRefreshRate : kDefaultRefreshRate; |
| 143 settings.partialSwapEnabled = | 146 settings.partialSwapEnabled = |
| 144 command_line->HasSwitch(switches::kUIEnablePartialSwap); | 147 command_line->HasSwitch(switches::kUIEnablePartialSwap); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 171 void Compositor::Terminate() { | 174 void Compositor::Terminate() { |
| 172 WebKit::WebCompositor::shutdown(); | 175 WebKit::WebCompositor::shutdown(); |
| 173 if (g_compositor_thread) { | 176 if (g_compositor_thread) { |
| 174 delete g_compositor_thread; | 177 delete g_compositor_thread; |
| 175 g_compositor_thread = NULL; | 178 g_compositor_thread = NULL; |
| 176 } | 179 } |
| 177 } | 180 } |
| 178 | 181 |
| 179 void Compositor::ScheduleDraw() { | 182 void Compositor::ScheduleDraw() { |
| 180 if (g_compositor_thread) { | 183 if (g_compositor_thread) { |
| 184 disable_schedule_composite_ = true; | |
|
piman
2012/06/06 20:17:24
nit: it's probably not useful to do this here, sin
jonathan.backer
2012/06/06 20:31:43
Thanks. Tried to squeeze this in before a meeting.
| |
| 181 // TODO(nduca): Temporary while compositor calls | 185 // TODO(nduca): Temporary while compositor calls |
| 182 // compositeImmediately() directly. | 186 // compositeImmediately() directly. |
| 183 layout(); | 187 layout(); |
| 188 disable_schedule_composite_ = false; | |
| 184 host_.composite(); | 189 host_.composite(); |
| 185 } else if (delegate_) { | 190 } else if (delegate_) { |
| 186 delegate_->ScheduleDraw(); | 191 delegate_->ScheduleDraw(); |
| 187 } | 192 } |
| 188 } | 193 } |
| 189 | 194 |
| 190 void Compositor::SetRootLayer(Layer* root_layer) { | 195 void Compositor::SetRootLayer(Layer* root_layer) { |
| 191 if (root_layer_ == root_layer) | 196 if (root_layer_ == root_layer) |
| 192 return; | 197 return; |
| 193 if (root_layer_) | 198 if (root_layer_) |
| 194 root_layer_->SetCompositor(NULL); | 199 root_layer_->SetCompositor(NULL); |
| 195 root_layer_ = root_layer; | 200 root_layer_ = root_layer; |
| 196 if (root_layer_ && !root_layer_->GetCompositor()) | 201 if (root_layer_ && !root_layer_->GetCompositor()) |
| 197 root_layer_->SetCompositor(this); | 202 root_layer_->SetCompositor(this); |
| 198 root_web_layer_.removeAllChildren(); | 203 root_web_layer_.removeAllChildren(); |
| 199 if (root_layer_) | 204 if (root_layer_) |
| 200 root_web_layer_.addChild(root_layer_->web_layer()); | 205 root_web_layer_.addChild(root_layer_->web_layer()); |
| 201 } | 206 } |
| 202 | 207 |
| 203 void Compositor::Draw(bool force_clear) { | 208 void Compositor::Draw(bool force_clear) { |
| 204 if (!root_layer_) | 209 if (!root_layer_) |
| 205 return; | 210 return; |
| 206 | 211 |
| 212 last_started_frame_++; | |
| 213 | |
| 207 // TODO(nduca): Temporary while compositor calls | 214 // TODO(nduca): Temporary while compositor calls |
| 208 // compositeImmediately() directly. | 215 // compositeImmediately() directly. |
| 209 layout(); | 216 layout(); |
| 210 host_.composite(); | 217 host_.composite(); |
| 211 if (!g_compositor_thread && !swap_posted_) | 218 if (!g_compositor_thread && !swap_posted_) |
| 212 NotifyEnd(); | 219 NotifyEnd(); |
| 213 } | 220 } |
| 214 | 221 |
| 215 void Compositor::ScheduleFullDraw() { | 222 void Compositor::ScheduleFullDraw() { |
| 216 host_.setNeedsRedraw(); | 223 host_.setNeedsRedraw(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 } | 290 } |
| 284 FOR_EACH_OBSERVER(CompositorObserver, | 291 FOR_EACH_OBSERVER(CompositorObserver, |
| 285 observer_list_, | 292 observer_list_, |
| 286 OnCompositingAborted(this)); | 293 OnCompositingAborted(this)); |
| 287 } | 294 } |
| 288 | 295 |
| 289 void Compositor::updateAnimations(double frameBeginTime) { | 296 void Compositor::updateAnimations(double frameBeginTime) { |
| 290 } | 297 } |
| 291 | 298 |
| 292 void Compositor::layout() { | 299 void Compositor::layout() { |
| 300 // We're sending damage that will be addressed during this composite | |
| 301 // cycle, so we don't need to schedule another composite to address it. | |
| 302 disable_schedule_composite_ = true; | |
| 293 if (root_layer_) | 303 if (root_layer_) |
| 294 root_layer_->SendDamagedRects(); | 304 root_layer_->SendDamagedRects(); |
| 305 disable_schedule_composite_ = false; | |
| 295 } | 306 } |
| 296 | 307 |
| 297 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, | 308 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, |
| 298 float scaleFactor) { | 309 float scaleFactor) { |
| 299 } | 310 } |
| 300 | 311 |
| 301 WebKit::WebGraphicsContext3D* Compositor::createContext3D() { | 312 WebKit::WebGraphicsContext3D* Compositor::createContext3D() { |
| 302 if (test_compositor_enabled) { | 313 if (test_compositor_enabled) { |
| 303 ui::TestWebGraphicsContext3D* test_context = | 314 ui::TestWebGraphicsContext3D* test_context = |
| 304 new ui::TestWebGraphicsContext3D(); | 315 new ui::TestWebGraphicsContext3D(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 316 FOR_EACH_OBSERVER(CompositorObserver, | 327 FOR_EACH_OBSERVER(CompositorObserver, |
| 317 observer_list_, | 328 observer_list_, |
| 318 OnCompositingStarted(this)); | 329 OnCompositingStarted(this)); |
| 319 } | 330 } |
| 320 | 331 |
| 321 void Compositor::didCompleteSwapBuffers() { | 332 void Compositor::didCompleteSwapBuffers() { |
| 322 NotifyEnd(); | 333 NotifyEnd(); |
| 323 } | 334 } |
| 324 | 335 |
| 325 void Compositor::scheduleComposite() { | 336 void Compositor::scheduleComposite() { |
| 326 ScheduleDraw(); | 337 if (!disable_schedule_composite_) |
| 338 ScheduleDraw(); | |
| 327 } | 339 } |
| 328 | 340 |
| 329 void Compositor::SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, | 341 void Compositor::SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, |
| 330 const gfx::Size& image_size) { | 342 const gfx::Size& image_size) { |
| 331 // Swizzle from RGBA to BGRA | 343 // Swizzle from RGBA to BGRA |
| 332 size_t bitmap_size = 4 * image_size.width() * image_size.height(); | 344 size_t bitmap_size = 4 * image_size.width() * image_size.height(); |
| 333 for(size_t i = 0; i < bitmap_size; i += 4) | 345 for(size_t i = 0; i < bitmap_size; i += 4) |
| 334 std::swap(pixels[i], pixels[i + 2]); | 346 std::swap(pixels[i], pixels[i + 2]); |
| 335 | 347 |
| 336 // Vertical flip to transform from GL co-ords | 348 // Vertical flip to transform from GL co-ords |
| 337 size_t row_size = 4 * image_size.width(); | 349 size_t row_size = 4 * image_size.width(); |
| 338 scoped_array<unsigned char> tmp_row(new unsigned char[row_size]); | 350 scoped_array<unsigned char> tmp_row(new unsigned char[row_size]); |
| 339 for(int row = 0; row < image_size.height() / 2; row++) { | 351 for(int row = 0; row < image_size.height() / 2; row++) { |
| 340 memcpy(tmp_row.get(), | 352 memcpy(tmp_row.get(), |
| 341 &pixels[row * row_size], | 353 &pixels[row * row_size], |
| 342 row_size); | 354 row_size); |
| 343 memcpy(&pixels[row * row_size], | 355 memcpy(&pixels[row * row_size], |
| 344 &pixels[bitmap_size - (row + 1) * row_size], | 356 &pixels[bitmap_size - (row + 1) * row_size], |
| 345 row_size); | 357 row_size); |
| 346 memcpy(&pixels[bitmap_size - (row + 1) * row_size], | 358 memcpy(&pixels[bitmap_size - (row + 1) * row_size], |
| 347 tmp_row.get(), | 359 tmp_row.get(), |
| 348 row_size); | 360 row_size); |
| 349 } | 361 } |
| 350 } | 362 } |
| 351 | 363 |
| 352 void Compositor::NotifyEnd() { | 364 void Compositor::NotifyEnd() { |
| 365 last_ended_frame_++; | |
| 353 FOR_EACH_OBSERVER(CompositorObserver, | 366 FOR_EACH_OBSERVER(CompositorObserver, |
| 354 observer_list_, | 367 observer_list_, |
| 355 OnCompositingEnded(this)); | 368 OnCompositingEnded(this)); |
| 356 } | 369 } |
| 357 | 370 |
| 358 COMPOSITOR_EXPORT void SetupTestCompositor() { | 371 COMPOSITOR_EXPORT void SetupTestCompositor() { |
| 359 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 372 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 360 switches::kDisableTestCompositor)) { | 373 switches::kDisableTestCompositor)) { |
| 361 test_compositor_enabled = true; | 374 test_compositor_enabled = true; |
| 362 } | 375 } |
| 363 #if defined(OS_CHROMEOS) | 376 #if defined(OS_CHROMEOS) |
| 364 // If the test is running on the chromeos envrionment (such as | 377 // If the test is running on the chromeos envrionment (such as |
| 365 // device or vm bots), use the real compositor. | 378 // device or vm bots), use the real compositor. |
| 366 if (base::chromeos::IsRunningOnChromeOS()) | 379 if (base::chromeos::IsRunningOnChromeOS()) |
| 367 test_compositor_enabled = false; | 380 test_compositor_enabled = false; |
| 368 #endif | 381 #endif |
| 369 } | 382 } |
| 370 | 383 |
| 371 COMPOSITOR_EXPORT void DisableTestCompositor() { | 384 COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 372 test_compositor_enabled = false; | 385 test_compositor_enabled = false; |
| 373 } | 386 } |
| 374 | 387 |
| 375 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 388 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 376 return test_compositor_enabled; | 389 return test_compositor_enabled; |
| 377 } | 390 } |
| 378 | 391 |
| 379 } // namespace ui | 392 } // namespace ui |
| OLD | NEW |