| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 root_layer_->SetCompositor(this); | 200 root_layer_->SetCompositor(this); |
| 198 root_web_layer_.removeAllChildren(); | 201 root_web_layer_.removeAllChildren(); |
| 199 if (root_layer_) | 202 if (root_layer_) |
| 200 root_web_layer_.addChild(root_layer_->web_layer()); | 203 root_web_layer_.addChild(root_layer_->web_layer()); |
| 201 } | 204 } |
| 202 | 205 |
| 203 void Compositor::Draw(bool force_clear) { | 206 void Compositor::Draw(bool force_clear) { |
| 204 if (!root_layer_) | 207 if (!root_layer_) |
| 205 return; | 208 return; |
| 206 | 209 |
| 210 last_started_frame_++; |
| 211 |
| 207 // TODO(nduca): Temporary while compositor calls | 212 // TODO(nduca): Temporary while compositor calls |
| 208 // compositeImmediately() directly. | 213 // compositeImmediately() directly. |
| 209 layout(); | 214 layout(); |
| 210 host_.composite(); | 215 host_.composite(); |
| 211 if (!g_compositor_thread && !swap_posted_) | 216 if (!g_compositor_thread && !swap_posted_) |
| 212 NotifyEnd(); | 217 NotifyEnd(); |
| 213 } | 218 } |
| 214 | 219 |
| 215 void Compositor::ScheduleFullDraw() { | 220 void Compositor::ScheduleFullDraw() { |
| 216 host_.setNeedsRedraw(); | 221 host_.setNeedsRedraw(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 288 } |
| 284 FOR_EACH_OBSERVER(CompositorObserver, | 289 FOR_EACH_OBSERVER(CompositorObserver, |
| 285 observer_list_, | 290 observer_list_, |
| 286 OnCompositingAborted(this)); | 291 OnCompositingAborted(this)); |
| 287 } | 292 } |
| 288 | 293 |
| 289 void Compositor::updateAnimations(double frameBeginTime) { | 294 void Compositor::updateAnimations(double frameBeginTime) { |
| 290 } | 295 } |
| 291 | 296 |
| 292 void Compositor::layout() { | 297 void Compositor::layout() { |
| 298 // We're sending damage that will be addressed during this composite |
| 299 // cycle, so we don't need to schedule another composite to address it. |
| 300 disable_schedule_composite_ = true; |
| 293 if (root_layer_) | 301 if (root_layer_) |
| 294 root_layer_->SendDamagedRects(); | 302 root_layer_->SendDamagedRects(); |
| 303 disable_schedule_composite_ = false; |
| 295 } | 304 } |
| 296 | 305 |
| 297 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, | 306 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, |
| 298 float scaleFactor) { | 307 float scaleFactor) { |
| 299 } | 308 } |
| 300 | 309 |
| 301 WebKit::WebGraphicsContext3D* Compositor::createContext3D() { | 310 WebKit::WebGraphicsContext3D* Compositor::createContext3D() { |
| 302 if (test_compositor_enabled) { | 311 if (test_compositor_enabled) { |
| 303 ui::TestWebGraphicsContext3D* test_context = | 312 ui::TestWebGraphicsContext3D* test_context = |
| 304 new ui::TestWebGraphicsContext3D(); | 313 new ui::TestWebGraphicsContext3D(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 316 FOR_EACH_OBSERVER(CompositorObserver, | 325 FOR_EACH_OBSERVER(CompositorObserver, |
| 317 observer_list_, | 326 observer_list_, |
| 318 OnCompositingStarted(this)); | 327 OnCompositingStarted(this)); |
| 319 } | 328 } |
| 320 | 329 |
| 321 void Compositor::didCompleteSwapBuffers() { | 330 void Compositor::didCompleteSwapBuffers() { |
| 322 NotifyEnd(); | 331 NotifyEnd(); |
| 323 } | 332 } |
| 324 | 333 |
| 325 void Compositor::scheduleComposite() { | 334 void Compositor::scheduleComposite() { |
| 326 ScheduleDraw(); | 335 if (!disable_schedule_composite_) |
| 336 ScheduleDraw(); |
| 327 } | 337 } |
| 328 | 338 |
| 329 void Compositor::SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, | 339 void Compositor::SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, |
| 330 const gfx::Size& image_size) { | 340 const gfx::Size& image_size) { |
| 331 // Swizzle from RGBA to BGRA | 341 // Swizzle from RGBA to BGRA |
| 332 size_t bitmap_size = 4 * image_size.width() * image_size.height(); | 342 size_t bitmap_size = 4 * image_size.width() * image_size.height(); |
| 333 for(size_t i = 0; i < bitmap_size; i += 4) | 343 for(size_t i = 0; i < bitmap_size; i += 4) |
| 334 std::swap(pixels[i], pixels[i + 2]); | 344 std::swap(pixels[i], pixels[i + 2]); |
| 335 | 345 |
| 336 // Vertical flip to transform from GL co-ords | 346 // Vertical flip to transform from GL co-ords |
| 337 size_t row_size = 4 * image_size.width(); | 347 size_t row_size = 4 * image_size.width(); |
| 338 scoped_array<unsigned char> tmp_row(new unsigned char[row_size]); | 348 scoped_array<unsigned char> tmp_row(new unsigned char[row_size]); |
| 339 for(int row = 0; row < image_size.height() / 2; row++) { | 349 for(int row = 0; row < image_size.height() / 2; row++) { |
| 340 memcpy(tmp_row.get(), | 350 memcpy(tmp_row.get(), |
| 341 &pixels[row * row_size], | 351 &pixels[row * row_size], |
| 342 row_size); | 352 row_size); |
| 343 memcpy(&pixels[row * row_size], | 353 memcpy(&pixels[row * row_size], |
| 344 &pixels[bitmap_size - (row + 1) * row_size], | 354 &pixels[bitmap_size - (row + 1) * row_size], |
| 345 row_size); | 355 row_size); |
| 346 memcpy(&pixels[bitmap_size - (row + 1) * row_size], | 356 memcpy(&pixels[bitmap_size - (row + 1) * row_size], |
| 347 tmp_row.get(), | 357 tmp_row.get(), |
| 348 row_size); | 358 row_size); |
| 349 } | 359 } |
| 350 } | 360 } |
| 351 | 361 |
| 352 void Compositor::NotifyEnd() { | 362 void Compositor::NotifyEnd() { |
| 363 last_ended_frame_++; |
| 353 FOR_EACH_OBSERVER(CompositorObserver, | 364 FOR_EACH_OBSERVER(CompositorObserver, |
| 354 observer_list_, | 365 observer_list_, |
| 355 OnCompositingEnded(this)); | 366 OnCompositingEnded(this)); |
| 356 } | 367 } |
| 357 | 368 |
| 358 COMPOSITOR_EXPORT void SetupTestCompositor() { | 369 COMPOSITOR_EXPORT void SetupTestCompositor() { |
| 359 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 370 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 360 switches::kDisableTestCompositor)) { | 371 switches::kDisableTestCompositor)) { |
| 361 test_compositor_enabled = true; | 372 test_compositor_enabled = true; |
| 362 } | 373 } |
| 363 #if defined(OS_CHROMEOS) | 374 #if defined(OS_CHROMEOS) |
| 364 // If the test is running on the chromeos envrionment (such as | 375 // If the test is running on the chromeos envrionment (such as |
| 365 // device or vm bots), use the real compositor. | 376 // device or vm bots), use the real compositor. |
| 366 if (base::chromeos::IsRunningOnChromeOS()) | 377 if (base::chromeos::IsRunningOnChromeOS()) |
| 367 test_compositor_enabled = false; | 378 test_compositor_enabled = false; |
| 368 #endif | 379 #endif |
| 369 } | 380 } |
| 370 | 381 |
| 371 COMPOSITOR_EXPORT void DisableTestCompositor() { | 382 COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 372 test_compositor_enabled = false; | 383 test_compositor_enabled = false; |
| 373 } | 384 } |
| 374 | 385 |
| 375 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 386 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 376 return test_compositor_enabled; | 387 return test_compositor_enabled; |
| 377 } | 388 } |
| 378 | 389 |
| 379 } // namespace ui | 390 } // namespace ui |
| OLD | NEW |