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

Unified Diff: ui/snapshot/snapshot_android.cc

Issue 281003002: Make ui::Snapshot asynchronous on Android, remove CompositeAndReadback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: pixeltests: syntax Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/snapshot/snapshot.gyp ('k') | ui/snapshot/snapshot_async.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/snapshot/snapshot_android.cc
diff --git a/ui/snapshot/snapshot_android.cc b/ui/snapshot/snapshot_android.cc
index 837c13c8d4f1578446fa1b1a1c0529f629868e7a..49e276c579b08733197eb35e23010ba60da46a1f 100644
--- a/ui/snapshot/snapshot_android.cc
+++ b/ui/snapshot/snapshot_android.cc
@@ -4,13 +4,13 @@
#include "ui/snapshot/snapshot.h"
-#include "base/callback.h"
+#include "base/bind.h"
+#include "cc/output/copy_output_request.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/android/view_android.h"
#include "ui/base/android/window_android.h"
-#include "ui/gfx/display.h"
-#include "ui/gfx/image/image.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/screen.h"
+#include "ui/base/android/window_android_compositor.h"
+#include "ui/snapshot/snapshot_async.h"
namespace ui {
@@ -24,39 +24,53 @@ bool GrabViewSnapshot(gfx::NativeView view,
bool GrabWindowSnapshot(gfx::NativeWindow window,
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds) {
- gfx::Display display =
- gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
- gfx::Rect scaled_bounds =
- gfx::ScaleToEnclosingRect(snapshot_bounds,
- display.device_scale_factor());
- return window->GrabSnapshot(
- scaled_bounds.x(), scaled_bounds.y(), scaled_bounds.width(),
- scaled_bounds.height(), png_representation);
+ // Not supported in Android. Callers should fall back to the async version.
+ return false;
+}
+
+static void MakeAsyncCopyRequest(
+ gfx::NativeWindow window,
+ const gfx::Rect& source_rect,
+ const cc::CopyOutputRequest::CopyOutputRequestCallback& callback) {
+ scoped_ptr<cc::CopyOutputRequest> request =
+ cc::CopyOutputRequest::CreateBitmapRequest(callback);
+ request->set_area(source_rect);
+ window->GetCompositor()->RequestCopyOfOutputOnRootLayer(request.Pass());
}
void GrabWindowSnapshotAndScaleAsync(
gfx::NativeWindow window,
- const gfx::Rect& snapshot_bounds,
+ const gfx::Rect& source_rect,
const gfx::Size& target_size,
scoped_refptr<base::TaskRunner> background_task_runner,
- GrabWindowSnapshotAsyncCallback callback) {
- callback.Run(gfx::Image());
+ const GrabWindowSnapshotAsyncCallback& callback) {
+ MakeAsyncCopyRequest(window,
+ source_rect,
+ base::Bind(&SnapshotAsync::ScaleCopyOutputResult,
+ callback,
+ target_size,
+ background_task_runner));
}
-void GrabViewSnapshotAsync(
- gfx::NativeView view,
+void GrabWindowSnapshotAsync(
+ gfx::NativeWindow window,
const gfx::Rect& source_rect,
scoped_refptr<base::TaskRunner> background_task_runner,
const GrabWindowSnapshotAsyncPNGCallback& callback) {
- callback.Run(scoped_refptr<base::RefCountedBytes>());
+ MakeAsyncCopyRequest(window,
+ source_rect,
+ base::Bind(&SnapshotAsync::EncodeCopyOutputResult,
+ callback,
+ background_task_runner));
}
-void GrabWindowSnapshotAsync(
- gfx::NativeWindow window,
+void GrabViewSnapshotAsync(
+ gfx::NativeView view,
const gfx::Rect& source_rect,
scoped_refptr<base::TaskRunner> background_task_runner,
const GrabWindowSnapshotAsyncPNGCallback& callback) {
- callback.Run(scoped_refptr<base::RefCountedBytes>());
+ GrabWindowSnapshotAsync(
+ view->GetWindowAndroid(), source_rect, background_task_runner, callback);
}
} // namespace ui
« no previous file with comments | « ui/snapshot/snapshot.gyp ('k') | ui/snapshot/snapshot_async.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698