| OLD | NEW |
| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 clipped_bitmap = GetClippedBitmap( | 170 clipped_bitmap = GetClippedBitmap( |
| 171 bmp, desired_size.width(), desired_size.height(), clip_result); | 171 bmp, desired_size.width(), desired_size.height(), clip_result); |
| 172 } else { | 172 } else { |
| 173 clipped_bitmap = bitmap; | 173 clipped_bitmap = bitmap; |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Need to resize it to the size we want, so downsample until it's | 176 // Need to resize it to the size we want, so downsample until it's |
| 177 // close, and let the caller make it the exact size if desired. | 177 // close, and let the caller make it the exact size if desired. |
| 178 SkBitmap result = SkBitmapOperations::DownsampleByTwoUntilSize( | 178 SkBitmap result = SkBitmapOperations::DownsampleByTwoUntilSize( |
| 179 clipped_bitmap, desired_size.width(), desired_size.height()); | 179 clipped_bitmap, desired_size.width(), desired_size.height()); |
| 180 #if !defined(USE_AURA) | |
| 181 // This is a bit subtle. SkBitmaps are refcounted, but the magic | |
| 182 // ones in PlatformCanvas can't be assigned to SkBitmap with proper | |
| 183 // refcounting. If the bitmap doesn't change, then the downsampler | |
| 184 // will return the input bitmap, which will be the reference to the | |
| 185 // weird PlatformCanvas one insetad of a regular one. To get a | |
| 186 // regular refcounted bitmap, we need to copy it. | |
| 187 // | |
| 188 // On Aura, the PlatformCanvas is platform-independent and does not have | |
| 189 // any native platform resources that can't be refounted, so this issue does | |
| 190 // not occur. | |
| 191 // | |
| 192 // Note that GetClippedBitmap() does extractSubset() but it won't copy | |
| 193 // the pixels, hence we check result size == clipped_bitmap size here. | |
| 194 if (clipped_bitmap.width() == result.width() && | |
| 195 clipped_bitmap.height() == result.height()) | |
| 196 clipped_bitmap.copyTo(&result, kN32_SkColorType); | |
| 197 #endif | |
| 198 | 180 |
| 199 LOCAL_HISTOGRAM_TIMES(kThumbnailHistogramName, | 181 LOCAL_HISTOGRAM_TIMES(kThumbnailHistogramName, |
| 200 base::TimeTicks::Now() - begin_compute_thumbnail); | 182 base::TimeTicks::Now() - begin_compute_thumbnail); |
| 201 return result; | 183 return result; |
| 202 } | 184 } |
| 203 | 185 |
| 204 } // namespace thumbnails | 186 } // namespace thumbnails |
| OLD | NEW |