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

Side by Side Diff: ui/snapshot/snapshot_aura.cc

Issue 100833002: Add AshDesktopMediaList and enable Desktop Capture API on Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/snapshot/snapshot_android.cc ('k') | ui/snapshot/snapshot_gtk.cc » ('j') | no next file with comments »
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 "ui/snapshot/snapshot.h" 5 #include "ui/snapshot/snapshot.h"
6 6
7 #include "base/bind.h"
8 #include "base/callback.h"
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/safe_numerics.h" 10 #include "base/safe_numerics.h"
11 #include "base/task_runner_util.h"
12 #include "cc/output/copy_output_request.h"
13 #include "cc/output/copy_output_result.h"
14 #include "skia/ext/image_operations.h"
9 #include "third_party/skia/include/core/SkBitmap.h" 15 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "third_party/skia/include/core/SkPixelRef.h" 16 #include "third_party/skia/include/core/SkPixelRef.h"
11 #include "ui/aura/root_window.h" 17 #include "ui/aura/root_window.h"
12 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
13 #include "ui/compositor/compositor.h" 19 #include "ui/compositor/compositor.h"
14 #include "ui/compositor/dip_util.h" 20 #include "ui/compositor/dip_util.h"
15 #include "ui/compositor/layer.h" 21 #include "ui/compositor/layer.h"
16 #include "ui/gfx/codec/png_codec.h" 22 #include "ui/gfx/codec/png_codec.h"
17 #include "ui/gfx/display.h" 23 #include "ui/gfx/display.h"
24 #include "ui/gfx/image/image.h"
25 #include "ui/gfx/image/image_skia.h"
18 #include "ui/gfx/rect.h" 26 #include "ui/gfx/rect.h"
19 #include "ui/gfx/rect_conversions.h" 27 #include "ui/gfx/rect_conversions.h"
20 #include "ui/gfx/rect_f.h" 28 #include "ui/gfx/rect_f.h"
21 #include "ui/gfx/screen.h" 29 #include "ui/gfx/screen.h"
22 #include "ui/gfx/skbitmap_operations.h" 30 #include "ui/gfx/skbitmap_operations.h"
23 #include "ui/gfx/transform.h" 31 #include "ui/gfx/transform.h"
24 32
25 namespace ui { 33 namespace ui {
26 34
35 namespace {
36
37 void OnFrameScalingFinished(
38 const GrapWindowSnapshotAsyncCallback& callback,
39 const SkBitmap& scaled_bitmap) {
40 callback.Run(gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(scaled_bitmap)));
41 }
42
43 void ScaleCopyOutputResult(
44 const GrapWindowSnapshotAsyncCallback& callback,
45 const gfx::Size& target_size,
46 scoped_refptr<base::TaskRunner> background_task_runner,
47 scoped_ptr<cc::CopyOutputResult> result) {
48 if (result->IsEmpty()) {
49 callback.Run(gfx::Image());
50 return;
51 }
52
53 // There are two overrides for skia::ImageOperations::Resize(), so we need get
54 // pointer to the right override explicitly (otherwise the base::Bind() call
55 // below won't compile).
56 SkBitmap (*resize_function)(const SkBitmap&,
57 skia::ImageOperations::ResizeMethod, int, int,
58 SkBitmap::Allocator* allocator) =
59 &skia::ImageOperations::Resize;
60
61 // TODO(sergeyu): Potentially images can be scaled on GPU before reading it
62 // from GPU. Image scaling is implemented in content::GlHelper, but it's can't
63 // be used here because it's not in content/public. Move the scaling code
64 // somewhere so that it can be reused here.
65 base::PostTaskAndReplyWithResult(
66 background_task_runner, FROM_HERE,
67 base::Bind(resize_function, *result->TakeBitmap(),
68 skia::ImageOperations::RESIZE_GOOD,
69 target_size.width(), target_size.height(),
70 static_cast<SkBitmap::Allocator*>(NULL)),
71 base::Bind(&OnFrameScalingFinished, callback));
72 }
73
74 } // namespace
75
27 bool GrabViewSnapshot(gfx::NativeView view, 76 bool GrabViewSnapshot(gfx::NativeView view,
28 std::vector<unsigned char>* png_representation, 77 std::vector<unsigned char>* png_representation,
29 const gfx::Rect& snapshot_bounds) { 78 const gfx::Rect& snapshot_bounds) {
30 return GrabWindowSnapshot(view, png_representation, snapshot_bounds); 79 return GrabWindowSnapshot(view, png_representation, snapshot_bounds);
31 } 80 }
32 81
33 bool GrabWindowSnapshot(gfx::NativeWindow window, 82 bool GrabWindowSnapshot(gfx::NativeWindow window,
34 std::vector<unsigned char>* png_representation, 83 std::vector<unsigned char>* png_representation,
35 const gfx::Rect& snapshot_bounds) { 84 const gfx::Rect& snapshot_bounds) {
36 ui::Compositor* compositor = window->layer()->GetCompositor(); 85 ui::Compositor* compositor = window->layer()->GetCompositor();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 unsigned char* pixels = reinterpret_cast<unsigned char*>( 129 unsigned char* pixels = reinterpret_cast<unsigned char*>(
81 bitmap.pixelRef()->pixels()); 130 bitmap.pixelRef()->pixels());
82 return gfx::PNGCodec::Encode( 131 return gfx::PNGCodec::Encode(
83 pixels, gfx::PNGCodec::FORMAT_BGRA, 132 pixels, gfx::PNGCodec::FORMAT_BGRA,
84 gfx::Size(bitmap.width(), bitmap.height()), 133 gfx::Size(bitmap.width(), bitmap.height()),
85 base::checked_numeric_cast<int>(bitmap.rowBytes()), 134 base::checked_numeric_cast<int>(bitmap.rowBytes()),
86 true, std::vector<gfx::PNGCodec::Comment>(), 135 true, std::vector<gfx::PNGCodec::Comment>(),
87 png_representation); 136 png_representation);
88 } 137 }
89 138
139 SNAPSHOT_EXPORT void GrapWindowSnapshotAsync(
140 gfx::NativeWindow window,
141 const gfx::Rect& source_rect,
142 const gfx::Size& target_size,
143 scoped_refptr<base::TaskRunner> background_task_runner,
144 const GrapWindowSnapshotAsyncCallback& callback) {
145 scoped_ptr<cc::CopyOutputRequest> request =
146 cc::CopyOutputRequest::CreateBitmapRequest(
147 base::Bind(&ScaleCopyOutputResult, callback, target_size,
148 background_task_runner));
149 request->set_area(ui::ConvertRectToPixel(window->layer(), source_rect));
150 window->layer()->RequestCopyOfOutput(request.Pass());
151 }
152
90 } // namespace ui 153 } // namespace ui
OLDNEW
« no previous file with comments | « ui/snapshot/snapshot_android.cc ('k') | ui/snapshot/snapshot_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698