summaryrefslogtreecommitdiffstats
path: root/chrome/browser/thumbnails/thumbnailing_algorithm.h
blob: 11b447632237ee9d9e2e4f01db31250c750349d0 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2013 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.

#ifndef CHROME_BROWSER_THUMBNAILS_THUMBNAILING_ALGORITHM_H_
#define CHROME_BROWSER_THUMBNAILS_THUMBNAILING_ALGORITHM_H_

#include "base/memory/ref_counted.h"
#include "chrome/browser/thumbnails/thumbnailing_context.h"
#include "ui/base/layout.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"

class SkBitmap;

namespace thumbnails {

// An interface abstracting thumbnailing algorithms. Instances are intended to
// be created by ThumbnailService's implementations and used by
// ThumbnailTabHelper as consumers of captured source images.
class ThumbnailingAlgorithm
    : public base::RefCountedThreadSafe<ThumbnailingAlgorithm> {
 public:
  typedef base::Callback<void(const ThumbnailingContext&, const SkBitmap&)>
      ConsumerCallback;
  // Provides information necessary to crop-and-resize image data from a source
  // canvas of |source_size|. Auxiliary |scale_factor| helps compute the target
  // thumbnail size. Parameters of the required copy operation are assigned to
  // |clipping_rect| (cropping rectangle for the source canvas) and
  // |target_size| (the size of the target bitmap).
  // The return value indicates the type of clipping that will be done.
  virtual ClipResult GetCanvasCopyInfo(const gfx::Size& source_size,
                                       ui::ScaleFactor scale_factor,
                                       gfx::Rect* clipping_rect,
                                       gfx::Size* target_size) const = 0;

  // Invoked to produce a thumbnail image from a |bitmap| extracted by the
  // callee from source canvas according to instructions provided by a call
  // to GetCanvasCopyInfo.
  // Note that ProcessBitmap must be able to handle bitmaps which might have not
  // been processed (scalled/cropped) as requested. |context| gives additional
  // information on the source, including if and how it was clipped.
  // The function shall invoke |callback| once done, passing in fully populated
  // |context| along with resulting thumbnail bitmap.
  virtual void ProcessBitmap(scoped_refptr<ThumbnailingContext> context,
                             const ConsumerCallback& callback,
                             const SkBitmap& bitmap) = 0;

 protected:
  virtual ~ThumbnailingAlgorithm() {}
  friend class base::RefCountedThreadSafe<ThumbnailingAlgorithm>;
};

}

#endif  // CHROME_BROWSER_THUMBNAILS_THUMBNAILING_ALGORITHM_H_