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

Side by Side Diff: chrome/browser/thumbnails/simple_thumbnail_crop.cc

Issue 15458003: Plugs in the new thumbnailing algorithm to ThumbnailTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit tests. Created 7 years, 7 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) 2013 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" 5 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "skia/ext/platform_canvas.h" 9 #include "skia/ext/platform_canvas.h"
10 #include "ui/gfx/color_utils.h" 10 #include "ui/gfx/color_utils.h"
(...skipping 18 matching lines...) Expand all
29 ui::ScaleFactor scale_factor, 29 ui::ScaleFactor scale_factor,
30 gfx::Rect* clipping_rect, 30 gfx::Rect* clipping_rect,
31 gfx::Size* target_size) const { 31 gfx::Size* target_size) const {
32 DCHECK(!source_size.IsEmpty()); 32 DCHECK(!source_size.IsEmpty());
33 ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED; 33 ClipResult clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED;
34 *clipping_rect = GetClippingRect(source_size, target_size_, &clip_result); 34 *clipping_rect = GetClippingRect(source_size, target_size_, &clip_result);
35 *target_size = GetCopySizeForThumbnail(scale_factor, target_size_); 35 *target_size = GetCopySizeForThumbnail(scale_factor, target_size_);
36 return clip_result; 36 return clip_result;
37 } 37 }
38 38
39 void SimpleThumbnailCrop::ProcessBitmap(ThumbnailingContext* context, 39 void SimpleThumbnailCrop::ProcessBitmap(
40 const ConsumerCallback& callback, 40 scoped_refptr<ThumbnailingContext> context,
41 const SkBitmap& bitmap) { 41 const ConsumerCallback& callback,
42 const SkBitmap& bitmap) {
42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 43 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
43 if (bitmap.isNull() || bitmap.empty()) 44 if (bitmap.isNull() || bitmap.empty())
44 return; 45 return;
45 46
46 SkBitmap thumbnail = CreateThumbnail(bitmap, 47 SkBitmap thumbnail = CreateThumbnail(bitmap,
47 GetThumbnailSizeInPixel(), 48 GetThumbnailSizeInPixel(),
48 &context->clip_result); 49 &context->clip_result);
49 50
50 context->score.boring_score = CalculateBoringScore(thumbnail); 51 context->score.boring_score = CalculateBoringScore(thumbnail);
51 context->score.good_clipping = 52 context->score.good_clipping =
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 default: 128 default:
128 DLOG(WARNING) << "Unsupported scale factor. Use the same copy size as " 129 DLOG(WARNING) << "Unsupported scale factor. Use the same copy size as "
129 << "ui::SCALE_FACTOR_100P"; 130 << "ui::SCALE_FACTOR_100P";
130 copy_size = gfx::ToFlooredSize(gfx::ScaleSize( 131 copy_size = gfx::ToFlooredSize(gfx::ScaleSize(
131 copy_size, ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P))); 132 copy_size, ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P)));
132 break; 133 break;
133 } 134 }
134 return copy_size; 135 return copy_size;
135 } 136 }
136 137
137 SimpleThumbnailCrop::~SimpleThumbnailCrop() {
138 }
139
140 // Returns the size of the thumbnail stored in the database in pixel.
141 gfx::Size SimpleThumbnailCrop::GetThumbnailSizeInPixel() const {
142 // Determine the resolution of the thumbnail based on the maximum scale
143 // factor.
144 // TODO(mazda|oshima): Update thumbnail when the max scale factor changes.
145 // crbug.com/159157.
146 float max_scale_factor =
147 ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
148 return gfx::ToFlooredSize(gfx::ScaleSize(target_size_, max_scale_factor));
149 }
150
151 gfx::Rect SimpleThumbnailCrop::GetClippingRect(const gfx::Size& source_size, 138 gfx::Rect SimpleThumbnailCrop::GetClippingRect(const gfx::Size& source_size,
152 const gfx::Size& desired_size, 139 const gfx::Size& desired_size,
153 ClipResult* clip_result) { 140 ClipResult* clip_result) {
154 DCHECK(clip_result); 141 DCHECK(clip_result);
155 142
156 float desired_aspect = 143 float desired_aspect =
157 static_cast<float>(desired_size.width()) / desired_size.height(); 144 static_cast<float>(desired_size.width()) / desired_size.height();
158 145
159 // Get the clipping rect so that we can preserve the aspect ratio while 146 // Get the clipping rect so that we can preserve the aspect ratio while
160 // filling the destination. 147 // filling the destination.
(...skipping 22 matching lines...) Expand all
183 gfx::Rect(source_size.width(), source_size.width() / desired_aspect); 170 gfx::Rect(source_size.width(), source_size.width() / desired_aspect);
184 *clip_result = thumbnails::CLIP_RESULT_TALLER_THAN_WIDE; 171 *clip_result = thumbnails::CLIP_RESULT_TALLER_THAN_WIDE;
185 } else { 172 } else {
186 clipping_rect = gfx::Rect(source_size); 173 clipping_rect = gfx::Rect(source_size);
187 *clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED; 174 *clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED;
188 } 175 }
189 } 176 }
190 return clipping_rect; 177 return clipping_rect;
191 } 178 }
192 179
180 SimpleThumbnailCrop::~SimpleThumbnailCrop() {
181 }
182
183 // Returns the size of the thumbnail stored in the database in pixel.
184 gfx::Size SimpleThumbnailCrop::GetThumbnailSizeInPixel() const {
185 // Determine the resolution of the thumbnail based on the maximum scale
186 // factor.
187 // TODO(mazda|oshima): Update thumbnail when the max scale factor changes.
188 // crbug.com/159157.
189 float max_scale_factor =
190 ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
191 return gfx::ToFlooredSize(gfx::ScaleSize(target_size_, max_scale_factor));
192 }
193
193 // Creates a downsampled thumbnail from the given bitmap. 194 // Creates a downsampled thumbnail from the given bitmap.
194 // store. The returned bitmap will be isNull if there was an error creating it. 195 // store. The returned bitmap will be isNull if there was an error creating it.
195 SkBitmap SimpleThumbnailCrop::CreateThumbnail(const SkBitmap& bitmap, 196 SkBitmap SimpleThumbnailCrop::CreateThumbnail(const SkBitmap& bitmap,
196 const gfx::Size& desired_size, 197 const gfx::Size& desired_size,
197 ClipResult* clip_result) { 198 ClipResult* clip_result) {
198 base::TimeTicks begin_compute_thumbnail = base::TimeTicks::Now(); 199 base::TimeTicks begin_compute_thumbnail = base::TimeTicks::Now();
199 200
200 SkBitmap clipped_bitmap; 201 SkBitmap clipped_bitmap;
201 if (*clip_result == thumbnails::CLIP_RESULT_UNPROCESSED) { 202 if (*clip_result == thumbnails::CLIP_RESULT_UNPROCESSED) {
202 // Clip the pixels that will commonly hold a scrollbar, which looks bad in 203 // Clip the pixels that will commonly hold a scrollbar, which looks bad in
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 clipped_bitmap.height() == result.height()) 238 clipped_bitmap.height() == result.height())
238 clipped_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); 239 clipped_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config);
239 #endif 240 #endif
240 241
241 HISTOGRAM_TIMES(kThumbnailHistogramName, 242 HISTOGRAM_TIMES(kThumbnailHistogramName,
242 base::TimeTicks::Now() - begin_compute_thumbnail); 243 base::TimeTicks::Now() - begin_compute_thumbnail);
243 return result; 244 return result;
244 } 245 }
245 246
246 } 247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698