1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_THUMBNAILS_THUMBNAILING_ALGORITHM_H_
6 #define CHROME_BROWSER_THUMBNAILS_THUMBNAILING_ALGORITHM_H_
8 #include "base/memory/ref_counted.h"
9 #include "chrome/browser/thumbnails/thumbnailing_context.h"
10 #include "ui/base/layout.h"
11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/geometry/size.h"
16 namespace thumbnails
{
18 // An interface abstracting thumbnailing algorithms. Instances are intended to
19 // be created by ThumbnailService's implementations and used by
20 // ThumbnailTabHelper as consumers of captured source images.
21 class ThumbnailingAlgorithm
22 : public base::RefCountedThreadSafe
<ThumbnailingAlgorithm
> {
24 typedef base::Callback
<void(const ThumbnailingContext
&, const SkBitmap
&)>
26 // Provides information necessary to crop-and-resize image data from a source
27 // canvas of |source_size|. Auxiliary |scale_factor| helps compute the target
28 // thumbnail size to be copied from the backing store, in pixels. Parameters
29 // of the required copy operation are assigned to |clipping_rect| (cropping
30 // rectangle for the source canvas) and |copy_size| (the size of the copied
31 // bitmap in pixels). The return value indicates the type of clipping that
33 virtual ClipResult
GetCanvasCopyInfo(const gfx::Size
& source_size
,
34 ui::ScaleFactor scale_factor
,
35 gfx::Rect
* clipping_rect
,
36 gfx::Size
* copy_size
) const = 0;
38 // Invoked to produce a thumbnail image from a |bitmap| extracted by the
39 // callee from source canvas according to instructions provided by a call
40 // to GetCanvasCopyInfo.
41 // Note that ProcessBitmap must be able to handle bitmaps which might have not
42 // been processed (scalled/cropped) as requested. |context| gives additional
43 // information on the source, including if and how it was clipped.
44 // The function shall invoke |callback| once done, passing in fully populated
45 // |context| along with resulting thumbnail bitmap.
46 virtual void ProcessBitmap(scoped_refptr
<ThumbnailingContext
> context
,
47 const ConsumerCallback
& callback
,
48 const SkBitmap
& bitmap
) = 0;
51 virtual ~ThumbnailingAlgorithm() {}
52 friend class base::RefCountedThreadSafe
<ThumbnailingAlgorithm
>;
55 } // namespace thumbnails
57 #endif // CHROME_BROWSER_THUMBNAILS_THUMBNAILING_ALGORITHM_H_