summaryrefslogtreecommitdiff
path: root/chromium/ui/snapshot/snapshot.cc
blob: aaee01f12abb57d8dde73a91ef7ed957234b63ff (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
36
37
38
39
40
41
// Copyright 2017 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 "base/bind.h"
#include "base/callback.h"
#include "base/task_runner_util.h"
#include "ui/gfx/image/image.h"

namespace ui {

namespace {

scoped_refptr<base::RefCountedMemory> EncodeImage(const gfx::Image& image) {
  return image.As1xPNGBytes();
}

void EncodeImageAndSchedulePNGCallback(
    scoped_refptr<base::TaskRunner> background_task_runner,
    const GrabWindowSnapshotAsyncPNGCallback& callback,
    const gfx::Image& image) {
  base::PostTaskAndReplyWithResult(background_task_runner.get(), FROM_HERE,
                                   base::Bind(EncodeImage, image), callback);
}

}  // namespace

void GrabWindowSnapshotAsyncPNG(
    gfx::NativeWindow window,
    const gfx::Rect& source_rect,
    scoped_refptr<base::TaskRunner> background_task_runner,
    const GrabWindowSnapshotAsyncPNGCallback& callback) {
  GrabWindowSnapshotAsync(
      window, source_rect,
      base::Bind(EncodeImageAndSchedulePNGCallback,
                 std::move(background_task_runner), callback));
}

}  // namespace ui