| 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 "chrome/browser/ui/window_snapshot/window_snapshot.h" | 5 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "ui/aura/root_window.h" | |
| 10 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 11 #include "ui/compositor/compositor.h" | 10 #include "ui/compositor/compositor.h" |
| 12 #include "ui/compositor/dip_util.h" | 11 #include "ui/compositor/dip_util.h" |
| 13 #include "ui/compositor/layer.h" | 12 #include "ui/compositor/layer.h" |
| 14 #include "ui/gfx/codec/png_codec.h" | 13 #include "ui/gfx/codec/png_codec.h" |
| 15 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 16 | 15 |
| 17 namespace browser { | 16 namespace browser { |
| 18 | 17 |
| 19 bool GrabWindowSnapshot(gfx::NativeWindow window, | 18 bool GrabWindowSnapshot(gfx::NativeWindow window, |
| 20 std::vector<unsigned char>* png_representation, | 19 std::vector<unsigned char>* png_representation, |
| 21 const gfx::Rect& snapshot_bounds) { | 20 const gfx::Rect& snapshot_bounds) { |
| 22 #if defined(OS_LINUX) | |
| 23 // We use XGetImage() for Linux/ChromeOS for performance reasons. | |
| 24 // See crbug.com/122720 | |
| 25 if (window->GetRootWindow()->GrabSnapshot( | |
| 26 snapshot_bounds, png_representation)) | |
| 27 return true; | |
| 28 #endif // OS_LINUX | |
| 29 | |
| 30 ui::Compositor* compositor = window->layer()->GetCompositor(); | 21 ui::Compositor* compositor = window->layer()->GetCompositor(); |
| 31 | 22 |
| 32 gfx::Rect read_pixels_bounds = snapshot_bounds; | 23 gfx::Rect read_pixels_bounds = snapshot_bounds; |
| 33 | 24 |
| 34 // When not in compact mode we must take into account the window's position on | 25 // When not in compact mode we must take into account the window's position on |
| 35 // the desktop. | 26 // the desktop. |
| 36 read_pixels_bounds.set_origin( | 27 read_pixels_bounds.set_origin( |
| 37 snapshot_bounds.origin().Add(window->bounds().origin())); | 28 snapshot_bounds.origin().Add(window->bounds().origin())); |
| 38 gfx::Rect read_pixels_bounds_in_pixel = | 29 gfx::Rect read_pixels_bounds_in_pixel = |
| 39 ui::ConvertRectToPixel(window->layer(), read_pixels_bounds); | 30 ui::ConvertRectToPixel(window->layer(), read_pixels_bounds); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 51 | 42 |
| 52 gfx::PNGCodec::Encode(pixels, gfx::PNGCodec::FORMAT_BGRA, | 43 gfx::PNGCodec::Encode(pixels, gfx::PNGCodec::FORMAT_BGRA, |
| 53 read_pixels_bounds_in_pixel.size(), | 44 read_pixels_bounds_in_pixel.size(), |
| 54 bitmap.rowBytes(), true, | 45 bitmap.rowBytes(), true, |
| 55 std::vector<gfx::PNGCodec::Comment>(), | 46 std::vector<gfx::PNGCodec::Comment>(), |
| 56 png_representation); | 47 png_representation); |
| 57 return true; | 48 return true; |
| 58 } | 49 } |
| 59 | 50 |
| 60 } // namespace browser | 51 } // namespace browser |
| OLD | NEW |