OLD | NEW |
---|---|
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, | |
brettw
2011/01/21 00:09:17
Can you rename this to kNoOptions (or something si
satorux1
2011/01/21 04:53:43
Done.
| |
46 // Request a clipped thumbnail with the aspect ratio preserved. | |
47 kClippedThumbnail = 1 << 0, | |
48 }; | |
49 | |
29 // This class will do nothing until you call StartThumbnailing. | 50 // This class will do nothing until you call StartThumbnailing. |
30 ThumbnailGenerator(); | 51 ThumbnailGenerator(); |
31 ~ThumbnailGenerator(); | 52 ~ThumbnailGenerator(); |
32 | 53 |
33 // Ensures that we're properly hooked in to generated thumbnails. This can | 54 // Ensures that we're properly hooked in to generated thumbnails. This can |
34 // be called repeatedly and with wild abandon to no ill effect. | 55 // be called repeatedly and with wild abandon to no ill effect. |
35 void StartThumbnailing(); | 56 void StartThumbnailing(); |
36 | 57 |
37 // This registers a callback that can receive the resulting SkBitmap | 58 // This registers a callback that can receive the resulting SkBitmap |
38 // from the renderer when it is done rendering it. This differs | 59 // from the renderer when it is done rendering it. This differs |
(...skipping 15 matching lines...) Expand all Loading... | |
54 void AskForSnapshot(RenderWidgetHost* renderer, | 75 void AskForSnapshot(RenderWidgetHost* renderer, |
55 bool prefer_backing_store, | 76 bool prefer_backing_store, |
56 ThumbnailReadyCallback* callback, | 77 ThumbnailReadyCallback* callback, |
57 gfx::Size page_size, | 78 gfx::Size page_size, |
58 gfx::Size desired_size); | 79 gfx::Size desired_size); |
59 | 80 |
60 // This returns a thumbnail of a fixed, small size for the given | 81 // This returns a thumbnail of a fixed, small size for the given |
61 // renderer. | 82 // renderer. |
62 SkBitmap GetThumbnailForRenderer(RenderWidgetHost* renderer) const; | 83 SkBitmap GetThumbnailForRenderer(RenderWidgetHost* renderer) const; |
63 | 84 |
85 // This returns a thumbnail of a fixed, small size for the given | |
86 // renderer. |options| is a bitmask of ThumbnailOptions. If | |
87 // |clip_result| is non-NULL, the result of clipping will be written. | |
88 SkBitmap GetThumbnailForRendererWithOptions(RenderWidgetHost* renderer, | |
89 int options, | |
90 ClipResult* clip_result) const; | |
91 | |
64 // Start or stop monitoring notifications for |renderer| based on the value | 92 // Start or stop monitoring notifications for |renderer| based on the value |
65 // of |monitor|. | 93 // of |monitor|. |
66 void MonitorRenderer(RenderWidgetHost* renderer, bool monitor); | 94 void MonitorRenderer(RenderWidgetHost* renderer, bool monitor); |
67 | 95 |
68 #ifdef UNIT_TEST | 96 #ifdef UNIT_TEST |
69 // When true, the class will not use a timeout to do the expiration. This | 97 // 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. | 98 // 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 | 99 // Unit tests case use this to test expiration by choosing when the message |
72 // loop runs. | 100 // loop runs. |
73 void set_no_timeout(bool no_timeout) { no_timeout_ = no_timeout; } | 101 void set_no_timeout(bool no_timeout) { no_timeout_ = no_timeout; } |
74 #endif | 102 #endif |
75 | 103 |
104 // Calculates how "boring" a thumbnail is. The boring score is the | |
105 // 0,1 ranged percentage of pixels that are the most common | |
106 // luma. Higher boring scores indicate that a higher percentage of a | |
107 // bitmap are all the same brightness. | |
108 static double CalculateBoringScore(SkBitmap* bitmap); | |
brettw
2011/01/21 00:09:17
Moving the thumbnail computation, you can remove t
| |
109 | |
110 // Gets the clipped bitmap from |bitmap| per the aspect ratio of the | |
111 // desired width and the desired height. For instance, if the input | |
112 // bitmap is vertically long (ex. 400x900) and the desired size is | |
113 // square (ex. 100x100), the clipped bitmap will be the top half of the | |
114 // input bitmap (400x400). | |
115 static SkBitmap GetClippedBitmap(const SkBitmap& bitmap, | |
116 int desired_width, | |
117 int desired_height, | |
118 ClipResult* clip_result); | |
76 private: | 119 private: |
77 // RenderWidgetHostPaintingObserver implementation. | 120 // RenderWidgetHostPaintingObserver implementation. |
78 virtual void WidgetWillDestroyBackingStore(RenderWidgetHost* widget, | 121 virtual void WidgetWillDestroyBackingStore(RenderWidgetHost* widget, |
79 BackingStore* backing_store); | 122 BackingStore* backing_store); |
80 virtual void WidgetDidUpdateBackingStore(RenderWidgetHost* widget); | 123 virtual void WidgetDidUpdateBackingStore(RenderWidgetHost* widget); |
81 | 124 |
82 virtual void WidgetDidReceivePaintAtSizeAck( | 125 virtual void WidgetDidReceivePaintAtSizeAck( |
83 RenderWidgetHost* widget, | 126 RenderWidgetHost* widget, |
84 int tag, | 127 int tag, |
85 const gfx::Size& size); | 128 const gfx::Size& size); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 // Map of callback objects by sequence number. | 165 // Map of callback objects by sequence number. |
123 struct AsyncRequestInfo; | 166 struct AsyncRequestInfo; |
124 typedef std::map<int, | 167 typedef std::map<int, |
125 linked_ptr<AsyncRequestInfo> > ThumbnailCallbackMap; | 168 linked_ptr<AsyncRequestInfo> > ThumbnailCallbackMap; |
126 ThumbnailCallbackMap callback_map_; | 169 ThumbnailCallbackMap callback_map_; |
127 | 170 |
128 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator); | 171 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator); |
129 }; | 172 }; |
130 | 173 |
131 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ | 174 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ |
OLD | NEW |