| OLD | NEW |
| 1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 canvas.drawBitmapRect(resampled, 0, destRect, &paint); | 210 canvas.drawBitmapRect(resampled, 0, destRect, &paint); |
| 211 } else { | 211 } else { |
| 212 // We should only resize the exposed part of the bitmap to do the | 212 // We should only resize the exposed part of the bitmap to do the |
| 213 // minimal possible work. | 213 // minimal possible work. |
| 214 gfx::Rect destBitmapSubset(destBitmapSubsetSkI.fLeft, | 214 gfx::Rect destBitmapSubset(destBitmapSubsetSkI.fLeft, |
| 215 destBitmapSubsetSkI.fTop, | 215 destBitmapSubsetSkI.fTop, |
| 216 destBitmapSubsetSkI.width(), | 216 destBitmapSubsetSkI.width(), |
| 217 destBitmapSubsetSkI.height()); | 217 destBitmapSubsetSkI.height()); |
| 218 | 218 |
| 219 // Resample the needed part of the image. | 219 // Resample the needed part of the image. |
| 220 SkBitmap resampled = gfx::ImageOperations::Resize(subset, | 220 SkBitmap resampled = skia::ImageOperations::Resize(subset, |
| 221 gfx::ImageOperations::RESIZE_LANCZOS3, | 221 skia::ImageOperations::RESIZE_LANCZOS3, |
| 222 gfx::Size(destRectRounded.width(), destRectRounded.height()), | 222 destRectRounded.width(), destRectRounded.height(), |
| 223 destBitmapSubset); | 223 destBitmapSubset); |
| 224 | 224 |
| 225 // Compute where the new bitmap should be drawn. Since our new bitmap | 225 // Compute where the new bitmap should be drawn. Since our new bitmap |
| 226 // may be smaller than the original, we have to shift it over by the | 226 // may be smaller than the original, we have to shift it over by the |
| 227 // same amount that we cut off the top and left. | 227 // same amount that we cut off the top and left. |
| 228 SkRect offsetDestRect = { | 228 SkRect offsetDestRect = { |
| 229 destBitmapSubset.x() + destRect.fLeft, | 229 destBitmapSubset.x() + destRect.fLeft, |
| 230 destBitmapSubset.y() + destRect.fTop, | 230 destBitmapSubset.y() + destRect.fTop, |
| 231 destBitmapSubset.right() + destRect.fLeft, | 231 destBitmapSubset.right() + destRect.fLeft, |
| 232 destBitmapSubset.bottom() + destRect.fTop }; | 232 destBitmapSubset.bottom() + destRect.fTop }; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 resampling = computeResamplingMode(*bitmap, | 343 resampling = computeResamplingMode(*bitmap, |
| 344 srcRect.width(), srcRect.height(), | 344 srcRect.width(), srcRect.height(), |
| 345 dest_bitmap_width, dest_bitmap_height); | 345 dest_bitmap_width, dest_bitmap_height); |
| 346 } | 346 } |
| 347 | 347 |
| 348 // Load the transform WebKit requested. | 348 // Load the transform WebKit requested. |
| 349 SkMatrix matrix(patternTransform); | 349 SkMatrix matrix(patternTransform); |
| 350 | 350 |
| 351 if (resampling == RESAMPLE_AWESOME) { | 351 if (resampling == RESAMPLE_AWESOME) { |
| 352 // Do nice resampling. | 352 // Do nice resampling. |
| 353 SkBitmap resampled = gfx::ImageOperations::Resize(src_subset, | 353 SkBitmap resampled = skia::ImageOperations::Resize(src_subset, |
| 354 gfx::ImageOperations::RESIZE_LANCZOS3, | 354 skia::ImageOperations::RESIZE_LANCZOS3, |
| 355 gfx::Size(static_cast<int>(dest_bitmap_width), | 355 static_cast<int>(dest_bitmap_width), |
| 356 static_cast<int>(dest_bitmap_height))); | 356 static_cast<int>(dest_bitmap_height)); |
| 357 shader = SkShader::CreateBitmapShader( | 357 shader = SkShader::CreateBitmapShader( |
| 358 resampled, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); | 358 resampled, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); |
| 359 | 359 |
| 360 // Since we just resized the bitmap, we need to undo the scale set in | 360 // Since we just resized the bitmap, we need to undo the scale set in |
| 361 // the image transform. | 361 // the image transform. |
| 362 matrix.setScaleX(SkIntToScalar(1)); | 362 matrix.setScaleX(SkIntToScalar(1)); |
| 363 matrix.setScaleY(SkIntToScalar(1)); | 363 matrix.setScaleY(SkIntToScalar(1)); |
| 364 } else { | 364 } else { |
| 365 // No need to do nice resampling. | 365 // No need to do nice resampling. |
| 366 shader = SkShader::CreateBitmapShader( | 366 shader = SkShader::CreateBitmapShader( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 PassRefPtr<BitmapImageSingleFrameSkia> BitmapImageSingleFrameSkia::create( | 447 PassRefPtr<BitmapImageSingleFrameSkia> BitmapImageSingleFrameSkia::create( |
| 448 const SkBitmap& bitmap) | 448 const SkBitmap& bitmap) |
| 449 { | 449 { |
| 450 RefPtr<BitmapImageSingleFrameSkia> image(new BitmapImageSingleFrameSkia()); | 450 RefPtr<BitmapImageSingleFrameSkia> image(new BitmapImageSingleFrameSkia()); |
| 451 if (!bitmap.copyTo(&image->m_nativeImage, bitmap.config())) | 451 if (!bitmap.copyTo(&image->m_nativeImage, bitmap.config())) |
| 452 return 0; | 452 return 0; |
| 453 return image.release(); | 453 return image.release(); |
| 454 } | 454 } |
| 455 | 455 |
| 456 } // namespace WebCore | 456 } // namespace WebCore |
| OLD | NEW |