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

Side by Side Diff: chrome/browser/tab_contents/thumbnail_generator.h

Issue 6246007: Generate thumbnails in the browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ 6 #define CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/linked_ptr.h" 15 #include "base/linked_ptr.h"
16 #include "base/lock.h" 16 #include "base/lock.h"
17 #include "base/timer.h" 17 #include "base/timer.h"
18 #include "chrome/browser/renderer_host/backing_store.h" 18 #include "chrome/browser/renderer_host/backing_store.h"
19 #include "chrome/common/notification_observer.h" 19 #include "chrome/common/notification_observer.h"
20 #include "chrome/common/notification_registrar.h" 20 #include "chrome/common/notification_registrar.h"
21 21
22 class RenderWidgetHost; 22 class RenderWidgetHost;
23 class SkBitmap; 23 class SkBitmap;
24 class TabContents; 24 class TabContents;
25 25
26 class ThumbnailGenerator : NotificationObserver { 26 class ThumbnailGenerator : NotificationObserver {
27 public: 27 public:
28 typedef Callback1<const SkBitmap&>::Type ThumbnailReadyCallback; 28 typedef Callback1<const SkBitmap&>::Type ThumbnailReadyCallback;
29 // The result of clipping. This can be used to determine if the
30 // generated thumbnail is good or not.
31 enum ClipResult {
32 // The source image is smaller.
33 kSourceIsSmaller,
34 // Wider than tall, clip horizontally.
35 kWiderThanTall,
36 // Taller than wide, clip vertically.
37 kTallerThanWide,
38 // The source and destination aspect ratios are identical.
39 kNotClipped,
40 };
41
42 // Bitmasks of options for generating a thumbnail.
43 enum ThumbnailOptions {
44 // No options.
45 kNone = 0,
46 // Request a clipped thumbnail with the aspect ratio preserved.
47 kClippedThumbnail = 1 << 0,
48 // Calculate the boring score.
49 kBoringScore = 1 << 1,
50 };
51
52 // The result of thumbnailing.
53 struct ThumbnailResult {
54 ThumbnailResult() : clip_result(kNotClipped), boring_score(0.0) {}
55
56 ClipResult clip_result;
57 // The boring score is the 0,1 ranged percentage of boringness. Higher
58 // boring scores indicate that the generated thumbnail is more like empty.
59 double boring_score;
60 };
61
29 // This class will do nothing until you call StartThumbnailing. 62 // This class will do nothing until you call StartThumbnailing.
30 ThumbnailGenerator(); 63 ThumbnailGenerator();
31 ~ThumbnailGenerator(); 64 ~ThumbnailGenerator();
32 65
33 // Ensures that we're properly hooked in to generated thumbnails. This can 66 // Ensures that we're properly hooked in to generated thumbnails. This can
34 // be called repeatedly and with wild abandon to no ill effect. 67 // be called repeatedly and with wild abandon to no ill effect.
35 void StartThumbnailing(); 68 void StartThumbnailing();
36 69
37 // This registers a callback that can receive the resulting SkBitmap 70 // This registers a callback that can receive the resulting SkBitmap
38 // from the renderer when it is done rendering it. This differs 71 // from the renderer when it is done rendering it. This differs
(...skipping 15 matching lines...) Expand all
54 void AskForSnapshot(RenderWidgetHost* renderer, 87 void AskForSnapshot(RenderWidgetHost* renderer,
55 bool prefer_backing_store, 88 bool prefer_backing_store,
56 ThumbnailReadyCallback* callback, 89 ThumbnailReadyCallback* callback,
57 gfx::Size page_size, 90 gfx::Size page_size,
58 gfx::Size desired_size); 91 gfx::Size desired_size);
59 92
60 // This returns a thumbnail of a fixed, small size for the given 93 // This returns a thumbnail of a fixed, small size for the given
61 // renderer. 94 // renderer.
62 SkBitmap GetThumbnailForRenderer(RenderWidgetHost* renderer) const; 95 SkBitmap GetThumbnailForRenderer(RenderWidgetHost* renderer) const;
63 96
97 // This returns a thumbnail of a fixed, small size for the given
98 // renderer. |options| is a bitmask of ThumbnailOptions. If
99 // |thumbnail_result| is non-NULL, additional information like the
100 // boring boring score will be stored in it.
101 SkBitmap GetThumbnailForRendererWithOptions(RenderWidgetHost* renderer,
102 int options,
103 ThumbnailResult* result) const;
104
64 // Start or stop monitoring notifications for |renderer| based on the value 105 // Start or stop monitoring notifications for |renderer| based on the value
65 // of |monitor|. 106 // of |monitor|.
66 void MonitorRenderer(RenderWidgetHost* renderer, bool monitor); 107 void MonitorRenderer(RenderWidgetHost* renderer, bool monitor);
67 108
68 #ifdef UNIT_TEST 109 #ifdef UNIT_TEST
69 // When true, the class will not use a timeout to do the expiration. This 110 // When true, the class will not use a timeout to do the expiration. This
70 // will cause expiration to happen on the next run of the message loop. 111 // will cause expiration to happen on the next run of the message loop.
71 // Unit tests case use this to test expiration by choosing when the message 112 // Unit tests case use this to test expiration by choosing when the message
72 // loop runs. 113 // loop runs.
73 void set_no_timeout(bool no_timeout) { no_timeout_ = no_timeout; } 114 void set_no_timeout(bool no_timeout) { no_timeout_ = no_timeout; }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Map of callback objects by sequence number. 163 // Map of callback objects by sequence number.
123 struct AsyncRequestInfo; 164 struct AsyncRequestInfo;
124 typedef std::map<int, 165 typedef std::map<int,
125 linked_ptr<AsyncRequestInfo> > ThumbnailCallbackMap; 166 linked_ptr<AsyncRequestInfo> > ThumbnailCallbackMap;
126 ThumbnailCallbackMap callback_map_; 167 ThumbnailCallbackMap callback_map_;
127 168
128 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator); 169 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator);
129 }; 170 };
130 171
131 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ 172 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698