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

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: Fixed up a compile problem (indpendent change). Created 7 years, 6 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(
47 GetThumbnailSizeInPixel(), 48 bitmap,
48 &context->clip_result); 49 ComputeTargetSizeAtMaximumScale(target_size_),
50 &context->clip_result);
49 51
50 context->score.boring_score = CalculateBoringScore(thumbnail); 52 context->score.boring_score = CalculateBoringScore(thumbnail);
51 context->score.good_clipping = 53 context->score.good_clipping =
52 (context->clip_result == CLIP_RESULT_WIDER_THAN_TALL || 54 (context->clip_result == CLIP_RESULT_WIDER_THAN_TALL ||
53 context->clip_result == CLIP_RESULT_TALLER_THAN_WIDE || 55 context->clip_result == CLIP_RESULT_TALLER_THAN_WIDE ||
54 context->clip_result == CLIP_RESULT_NOT_CLIPPED); 56 context->clip_result == CLIP_RESULT_NOT_CLIPPED);
55 57
56 callback.Run(*context, thumbnail); 58 callback.Run(*context, thumbnail);
57 } 59 }
58 60
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 default: 129 default:
128 DLOG(WARNING) << "Unsupported scale factor. Use the same copy size as " 130 DLOG(WARNING) << "Unsupported scale factor. Use the same copy size as "
129 << "ui::SCALE_FACTOR_100P"; 131 << "ui::SCALE_FACTOR_100P";
130 copy_size = gfx::ToFlooredSize(gfx::ScaleSize( 132 copy_size = gfx::ToFlooredSize(gfx::ScaleSize(
131 copy_size, ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P))); 133 copy_size, ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P)));
132 break; 134 break;
133 } 135 }
134 return copy_size; 136 return copy_size;
135 } 137 }
136 138
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, 139 gfx::Rect SimpleThumbnailCrop::GetClippingRect(const gfx::Size& source_size,
152 const gfx::Size& desired_size, 140 const gfx::Size& desired_size,
153 ClipResult* clip_result) { 141 ClipResult* clip_result) {
154 DCHECK(clip_result); 142 DCHECK(clip_result);
155 143
156 float desired_aspect = 144 float desired_aspect =
157 static_cast<float>(desired_size.width()) / desired_size.height(); 145 static_cast<float>(desired_size.width()) / desired_size.height();
158 146
159 // Get the clipping rect so that we can preserve the aspect ratio while 147 // Get the clipping rect so that we can preserve the aspect ratio while
160 // filling the destination. 148 // filling the destination.
(...skipping 22 matching lines...) Expand all
183 gfx::Rect(source_size.width(), source_size.width() / desired_aspect); 171 gfx::Rect(source_size.width(), source_size.width() / desired_aspect);
184 *clip_result = thumbnails::CLIP_RESULT_TALLER_THAN_WIDE; 172 *clip_result = thumbnails::CLIP_RESULT_TALLER_THAN_WIDE;
185 } else { 173 } else {
186 clipping_rect = gfx::Rect(source_size); 174 clipping_rect = gfx::Rect(source_size);
187 *clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED; 175 *clip_result = thumbnails::CLIP_RESULT_NOT_CLIPPED;
188 } 176 }
189 } 177 }
190 return clipping_rect; 178 return clipping_rect;
191 } 179 }
192 180
181 // static
182 gfx::Size SimpleThumbnailCrop::ComputeTargetSizeAtMaximumScale(
183 const gfx::Size& given_size) {
184 // TODO(mazda|oshima): Update thumbnail when the max scale factor changes.
185 // crbug.com/159157.
186 float max_scale_factor =
187 ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
188 return gfx::ToFlooredSize(gfx::ScaleSize(given_size, max_scale_factor));
189 }
190
191 SimpleThumbnailCrop::~SimpleThumbnailCrop() {
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
« no previous file with comments | « chrome/browser/thumbnails/simple_thumbnail_crop.h ('k') | chrome/browser/thumbnails/simple_thumbnail_crop_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698