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 "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" | |
9 #include "ui/aura/desktop.h" | |
sky
2011/11/18 21:08:06
remove desktop include.
| |
10 #include "ui/gfx/codec/png_codec.h" | |
11 #include "ui/gfx/compositor/compositor.h" | |
8 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
9 | 13 |
10 namespace browser { | 14 namespace browser { |
11 | 15 |
12 bool GrabWindowSnapshot(gfx::NativeWindow window_handle, | 16 bool GrabWindowSnapshot(gfx::NativeWindow window, |
13 std::vector<unsigned char>* png_representation, | 17 std::vector<unsigned char>* png_representation, |
14 const gfx::Rect& snapshot_bounds) { | 18 const gfx::Rect& snapshot_bounds) { |
15 // TODO(saintlou): Stub for Aura. | 19 ui::Compositor* compositor = window->layer()->GetCompositor(); |
16 NOTIMPLEMENTED(); | 20 |
17 return false; | 21 gfx::Rect desktop_snapshot_bounds = gfx::Rect( |
22 snapshot_bounds.origin().Add(window->bounds().origin()), | |
23 snapshot_bounds.size()); | |
24 | |
25 DCHECK_LE(desktop_snapshot_bounds.right() , compositor->size().width()); | |
26 DCHECK_LE(desktop_snapshot_bounds.bottom(), compositor->size().height()); | |
27 | |
28 SkBitmap bitmap; | |
29 if (!compositor->ReadPixels(&bitmap, desktop_snapshot_bounds)) | |
30 return false; | |
31 | |
32 unsigned char* pixels = reinterpret_cast<unsigned char*>(bitmap.getPixels()); | |
33 | |
34 gfx::PNGCodec::Encode(pixels, gfx::PNGCodec::FORMAT_BGRA, | |
35 snapshot_bounds.size(), | |
36 bitmap.rowBytes(), true, | |
37 std::vector<gfx::PNGCodec::Comment>(), | |
38 png_representation); | |
39 return true; | |
18 } | 40 } |
19 | 41 |
20 } // namespace browser | 42 } // namespace browser |
OLD | NEW |