| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 disable_schedule_composite_(false) { | 146 disable_schedule_composite_(false) { |
| 147 WebKit::WebLayerTreeView::Settings settings; | 147 WebKit::WebLayerTreeView::Settings settings; |
| 148 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 148 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 149 settings.showFPSCounter = | 149 settings.showFPSCounter = |
| 150 command_line->HasSwitch(switches::kUIShowFPSCounter); | 150 command_line->HasSwitch(switches::kUIShowFPSCounter); |
| 151 settings.showPlatformLayerTree = | 151 settings.showPlatformLayerTree = |
| 152 command_line->HasSwitch(switches::kUIShowLayerTree); | 152 command_line->HasSwitch(switches::kUIShowLayerTree); |
| 153 settings.refreshRate = | 153 settings.refreshRate = |
| 154 test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate; | 154 test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate; |
| 155 | 155 |
| 156 root_web_layer_->setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
| 157 #if defined(WEBLAYERTREEVIEW_IS_PURE_VIRTUAL) |
| 158 host_.reset(WebKit::WebLayerTreeView::create(this, *root_web_layer_, |
| 159 settings)); |
| 160 host_->setSurfaceReady(); |
| 161 #else |
| 156 host_.initialize(this, *root_web_layer_, settings); | 162 host_.initialize(this, *root_web_layer_, settings); |
| 157 root_web_layer_->setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | |
| 158 host_.setSurfaceReady(); | 163 host_.setSurfaceReady(); |
| 164 #endif |
| 159 } | 165 } |
| 160 | 166 |
| 161 Compositor::~Compositor() { | 167 Compositor::~Compositor() { |
| 162 // Don't call |CompositorDelegate::ScheduleDraw| from this point. | 168 // Don't call |CompositorDelegate::ScheduleDraw| from this point. |
| 163 delegate_ = NULL; | 169 delegate_ = NULL; |
| 164 if (root_layer_) | 170 if (root_layer_) |
| 165 root_layer_->SetCompositor(NULL); | 171 root_layer_->SetCompositor(NULL); |
| 166 | 172 |
| 167 // Stop all outstanding draws before telling the ContextFactory to tear | 173 // Stop all outstanding draws before telling the ContextFactory to tear |
| 168 // down any contexts that the |host_| may rely upon. | 174 // down any contexts that the |host_| may rely upon. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 190 delete g_compositor_thread; | 196 delete g_compositor_thread; |
| 191 g_compositor_thread = NULL; | 197 g_compositor_thread = NULL; |
| 192 } | 198 } |
| 193 } | 199 } |
| 194 | 200 |
| 195 void Compositor::ScheduleDraw() { | 201 void Compositor::ScheduleDraw() { |
| 196 if (g_compositor_thread) { | 202 if (g_compositor_thread) { |
| 197 // TODO(nduca): Temporary while compositor calls | 203 // TODO(nduca): Temporary while compositor calls |
| 198 // compositeImmediately() directly. | 204 // compositeImmediately() directly. |
| 199 layout(); | 205 layout(); |
| 206 #if defined(WEBLAYERTREEVIEW_IS_PURE_VIRTUAL) |
| 207 host_->composite(); |
| 208 #else |
| 200 host_.composite(); | 209 host_.composite(); |
| 210 #endif |
| 201 } else if (delegate_) { | 211 } else if (delegate_) { |
| 202 delegate_->ScheduleDraw(); | 212 delegate_->ScheduleDraw(); |
| 203 } | 213 } |
| 204 } | 214 } |
| 205 | 215 |
| 206 void Compositor::SetRootLayer(Layer* root_layer) { | 216 void Compositor::SetRootLayer(Layer* root_layer) { |
| 207 if (root_layer_ == root_layer) | 217 if (root_layer_ == root_layer) |
| 208 return; | 218 return; |
| 209 if (root_layer_) | 219 if (root_layer_) |
| 210 root_layer_->SetCompositor(NULL); | 220 root_layer_->SetCompositor(NULL); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 222 | 232 |
| 223 last_started_frame_++; | 233 last_started_frame_++; |
| 224 if (!g_compositor_thread) | 234 if (!g_compositor_thread) |
| 225 FOR_EACH_OBSERVER(CompositorObserver, | 235 FOR_EACH_OBSERVER(CompositorObserver, |
| 226 observer_list_, | 236 observer_list_, |
| 227 OnCompositingWillStart(this)); | 237 OnCompositingWillStart(this)); |
| 228 | 238 |
| 229 // TODO(nduca): Temporary while compositor calls | 239 // TODO(nduca): Temporary while compositor calls |
| 230 // compositeImmediately() directly. | 240 // compositeImmediately() directly. |
| 231 layout(); | 241 layout(); |
| 242 #if defined(WEBLAYERTREEVIEW_IS_PURE_VIRTUAL) |
| 243 host_->composite(); |
| 244 #else |
| 232 host_.composite(); | 245 host_.composite(); |
| 246 #endif |
| 233 if (!g_compositor_thread && !swap_posted_) | 247 if (!g_compositor_thread && !swap_posted_) |
| 234 NotifyEnd(); | 248 NotifyEnd(); |
| 235 } | 249 } |
| 236 | 250 |
| 237 void Compositor::ScheduleFullDraw() { | 251 void Compositor::ScheduleFullDraw() { |
| 252 #if defined(WEBLAYERTREEVIEW_IS_PURE_VIRTUAL) |
| 253 host_->setNeedsRedraw(); |
| 254 #else |
| 238 host_.setNeedsRedraw(); | 255 host_.setNeedsRedraw(); |
| 256 #endif |
| 239 } | 257 } |
| 240 | 258 |
| 241 bool Compositor::ReadPixels(SkBitmap* bitmap, | 259 bool Compositor::ReadPixels(SkBitmap* bitmap, |
| 242 const gfx::Rect& bounds_in_pixel) { | 260 const gfx::Rect& bounds_in_pixel) { |
| 243 if (bounds_in_pixel.right() > size().width() || | 261 if (bounds_in_pixel.right() > size().width() || |
| 244 bounds_in_pixel.bottom() > size().height()) | 262 bounds_in_pixel.bottom() > size().height()) |
| 245 return false; | 263 return false; |
| 246 // Convert to OpenGL coordinates. | 264 // Convert to OpenGL coordinates. |
| 247 gfx::Point new_origin( | 265 gfx::Point new_origin( |
| 248 bounds_in_pixel.x(), | 266 bounds_in_pixel.x(), |
| 249 size().height() - bounds_in_pixel.height() - bounds_in_pixel.y()); | 267 size().height() - bounds_in_pixel.height() - bounds_in_pixel.y()); |
| 250 | 268 |
| 251 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 269 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 252 bounds_in_pixel.width(), bounds_in_pixel.height()); | 270 bounds_in_pixel.width(), bounds_in_pixel.height()); |
| 253 bitmap->allocPixels(); | 271 bitmap->allocPixels(); |
| 254 SkAutoLockPixels lock_image(*bitmap); | 272 SkAutoLockPixels lock_image(*bitmap); |
| 255 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); | 273 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); |
| 274 #if defined(WEBLAYERTREEVIEW_IS_PURE_VIRTUAL) |
| 275 if (host_->compositeAndReadback( |
| 276 #else |
| 256 if (host_.compositeAndReadback( | 277 if (host_.compositeAndReadback( |
| 278 #endif |
| 257 pixels, gfx::Rect(new_origin, bounds_in_pixel.size()))) { | 279 pixels, gfx::Rect(new_origin, bounds_in_pixel.size()))) { |
| 258 SwizzleRGBAToBGRAAndFlip(pixels, bounds_in_pixel.size()); | 280 SwizzleRGBAToBGRAAndFlip(pixels, bounds_in_pixel.size()); |
| 259 return true; | 281 return true; |
| 260 } | 282 } |
| 261 return false; | 283 return false; |
| 262 } | 284 } |
| 263 | 285 |
| 264 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { | 286 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { |
| 265 DCHECK_GT(scale, 0); | 287 DCHECK_GT(scale, 0); |
| 266 if (size_in_pixel.IsEmpty() || scale <= 0) | 288 if (size_in_pixel.IsEmpty() || scale <= 0) |
| 267 return; | 289 return; |
| 268 size_ = size_in_pixel; | 290 size_ = size_in_pixel; |
| 291 #if defined(WEBLAYERTREEVIEW_IS_PURE_VIRTUAL) |
| 292 host_->setViewportSize(size_in_pixel); |
| 293 #else |
| 269 host_.setViewportSize(size_in_pixel); | 294 host_.setViewportSize(size_in_pixel); |
| 295 #endif |
| 270 root_web_layer_->setBounds(size_in_pixel); | 296 root_web_layer_->setBounds(size_in_pixel); |
| 271 | 297 |
| 272 if (device_scale_factor_ != scale) { | 298 if (device_scale_factor_ != scale) { |
| 273 device_scale_factor_ = scale; | 299 device_scale_factor_ = scale; |
| 274 if (root_layer_) | 300 if (root_layer_) |
| 275 root_layer_->OnDeviceScaleFactorChanged(scale); | 301 root_layer_->OnDeviceScaleFactorChanged(scale); |
| 276 } | 302 } |
| 277 } | 303 } |
| 278 | 304 |
| 279 void Compositor::AddObserver(CompositorObserver* observer) { | 305 void Compositor::AddObserver(CompositorObserver* observer) { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 485 |
| 460 COMPOSITOR_EXPORT void DisableTestCompositor() { | 486 COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 461 test_compositor_enabled = false; | 487 test_compositor_enabled = false; |
| 462 } | 488 } |
| 463 | 489 |
| 464 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 490 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 465 return test_compositor_enabled; | 491 return test_compositor_enabled; |
| 466 } | 492 } |
| 467 | 493 |
| 468 } // namespace ui | 494 } // namespace ui |
| OLD | NEW |