Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(731)

Side by Side Diff: chrome/browser/ui/window_snapshot/window_snapshot_aura.cc

Issue 11399002: Implemented GetWindowSnapshot on RenderViewImpl (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added stub methods for iOS Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
6
7 #include "base/logging.h"
8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "ui/aura/window.h"
10 #include "ui/compositor/compositor.h"
11 #include "ui/compositor/dip_util.h"
12 #include "ui/compositor/layer.h"
13 #include "ui/gfx/codec/png_codec.h"
14 #include "ui/gfx/rect.h"
15
16 namespace chrome {
17 namespace internal {
18
19 bool GrabWindowSnapshot(gfx::NativeWindow window,
20 std::vector<unsigned char>* png_representation,
21 const gfx::Rect& snapshot_bounds) {
22 ui::Compositor* compositor = window->layer()->GetCompositor();
23
24 gfx::Rect read_pixels_bounds = snapshot_bounds;
25
26 // When not in compact mode we must take into account the window's position on
27 // the desktop.
28 read_pixels_bounds.Offset(window->bounds().OffsetFromOrigin());
29 gfx::Rect read_pixels_bounds_in_pixel =
30 ui::ConvertRectToPixel(window->layer(), read_pixels_bounds);
31
32 // Sometimes (i.e. when using Aero on Windows) the compositor's size is
33 // smaller than the window bounds. So trim appropriately.
34 read_pixels_bounds_in_pixel.Intersect(gfx::Rect(compositor->size()));
35
36 DCHECK_LE(0, read_pixels_bounds.x());
37 DCHECK_LE(0, read_pixels_bounds.y());
38
39 SkBitmap bitmap;
40 if (!compositor->ReadPixels(&bitmap, read_pixels_bounds_in_pixel))
41 return false;
42
43 unsigned char* pixels = reinterpret_cast<unsigned char*>(bitmap.getPixels());
44
45 gfx::PNGCodec::Encode(pixels, gfx::PNGCodec::FORMAT_BGRA,
46 read_pixels_bounds_in_pixel.size(),
47 bitmap.rowBytes(), true,
48 std::vector<gfx::PNGCodec::Comment>(),
49 png_representation);
50 return true;
51 }
52
53 } // namespace internal
54 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/window_snapshot/window_snapshot.cc ('k') | chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698