OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/content_based_thumbnailing_algorithm.h" | 5 #include "chrome/browser/thumbnails/content_based_thumbnailing_algorithm.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/task_scheduler/post_task.h" | 10 #include "base/task_scheduler/post_task.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 // This means that the source bitmap has been requested and at least | 126 // This means that the source bitmap has been requested and at least |
127 // clipped. Upstream code in same cases seems opportunistic and it may | 127 // clipped. Upstream code in same cases seems opportunistic and it may |
128 // not perform actual resizing if copying with resize is not supported. | 128 // not perform actual resizing if copying with resize is not supported. |
129 // In this case we will resize to the orignally requested copy size. | 129 // In this case we will resize to the orignally requested copy size. |
130 resize_target = context->requested_copy_size; | 130 resize_target = context->requested_copy_size; |
131 clipped_bitmap = received_bitmap; | 131 clipped_bitmap = received_bitmap; |
132 } | 132 } |
133 | 133 |
134 SkBitmap result_bitmap = SkBitmapOperations::DownsampleByTwoUntilSize( | 134 SkBitmap result_bitmap = SkBitmapOperations::DownsampleByTwoUntilSize( |
135 clipped_bitmap, resize_target.width(), resize_target.height()); | 135 clipped_bitmap, resize_target.width(), resize_target.height()); |
136 #if !defined(USE_AURA) | |
137 // If the bitmap has not been indeed resized, it has to be copied. In that | |
138 // case resampler simply returns a reference to the original bitmap, sitting | |
139 // in PlatformCanvas. One does not simply assign these 'magic' bitmaps to | |
140 // SkBitmap. They cannot be refcounted. | |
141 // | |
142 // With Aura, this does not happen since PlatformCanvas is platform | |
143 // idependent. | |
144 if (clipped_bitmap.width() == result_bitmap.width() && | |
145 clipped_bitmap.height() == result_bitmap.height()) { | |
146 clipped_bitmap.copyTo(&result_bitmap, kN32_SkColorType); | |
147 } | |
148 #endif | |
149 | 136 |
150 return result_bitmap; | 137 return result_bitmap; |
151 } | 138 } |
152 | 139 |
153 // static | 140 // static |
154 void ContentBasedThumbnailingAlgorithm::CreateRetargetedThumbnail( | 141 void ContentBasedThumbnailingAlgorithm::CreateRetargetedThumbnail( |
155 const SkBitmap& source_bitmap, | 142 const SkBitmap& source_bitmap, |
156 const gfx::Size& thumbnail_size, | 143 const gfx::Size& thumbnail_size, |
157 scoped_refptr<ThumbnailingContext> context, | 144 scoped_refptr<ThumbnailingContext> context, |
158 const ConsumerCallback& callback) { | 145 const ConsumerCallback& callback) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } else { | 219 } else { |
233 clipping_rect = gfx::Rect(source_size); | 220 clipping_rect = gfx::Rect(source_size); |
234 target_size->SetSize(source_size.width() / 2, source_size.height() / 2); | 221 target_size->SetSize(source_size.width() / 2, source_size.height() / 2); |
235 *clip_result = CLIP_RESULT_NOT_CLIPPED; | 222 *clip_result = CLIP_RESULT_NOT_CLIPPED; |
236 } | 223 } |
237 | 224 |
238 return clipping_rect; | 225 return clipping_rect; |
239 } | 226 } |
240 | 227 |
241 } // namespace thumbnails | 228 } // namespace thumbnails |
OLD | NEW |