OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_cc.h" | 5 #include "ui/gfx/compositor/compositor_cc.h" |
6 | 6 |
7 #include "third_party/skia/include/images/SkImageEncoder.h" | 7 #include "third_party/skia/include/images/SkImageEncoder.h" |
8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.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/WebFloatPoint.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 void CompositorCC::OnRootLayerChanged() { | 175 void CompositorCC::OnRootLayerChanged() { |
176 root_web_layer_.removeAllChildren(); | 176 root_web_layer_.removeAllChildren(); |
177 if (root_layer()) | 177 if (root_layer()) |
178 root_web_layer_.addChild(root_layer()->web_layer()); | 178 root_web_layer_.addChild(root_layer()->web_layer()); |
179 } | 179 } |
180 | 180 |
181 void CompositorCC::DrawTree() { | 181 void CompositorCC::DrawTree() { |
182 host_.composite(); | 182 host_.composite(); |
183 } | 183 } |
184 | 184 |
185 bool CompositorCC::ReadPixels(SkBitmap* bitmap) { | 185 bool CompositorCC::ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds) { |
| 186 if (bounds.right() > size().width() || bounds.bottom() > size().height()) |
| 187 return false; |
| 188 // Convert to Skia coordinates. |
| 189 gfx::Point new_origin(bounds.x(), |
| 190 size().height() - bounds.height() - bounds.y()); |
| 191 |
186 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 192 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
187 size().width(), size().height()); | 193 bounds.width(), bounds.height()); |
188 bitmap->allocPixels(); | 194 bitmap->allocPixels(); |
189 SkAutoLockPixels lock_image(*bitmap); | 195 SkAutoLockPixels lock_image(*bitmap); |
190 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); | 196 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); |
191 if (host_.compositeAndReadback(pixels, gfx::Rect(size()))) { | 197 if (host_.compositeAndReadback(pixels, |
192 SwizzleRGBAToBGRAAndFlip(pixels, size()); | 198 gfx::Rect(new_origin, bounds.size()))) { |
| 199 SwizzleRGBAToBGRAAndFlip(pixels, bounds.size()); |
193 return true; | 200 return true; |
194 } | 201 } |
195 return false; | 202 return false; |
196 } | 203 } |
197 | 204 |
198 void CompositorCC::animateAndLayout(double frameBeginTime) { | 205 void CompositorCC::animateAndLayout(double frameBeginTime) { |
199 } | 206 } |
200 | 207 |
201 void CompositorCC::applyScrollAndScale(const WebKit::WebSize& scrollDelta, | 208 void CompositorCC::applyScrollAndScale(const WebKit::WebSize& scrollDelta, |
202 float scaleFactor) { | 209 float scaleFactor) { |
(...skipping 23 matching lines...) Expand all Loading... |
226 ScheduleDraw(); | 233 ScheduleDraw(); |
227 } | 234 } |
228 | 235 |
229 Compositor* Compositor::Create(CompositorDelegate* owner, | 236 Compositor* Compositor::Create(CompositorDelegate* owner, |
230 gfx::AcceleratedWidget widget, | 237 gfx::AcceleratedWidget widget, |
231 const gfx::Size& size) { | 238 const gfx::Size& size) { |
232 return new CompositorCC(owner, widget, size); | 239 return new CompositorCC(owner, widget, size); |
233 } | 240 } |
234 | 241 |
235 } // namespace ui | 242 } // namespace ui |
OLD | NEW |