diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-27 00:13:43 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-27 00:13:43 +0000 |
commit | 75a3f1b44ec1b22bc5acaff638eca6b1a3a74154 (patch) | |
tree | 65abe9f58ef3a9ca1cc66f4457ff4096a4365366 /ui | |
parent | c714e393b6f0bb6221c300888e655fc7379e4794 (diff) | |
download | chromium_src-75a3f1b44ec1b22bc5acaff638eca6b1a3a74154.zip chromium_src-75a3f1b44ec1b22bc5acaff638eca6b1a3a74154.tar.gz chromium_src-75a3f1b44ec1b22bc5acaff638eca6b1a3a74154.tar.bz2 |
Add AshDesktopMediaList and enable Desktop Capture API on Chrome OS.
The new AshDesktopMediaList gets list of windows/screens for the window
picker dialog which allows to enable Desktop Capture API on Chrome OS.
BUG=295102
R=ben@chromium.org, hshi@chromium.org
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=242361
Review URL: https://codereview.chromium.org/100833002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242578 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/snapshot/DEPS | 1 | ||||
-rw-r--r-- | ui/snapshot/snapshot.gyp | 1 | ||||
-rw-r--r-- | ui/snapshot/snapshot.h | 27 | ||||
-rw-r--r-- | ui/snapshot/snapshot_android.cc | 10 | ||||
-rw-r--r-- | ui/snapshot/snapshot_aura.cc | 63 | ||||
-rw-r--r-- | ui/snapshot/snapshot_gtk.cc | 10 | ||||
-rw-r--r-- | ui/snapshot/snapshot_ios.mm | 10 | ||||
-rw-r--r-- | ui/snapshot/snapshot_mac.mm | 10 | ||||
-rw-r--r-- | ui/snapshot/snapshot_win.cc | 12 |
9 files changed, 141 insertions, 3 deletions
diff --git a/ui/snapshot/DEPS b/ui/snapshot/DEPS index f4c1662..7cdf34d 100644 --- a/ui/snapshot/DEPS +++ b/ui/snapshot/DEPS @@ -1,4 +1,5 @@ include_rules = [ + "+cc", "+skia/ext", "+third_party/skia", "+ui/aura", diff --git a/ui/snapshot/snapshot.gyp b/ui/snapshot/snapshot.gyp index f7c16d1..95f2dac 100644 --- a/ui/snapshot/snapshot.gyp +++ b/ui/snapshot/snapshot.gyp @@ -37,6 +37,7 @@ 'conditions': [ ['use_aura==1', { 'dependencies': [ + '../../cc/cc.gyp:cc', '../aura/aura.gyp:aura', '../compositor/compositor.gyp:compositor', ], diff --git a/ui/snapshot/snapshot.h b/ui/snapshot/snapshot.h index 356309d..15b3db0 100644 --- a/ui/snapshot/snapshot.h +++ b/ui/snapshot/snapshot.h @@ -7,18 +7,28 @@ #include <vector> +#include "base/callback_forward.h" +#include "base/memory/ref_counted.h" #include "ui/gfx/native_widget_types.h" #include "ui/snapshot/snapshot_export.h" +namespace base { +class TaskRunner; +} + namespace gfx { class Rect; +class Image; +class Size; } namespace ui { -// Grabs a snapshot of the window/view. No security checks are done. -// This is intended to be used for debugging purposes where no BrowserProcess -// instance is available (ie. tests). DO NOT use in a result of user action. +// Grabs a snapshot of the window/view. No security checks are done. This is +// intended to be used for debugging purposes where no BrowserProcess instance +// is available (ie. tests). This function is synchronous, so it should NOT be +// used in a result of user action. Use asynchronous GrapWindowSnapshotAsync() +// instead. SNAPSHOT_EXPORT bool GrabWindowSnapshot( gfx::NativeWindow window, std::vector<unsigned char>* png_representation, @@ -29,6 +39,17 @@ SNAPSHOT_EXPORT bool GrabViewSnapshot( std::vector<unsigned char>* png_representation, const gfx::Rect& snapshot_bounds); +// GrapWindowSnapshotAsync() copies snapshot of |source_rect| from window and +// scales it to |target_size| asynchronously. +typedef base::Callback<void(const gfx::Image& snapshot)> + GrapWindowSnapshotAsyncCallback; +SNAPSHOT_EXPORT void GrapWindowSnapshotAsync( + gfx::NativeWindow window, + const gfx::Rect& source_rect, + const gfx::Size& target_size, + scoped_refptr<base::TaskRunner> background_task_runner, + const GrapWindowSnapshotAsyncCallback& callback); + } // namespace ui #endif // UI_SNAPSHOT_SNAPSHOT_H_ diff --git a/ui/snapshot/snapshot_android.cc b/ui/snapshot/snapshot_android.cc index f175a87..8dd309a 100644 --- a/ui/snapshot/snapshot_android.cc +++ b/ui/snapshot/snapshot_android.cc @@ -4,6 +4,7 @@ #include "ui/snapshot/snapshot.h" +#include "base/callback.h" #include "ui/base/android/view_android.h" #include "ui/base/android/window_android.h" #include "ui/gfx/display.h" @@ -32,4 +33,13 @@ bool GrabWindowSnapshot(gfx::NativeWindow window, scaled_bounds.height(), png_representation); } +SNAPSHOT_EXPORT void GrapWindowSnapshotAsync( + gfx::NativeWindow window, + const gfx::Rect& snapshot_bounds, + const gfx::Size& target_size, + scoped_refptr<base::TaskRunner> background_task_runner, + GrapWindowSnapshotAsyncCallback callback) { + NOTIMPLEMENTED(); +} + } // namespace ui diff --git a/ui/snapshot/snapshot_aura.cc b/ui/snapshot/snapshot_aura.cc index 8f7baa0..8e7ba31 100644 --- a/ui/snapshot/snapshot_aura.cc +++ b/ui/snapshot/snapshot_aura.cc @@ -4,8 +4,14 @@ #include "ui/snapshot/snapshot.h" +#include "base/bind.h" +#include "base/callback.h" #include "base/logging.h" #include "base/safe_numerics.h" +#include "base/task_runner_util.h" +#include "cc/output/copy_output_request.h" +#include "cc/output/copy_output_result.h" +#include "skia/ext/image_operations.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkPixelRef.h" #include "ui/aura/root_window.h" @@ -15,6 +21,8 @@ #include "ui/compositor/layer.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/display.h" +#include "ui/gfx/image/image.h" +#include "ui/gfx/image/image_skia.h" #include "ui/gfx/rect.h" #include "ui/gfx/rect_conversions.h" #include "ui/gfx/rect_f.h" @@ -24,6 +32,47 @@ namespace ui { +namespace { + +void OnFrameScalingFinished( + const GrapWindowSnapshotAsyncCallback& callback, + const SkBitmap& scaled_bitmap) { + callback.Run(gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(scaled_bitmap))); +} + +void ScaleCopyOutputResult( + const GrapWindowSnapshotAsyncCallback& callback, + const gfx::Size& target_size, + scoped_refptr<base::TaskRunner> background_task_runner, + scoped_ptr<cc::CopyOutputResult> result) { + if (result->IsEmpty()) { + callback.Run(gfx::Image()); + return; + } + + // There are two overrides for skia::ImageOperations::Resize(), so we need get + // pointer to the right override explicitly (otherwise the base::Bind() call + // below won't compile). + SkBitmap (*resize_function)(const SkBitmap&, + skia::ImageOperations::ResizeMethod, int, int, + SkBitmap::Allocator* allocator) = + &skia::ImageOperations::Resize; + + // TODO(sergeyu): Potentially images can be scaled on GPU before reading it + // from GPU. Image scaling is implemented in content::GlHelper, but it's can't + // be used here because it's not in content/public. Move the scaling code + // somewhere so that it can be reused here. + base::PostTaskAndReplyWithResult( + background_task_runner, FROM_HERE, + base::Bind(resize_function, *result->TakeBitmap(), + skia::ImageOperations::RESIZE_GOOD, + target_size.width(), target_size.height(), + static_cast<SkBitmap::Allocator*>(NULL)), + base::Bind(&OnFrameScalingFinished, callback)); +} + +} // namespace + bool GrabViewSnapshot(gfx::NativeView view, std::vector<unsigned char>* png_representation, const gfx::Rect& snapshot_bounds) { @@ -87,4 +136,18 @@ bool GrabWindowSnapshot(gfx::NativeWindow window, png_representation); } +SNAPSHOT_EXPORT void GrapWindowSnapshotAsync( + gfx::NativeWindow window, + const gfx::Rect& source_rect, + const gfx::Size& target_size, + scoped_refptr<base::TaskRunner> background_task_runner, + const GrapWindowSnapshotAsyncCallback& callback) { + scoped_ptr<cc::CopyOutputRequest> request = + cc::CopyOutputRequest::CreateBitmapRequest( + base::Bind(&ScaleCopyOutputResult, callback, target_size, + background_task_runner)); + request->set_area(ui::ConvertRectToPixel(window->layer(), source_rect)); + window->layer()->RequestCopyOfOutput(request.Pass()); +} + } // namespace ui diff --git a/ui/snapshot/snapshot_gtk.cc b/ui/snapshot/snapshot_gtk.cc index 8a2f8c1..4f3f833 100644 --- a/ui/snapshot/snapshot_gtk.cc +++ b/ui/snapshot/snapshot_gtk.cc @@ -7,6 +7,7 @@ #include <gdk/gdkx.h> #include <gtk/gtk.h> +#include "base/callback.h" #include "base/logging.h" #include "ui/base/x/x11_util.h" #include "ui/gfx/rect.h" @@ -82,4 +83,13 @@ bool GrabWindowSnapshot(gfx::NativeWindow window_handle, snapshot_bounds); } +SNAPSHOT_EXPORT void GrapWindowSnapshotAsync( + gfx::NativeWindow window, + const gfx::Rect& snapshot_bounds, + const gfx::Size& target_size, + scoped_refptr<base::TaskRunner> background_task_runner, + GrapWindowSnapshotAsyncCallback callback) { + NOTIMPLEMENTED(); +} + } // namespace ui diff --git a/ui/snapshot/snapshot_ios.mm b/ui/snapshot/snapshot_ios.mm index b373a03..af8cb47 100644 --- a/ui/snapshot/snapshot_ios.mm +++ b/ui/snapshot/snapshot_ios.mm @@ -4,6 +4,7 @@ #include "ui/snapshot/snapshot.h" +#include "base/callback.h" #include "ui/gfx/rect.h" namespace ui { @@ -22,4 +23,13 @@ bool GrabWindowSnapshot(gfx::NativeWindow window, return false; } +SNAPSHOT_EXPORT void GrapWindowSnapshotAsync( + gfx::NativeWindow window, + const gfx::Rect& snapshot_bounds, + const gfx::Size& target_size, + scoped_refptr<base::TaskRunner> background_task_runner, + GrapWindowSnapshotAsyncCallback callback) { + NOTIMPLEMENTED(); +} + } // namespace ui diff --git a/ui/snapshot/snapshot_mac.mm b/ui/snapshot/snapshot_mac.mm index abd8728..f86757b 100644 --- a/ui/snapshot/snapshot_mac.mm +++ b/ui/snapshot/snapshot_mac.mm @@ -6,6 +6,7 @@ #import <Cocoa/Cocoa.h> +#include "base/callback.h" #include "base/logging.h" #include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_nsobject.h" @@ -72,4 +73,13 @@ bool GrabWindowSnapshot(gfx::NativeWindow window, snapshot_bounds); } +SNAPSHOT_EXPORT void GrapWindowSnapshotAsync( + gfx::NativeWindow window, + const gfx::Rect& snapshot_bounds, + const gfx::Size& target_size, + scoped_refptr<base::TaskRunner> background_task_runner, + GrapWindowSnapshotAsyncCallback callback) { + NOTIMPLEMENTED(); +} + } // namespace ui diff --git a/ui/snapshot/snapshot_win.cc b/ui/snapshot/snapshot_win.cc index 8c2ff3b..fc157be 100644 --- a/ui/snapshot/snapshot_win.cc +++ b/ui/snapshot/snapshot_win.cc @@ -4,6 +4,7 @@ #include "ui/snapshot/snapshot_win.h" +#include "base/callback.h" #include "base/win/scoped_gdi_object.h" #include "base/win/scoped_hdc.h" #include "base/win/scoped_select_object.h" @@ -103,6 +104,7 @@ bool GrabHwndSnapshot(HWND window_handle, } // namespace internal #if !defined(USE_AURA) + bool GrabViewSnapshot(gfx::NativeView view_handle, std::vector<unsigned char>* png_representation, const gfx::Rect& snapshot_bounds) { @@ -116,6 +118,16 @@ bool GrabWindowSnapshot(gfx::NativeWindow window_handle, return internal::GrabHwndSnapshot(window_handle, snapshot_bounds, png_representation); } + +SNAPSHOT_EXPORT void GrapWindowSnapshotAsync( + gfx::NativeWindow window, + const gfx::Rect& snapshot_bounds, + const gfx::Size& target_size, + scoped_refptr<base::TaskRunner> background_task_runner, + GrapWindowSnapshotAsyncCallback callback) { + NOTIMPLEMENTED(); +} + #endif // !defined(USE_AURA) } // namespace ui |