summaryrefslogtreecommitdiffstats
path: root/chromium/ui/snapshot/snapshot_android.cc
blob: f175a87ce743cb9f04d0c2ae7dd0be91da0ecebd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/snapshot/snapshot.h"

#include "ui/base/android/view_android.h"
#include "ui/base/android/window_android.h"
#include "ui/gfx/display.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"

namespace ui {

bool GrabViewSnapshot(gfx::NativeView view,
                      std::vector<unsigned char>* png_representation,
                      const gfx::Rect& snapshot_bounds) {
  return GrabWindowSnapshot(
      view->GetWindowAndroid(), png_representation, snapshot_bounds);
}

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);
}

}  // namespace ui