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, |
sky
2012/05/08 00:41:59
How about SetScaleAndSize?
oshima
2012/05/08 01:24:16
Done.
| |
234 if (size.IsEmpty()) | 236 const gfx::Size& size_in_pixel) { |
237 DCHECK(scale > 0); | |
238 if (size_in_pixel.IsEmpty() || scale <= 0) | |
235 return; | 239 return; |
236 size_ = size; | 240 size_ = size_in_pixel; |
237 host_.setViewportSize(size_); | 241 host_.setViewportSize(size_in_pixel); |
238 root_web_layer_.setBounds(size_); | 242 root_web_layer_.setBounds(size_in_pixel); |
243 | |
244 if (device_scale_factor_ != scale && IsDIPEnabled()) { | |
245 device_scale_factor_ = scale; | |
246 if (root_layer_) | |
247 root_layer_->OnDeviceScaleFactorChanged(scale); | |
248 } | |
239 } | 249 } |
240 | 250 |
241 void Compositor::AddObserver(CompositorObserver* observer) { | 251 void Compositor::AddObserver(CompositorObserver* observer) { |
242 observer_list_.AddObserver(observer); | 252 observer_list_.AddObserver(observer); |
243 } | 253 } |
244 | 254 |
245 void Compositor::RemoveObserver(CompositorObserver* observer) { | 255 void Compositor::RemoveObserver(CompositorObserver* observer) { |
246 observer_list_.RemoveObserver(observer); | 256 observer_list_.RemoveObserver(observer); |
247 } | 257 } |
248 | 258 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 | 355 |
346 COMPOSITOR_EXPORT void DisableTestCompositor() { | 356 COMPOSITOR_EXPORT void DisableTestCompositor() { |
347 test_compositor_enabled = false; | 357 test_compositor_enabled = false; |
348 } | 358 } |
349 | 359 |
350 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 360 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
351 return test_compositor_enabled; | 361 return test_compositor_enabled; |
352 } | 362 } |
353 | 363 |
354 } // namespace ui | 364 } // namespace ui |
OLD | NEW |