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 25 matching lines...) Expand all Loading... |
36 #include "FloatRect.h" | 36 #include "FloatRect.h" |
37 #include "GraphicsContext.h" | 37 #include "GraphicsContext.h" |
38 #include "Logging.h" | 38 #include "Logging.h" |
39 #include "NativeImageSkia.h" | 39 #include "NativeImageSkia.h" |
40 #include "NotImplemented.h" | 40 #include "NotImplemented.h" |
41 #include "PlatformContextSkia.h" | 41 #include "PlatformContextSkia.h" |
42 #include "PlatformString.h" | 42 #include "PlatformString.h" |
43 #include "SkiaUtils.h" | 43 #include "SkiaUtils.h" |
44 #include "SkShader.h" | 44 #include "SkShader.h" |
45 | 45 |
46 #include "base/gfx/image_operations.h" // TODO(brettw) remove this dependency. | 46 #include "skia/ext/image_operations.h" |
47 #include "skia/ext/platform_canvas.h" | 47 #include "skia/ext/platform_canvas.h" |
48 | 48 |
49 namespace WebCore { | 49 namespace WebCore { |
50 | 50 |
51 namespace { | 51 namespace { |
52 | 52 |
53 // Used by computeResamplingMode to tell how bitmaps should be resampled. | 53 // Used by computeResamplingMode to tell how bitmaps should be resampled. |
54 enum ResamplingMode { | 54 enum ResamplingMode { |
55 // Nearest neighbor resampling. Used when we detect that the page is | 55 // Nearest neighbor resampling. Used when we detect that the page is |
56 // trying to make a pattern by stretching a small bitmap very large. | 56 // trying to make a pattern by stretching a small bitmap very large. |
(...skipping 153 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 gfx::Size(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, |
(...skipping 111 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 gfx::Size(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 { |
(...skipping 82 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 |