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

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

Issue 10386124: Introduce XGetImage() for GrabWindowSnapshot() in ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/aura/root_window.h » ('j') | ui/aura/root_window.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/aura/root_window.h"
10 #include "ui/compositor/compositor.h" 11 #include "ui/compositor/compositor.h"
11 #include "ui/compositor/dip_util.h" 12 #include "ui/compositor/dip_util.h"
12 #include "ui/compositor/layer.h" 13 #include "ui/compositor/layer.h"
13 #include "ui/gfx/codec/png_codec.h" 14 #include "ui/gfx/codec/png_codec.h"
14 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
15 16
16 namespace browser { 17 namespace browser {
17 18
18 bool GrabWindowSnapshot(gfx::NativeWindow window, 19 bool GrabWindowSnapshot(gfx::NativeWindow window,
19 std::vector<unsigned char>* png_representation, 20 std::vector<unsigned char>* png_representation,
20 const gfx::Rect& snapshot_bounds) { 21 const gfx::Rect& snapshot_bounds) {
22 #if defined(OS_CHROMEOS)
Daniel Erat 2012/05/14 23:17:40 Should this be OS_LINUX? I don't see anything Chr
Jun Mukai 2012/05/15 22:39:24 Done.
23 // We use XGetImage() for ChromeOS for the performance reason.
Daniel Erat 2012/05/14 23:17:40 nit: s/the performance reason/performance reasons/
Jun Mukai 2012/05/15 22:39:24 Done.
24 // See crbug.com/122720
25 return window->GetRootWindow()->GrabWindowSnapshot(
26 png_representation, snapshot_bounds);
27 #else
21 ui::Compositor* compositor = window->layer()->GetCompositor(); 28 ui::Compositor* compositor = window->layer()->GetCompositor();
22 29
23 gfx::Rect read_pixels_bounds = snapshot_bounds; 30 gfx::Rect read_pixels_bounds = snapshot_bounds;
24 31
25 // When not in compact mode we must take into account the window's position on 32 // When not in compact mode we must take into account the window's position on
26 // the desktop. 33 // the desktop.
27 read_pixels_bounds.set_origin( 34 read_pixels_bounds.set_origin(
28 snapshot_bounds.origin().Add(window->bounds().origin())); 35 snapshot_bounds.origin().Add(window->bounds().origin()));
29 gfx::Rect read_pixels_bounds_in_pixel = 36 gfx::Rect read_pixels_bounds_in_pixel =
30 ui::ConvertRectToPixel(window->layer(), read_pixels_bounds); 37 ui::ConvertRectToPixel(window->layer(), read_pixels_bounds);
31 38
32 DCHECK_GE(compositor->size().width(), read_pixels_bounds_in_pixel.right()); 39 DCHECK_GE(compositor->size().width(), read_pixels_bounds_in_pixel.right());
33 DCHECK_GE(compositor->size().height(), read_pixels_bounds_in_pixel.bottom()); 40 DCHECK_GE(compositor->size().height(), read_pixels_bounds_in_pixel.bottom());
34 DCHECK_LE(0, read_pixels_bounds.x()); 41 DCHECK_LE(0, read_pixels_bounds.x());
35 DCHECK_LE(0, read_pixels_bounds.y()); 42 DCHECK_LE(0, read_pixels_bounds.y());
36 43
37 SkBitmap bitmap; 44 SkBitmap bitmap;
38 if (!compositor->ReadPixels(&bitmap, read_pixels_bounds_in_pixel)) 45 if (!compositor->ReadPixels(&bitmap, read_pixels_bounds_in_pixel))
39 return false; 46 return false;
40 47
41 unsigned char* pixels = reinterpret_cast<unsigned char*>(bitmap.getPixels()); 48 unsigned char* pixels = reinterpret_cast<unsigned char*>(bitmap.getPixels());
42 49
43 gfx::PNGCodec::Encode(pixels, gfx::PNGCodec::FORMAT_BGRA, 50 gfx::PNGCodec::Encode(pixels, gfx::PNGCodec::FORMAT_BGRA,
44 read_pixels_bounds_in_pixel.size(), 51 read_pixels_bounds_in_pixel.size(),
45 bitmap.rowBytes(), true, 52 bitmap.rowBytes(), true,
46 std::vector<gfx::PNGCodec::Comment>(), 53 std::vector<gfx::PNGCodec::Comment>(),
47 png_representation); 54 png_representation);
48 return true; 55 return true;
56 #endif
49 } 57 }
50 58
51 } // namespace browser 59 } // namespace browser
OLDNEW
« no previous file with comments | « no previous file | ui/aura/root_window.h » ('j') | ui/aura/root_window.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698