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/gfx/compositor/compositor.h" | 5 #include "ui/gfx/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" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 #include "third_party/skia/include/images/SkImageEncoder.h" | 14 #include "third_party/skia/include/images/SkImageEncoder.h" |
| 15 #include "ui/gfx/compositor/compositor_observer.h" | 15 #include "ui/gfx/compositor/compositor_observer.h" |
| 16 #include "ui/gfx/compositor/compositor_switches.h" | 16 #include "ui/gfx/compositor/compositor_switches.h" |
| 17 #include "ui/gfx/compositor/layer.h" | 17 #include "ui/gfx/compositor/layer.h" |
| 18 #include "ui/gfx/compositor/dip_util.h" | |
| 18 #include "ui/gfx/compositor/test_web_graphics_context_3d.h" | 19 #include "ui/gfx/compositor/test_web_graphics_context_3d.h" |
| 19 #include "ui/gfx/gl/gl_context.h" | 20 #include "ui/gfx/gl/gl_context.h" |
| 20 #include "ui/gfx/gl/gl_implementation.h" | 21 #include "ui/gfx/gl/gl_implementation.h" |
| 21 #include "ui/gfx/gl/gl_surface.h" | 22 #include "ui/gfx/gl/gl_surface.h" |
| 22 #include "webkit/glue/webthread_impl.h" | 23 #include "webkit/glue/webthread_impl.h" |
| 23 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" | 24 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const double kDefaultRefreshRate = 60.0; | 28 const double kDefaultRefreshRate = 60.0; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 Texture::Texture(bool flipped, const gfx::Size& size) | 113 Texture::Texture(bool flipped, const gfx::Size& size) |
| 113 : texture_id_(0), | 114 : texture_id_(0), |
| 114 flipped_(flipped), | 115 flipped_(flipped), |
| 115 size_(size) { | 116 size_(size) { |
| 116 } | 117 } |
| 117 | 118 |
| 118 Texture::~Texture() { | 119 Texture::~Texture() { |
| 119 } | 120 } |
| 120 | 121 |
| 121 Compositor::Compositor(CompositorDelegate* delegate, | 122 Compositor::Compositor(CompositorDelegate* delegate, |
| 122 gfx::AcceleratedWidget widget, | 123 gfx::AcceleratedWidget widget) |
| 123 const gfx::Size& size) | |
| 124 : delegate_(delegate), | 124 : delegate_(delegate), |
| 125 size_(size), | |
| 126 root_layer_(NULL), | 125 root_layer_(NULL), |
| 127 widget_(widget), | 126 widget_(widget), |
| 128 root_web_layer_(WebKit::WebLayer::create()), | 127 root_web_layer_(WebKit::WebLayer::create()), |
| 129 swap_posted_(false) { | 128 swap_posted_(false), |
| 129 device_scale_factor_(0.0f) { | |
| 130 WebKit::WebLayerTreeView::Settings settings; | 130 WebKit::WebLayerTreeView::Settings settings; |
| 131 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 131 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 132 settings.showFPSCounter = | 132 settings.showFPSCounter = |
| 133 command_line->HasSwitch(switches::kUIShowFPSCounter); | 133 command_line->HasSwitch(switches::kUIShowFPSCounter); |
| 134 settings.showPlatformLayerTree = | 134 settings.showPlatformLayerTree = |
| 135 command_line->HasSwitch(switches::kUIShowLayerTree); | 135 command_line->HasSwitch(switches::kUIShowLayerTree); |
| 136 settings.refreshRate = test_compositor_enabled ? | 136 settings.refreshRate = test_compositor_enabled ? |
| 137 kTestRefreshRate : kDefaultRefreshRate; | 137 kTestRefreshRate : kDefaultRefreshRate; |
| 138 settings.partialSwapEnabled = | 138 settings.partialSwapEnabled = |
| 139 command_line->HasSwitch(switches::kUIEnablePartialSwap); | 139 command_line->HasSwitch(switches::kUIEnablePartialSwap); |
| 140 settings.perTilePainting = | 140 settings.perTilePainting = |
| 141 command_line->HasSwitch(switches::kUIEnablePerTilePainting); | 141 command_line->HasSwitch(switches::kUIEnablePerTilePainting); |
| 142 | 142 |
| 143 host_.initialize(this, root_web_layer_, settings); | 143 host_.initialize(this, root_web_layer_, settings); |
| 144 root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 144 root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
| 145 WidgetSizeChanged(size_); | |
| 146 } | 145 } |
| 147 | 146 |
| 148 Compositor::~Compositor() { | 147 Compositor::~Compositor() { |
| 149 // There's a cycle between |root_web_layer_| and |host_|, which results in | 148 // There's a cycle between |root_web_layer_| and |host_|, which results in |
| 150 // leaking and/or crashing. Explicitly set the root layer to NULL so the cycle | 149 // leaking and/or crashing. Explicitly set the root layer to NULL so the cycle |
| 151 // is broken. | 150 // is broken. |
| 152 host_.setRootLayer(NULL); | 151 host_.setRootLayer(NULL); |
| 153 if (root_layer_) | 152 if (root_layer_) |
| 154 root_layer_->SetCompositor(NULL); | 153 root_layer_->SetCompositor(NULL); |
| 155 if (!test_compositor_enabled) | 154 if (!test_compositor_enabled) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 layout(); | 202 layout(); |
| 204 host_.composite(); | 203 host_.composite(); |
| 205 if (!g_compositor_thread && !swap_posted_) | 204 if (!g_compositor_thread && !swap_posted_) |
| 206 NotifyEnd(); | 205 NotifyEnd(); |
| 207 } | 206 } |
| 208 | 207 |
| 209 void Compositor::ScheduleFullDraw() { | 208 void Compositor::ScheduleFullDraw() { |
| 210 host_.setNeedsRedraw(); | 209 host_.setNeedsRedraw(); |
| 211 } | 210 } |
| 212 | 211 |
| 213 bool Compositor::ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds) { | 212 bool Compositor::ReadPixels(SkBitmap* bitmap, |
| 214 if (bounds.right() > size().width() || bounds.bottom() > size().height()) | 213 const gfx::Rect& bounds_in_pixel) { |
| 214 if (bounds_in_pixel.right() > size().width() || | |
| 215 bounds_in_pixel.bottom() > size().height()) | |
| 215 return false; | 216 return false; |
| 216 // Convert to OpenGL coordinates. | 217 // Convert to OpenGL coordinates. |
| 217 gfx::Point new_origin(bounds.x(), | 218 gfx::Point new_origin( |
| 218 size().height() - bounds.height() - bounds.y()); | 219 bounds_in_pixel.x(), |
| 220 size().height() - bounds_in_pixel.height() - bounds_in_pixel.y()); | |
| 219 | 221 |
| 220 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 222 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 221 bounds.width(), bounds.height()); | 223 bounds_in_pixel.width(), bounds_in_pixel.height()); |
| 222 bitmap->allocPixels(); | 224 bitmap->allocPixels(); |
| 223 SkAutoLockPixels lock_image(*bitmap); | 225 SkAutoLockPixels lock_image(*bitmap); |
| 224 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); | 226 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); |
| 225 if (host_.compositeAndReadback(pixels, | 227 if (host_.compositeAndReadback( |
| 226 gfx::Rect(new_origin, bounds.size()))) { | 228 pixels, gfx::Rect(new_origin, bounds_in_pixel.size()))) { |
| 227 SwizzleRGBAToBGRAAndFlip(pixels, bounds.size()); | 229 SwizzleRGBAToBGRAAndFlip(pixels, bounds_in_pixel.size()); |
| 228 return true; | 230 return true; |
| 229 } | 231 } |
| 230 return false; | 232 return false; |
| 231 } | 233 } |
| 232 | 234 |
| 233 void Compositor::WidgetSizeChanged(const gfx::Size& size) { | 235 void Compositor::WidgetScaleOrSizeChanged(float scale, |
| 234 if (size.IsEmpty()) | 236 const gfx::Size& size_in_pixel) { |
| 237 if (size_in_pixel.IsEmpty() || scale <= 0) | |
| 235 return; | 238 return; |
| 236 size_ = size; | 239 size_ = size_in_pixel; |
| 237 host_.setViewportSize(size_); | 240 host_.setViewportSize(size_in_pixel); |
| 238 root_web_layer_.setBounds(size_); | 241 root_web_layer_.setBounds(size_in_pixel); |
| 242 | |
| 243 if (device_scale_factor_ != scale && IsDIPEnabled()) { | |
| 244 device_scale_factor_ = scale; | |
| 245 scale_translate_.matrix().set3x3(scale, 0, 0, | |
| 246 0, scale, 0, | |
| 247 0, 0, 1); | |
| 248 CHECK(scale_translate_.matrix().invert( | |
| 249 &invese_scale_translate_.matrix())); | |
| 250 if (root_layer_) | |
|
piman
2012/05/04 18:46:06
nit: indentation?
| |
| 251 root_layer_->UpdateLayerSize(); | |
| 252 } | |
| 239 } | 253 } |
| 240 | 254 |
| 241 void Compositor::AddObserver(CompositorObserver* observer) { | 255 void Compositor::AddObserver(CompositorObserver* observer) { |
| 242 observer_list_.AddObserver(observer); | 256 observer_list_.AddObserver(observer); |
| 243 } | 257 } |
| 244 | 258 |
| 245 void Compositor::RemoveObserver(CompositorObserver* observer) { | 259 void Compositor::RemoveObserver(CompositorObserver* observer) { |
| 246 observer_list_.RemoveObserver(observer); | 260 observer_list_.RemoveObserver(observer); |
| 247 } | 261 } |
| 248 | 262 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 260 NotifyEnd(); | 274 NotifyEnd(); |
| 261 } | 275 } |
| 262 | 276 |
| 263 void Compositor::OnSwapBuffersAborted() { | 277 void Compositor::OnSwapBuffersAborted() { |
| 264 if (swap_posted_) { | 278 if (swap_posted_) { |
| 265 swap_posted_ = false; | 279 swap_posted_ = false; |
| 266 NotifyEnd(); | 280 NotifyEnd(); |
| 267 } | 281 } |
| 268 } | 282 } |
| 269 | 283 |
| 284 Transform Compositor::GetTranslateTransform( | |
| 285 const Transform& transform, | |
| 286 const gfx::Point& offset) { | |
| 287 ui::Transform ret; | |
| 288 ret.ConcatTransform(invese_scale_translate_); | |
|
piman
2012/05/04 18:46:06
nit: you probably want to start with ret=inverse_s
| |
| 289 ret.ConcatTransform(transform); | |
| 290 ret.ConcatTranslate(offset.x(), offset.y()); | |
| 291 ret.ConcatTransform(scale_translate_); | |
| 292 return ret; | |
| 293 } | |
| 294 | |
| 270 void Compositor::updateAnimations(double frameBeginTime) { | 295 void Compositor::updateAnimations(double frameBeginTime) { |
| 271 } | 296 } |
| 272 | 297 |
| 273 void Compositor::layout() { | 298 void Compositor::layout() { |
| 274 if (root_layer_) | 299 if (root_layer_) |
| 275 root_layer_->SendDamagedRects(); | 300 root_layer_->SendDamagedRects(); |
| 276 } | 301 } |
| 277 | 302 |
| 278 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, | 303 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, |
| 279 float scaleFactor) { | 304 float scaleFactor) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 | 370 |
| 346 COMPOSITOR_EXPORT void DisableTestCompositor() { | 371 COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 347 test_compositor_enabled = false; | 372 test_compositor_enabled = false; |
| 348 } | 373 } |
| 349 | 374 |
| 350 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 375 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 351 return test_compositor_enabled; | 376 return test_compositor_enabled; |
| 352 } | 377 } |
| 353 | 378 |
| 354 } // namespace ui | 379 } // namespace ui |
| OLD | NEW |