| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "public/platform/Platform.h" | 45 #include "public/platform/Platform.h" |
| 46 #include "public/platform/WebData.h" | 46 #include "public/platform/WebData.h" |
| 47 #include "third_party/skia/include/core/SkImage.h" | 47 #include "third_party/skia/include/core/SkImage.h" |
| 48 | 48 |
| 49 #include <math.h> | 49 #include <math.h> |
| 50 #include <tuple> | 50 #include <tuple> |
| 51 | 51 |
| 52 namespace blink { | 52 namespace blink { |
| 53 | 53 |
| 54 Image::Image(ImageObserver* observer) | 54 Image::Image(ImageObserver* observer) |
| 55 : image_observer_disabled_(false), | 55 : image_observer_disabled_(false), image_observer_(observer) {} |
| 56 image_observer_(observer), | |
| 57 stable_image_id_(PaintImage::GetNextId()) {} | |
| 58 | 56 |
| 59 Image::~Image() {} | 57 Image::~Image() {} |
| 60 | 58 |
| 61 Image* Image::NullImage() { | 59 Image* Image::NullImage() { |
| 62 DCHECK(IsMainThread()); | 60 DCHECK(IsMainThread()); |
| 63 DEFINE_STATIC_REF(Image, null_image, (BitmapImage::Create())); | 61 DEFINE_STATIC_REF(Image, null_image, (BitmapImage::Create())); |
| 64 return null_image; | 62 return null_image; |
| 65 } | 63 } |
| 66 | 64 |
| 67 PassRefPtr<Image> Image::LoadPlatformResource(const char* name) { | 65 PassRefPtr<Image> Image::LoadPlatformResource(const char* name) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 SkFloatToScalar(adjusted_y)); | 290 SkFloatToScalar(adjusted_y)); |
| 293 | 291 |
| 294 // Because no resizing occurred, the shader transform should be | 292 // Because no resizing occurred, the shader transform should be |
| 295 // set to the pattern's transform, which just includes scale. | 293 // set to the pattern's transform, which just includes scale. |
| 296 local_matrix.preScale(scale.Width(), scale.Height()); | 294 local_matrix.preScale(scale.Width(), scale.Height()); |
| 297 | 295 |
| 298 // Fetch this now as subsetting may swap the image. | 296 // Fetch this now as subsetting may swap the image. |
| 299 auto image_id = image.sk_image()->uniqueID(); | 297 auto image_id = image.sk_image()->uniqueID(); |
| 300 | 298 |
| 301 image = | 299 image = |
| 302 PaintImage(stable_image_id_, | 300 PaintImage(image.sk_image()->makeSubset(EnclosingIntRect(norm_src_rect)), |
| 303 image.sk_image()->makeSubset(EnclosingIntRect(norm_src_rect)), | |
| 304 image.animation_type(), image.completion_state()); | 301 image.animation_type(), image.completion_state()); |
| 305 if (!image) | 302 if (!image) |
| 306 return; | 303 return; |
| 307 | 304 |
| 308 const FloatSize tile_size( | 305 const FloatSize tile_size( |
| 309 image.sk_image()->width() * scale.Width() + repeat_spacing.Width(), | 306 image.sk_image()->width() * scale.Width() + repeat_spacing.Width(), |
| 310 image.sk_image()->height() * scale.Height() + repeat_spacing.Height()); | 307 image.sk_image()->height() * scale.Height() + repeat_spacing.Height()); |
| 311 const auto tmx = ComputeTileMode(dest_rect.X(), dest_rect.MaxX(), adjusted_x, | 308 const auto tmx = ComputeTileMode(dest_rect.X(), dest_rect.MaxX(), adjusted_x, |
| 312 adjusted_x + tile_size.Width()); | 309 adjusted_x + tile_size.Width()); |
| 313 const auto tmy = ComputeTileMode(dest_rect.Y(), dest_rect.MaxY(), adjusted_y, | 310 const auto tmy = ComputeTileMode(dest_rect.Y(), dest_rect.MaxY(), adjusted_y, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 341 | 338 |
| 342 return image.Release(); | 339 return image.Release(); |
| 343 } | 340 } |
| 344 | 341 |
| 345 PaintImage Image::PaintImageForCurrentFrame() { | 342 PaintImage Image::PaintImageForCurrentFrame() { |
| 346 auto animation_type = MaybeAnimated() ? PaintImage::AnimationType::ANIMATED | 343 auto animation_type = MaybeAnimated() ? PaintImage::AnimationType::ANIMATED |
| 347 : PaintImage::AnimationType::STATIC; | 344 : PaintImage::AnimationType::STATIC; |
| 348 auto completion_state = CurrentFrameIsComplete() | 345 auto completion_state = CurrentFrameIsComplete() |
| 349 ? PaintImage::CompletionState::DONE | 346 ? PaintImage::CompletionState::DONE |
| 350 : PaintImage::CompletionState::PARTIALLY_DONE; | 347 : PaintImage::CompletionState::PARTIALLY_DONE; |
| 351 return PaintImage(stable_image_id_, ImageForCurrentFrame(), animation_type, | 348 return PaintImage(ImageForCurrentFrame(), animation_type, completion_state); |
| 352 completion_state); | |
| 353 } | 349 } |
| 354 | 350 |
| 355 bool Image::ApplyShader(PaintFlags& flags, const SkMatrix& local_matrix) { | 351 bool Image::ApplyShader(PaintFlags& flags, const SkMatrix& local_matrix) { |
| 356 // Default shader impl: attempt to build a shader based on the current frame | 352 // Default shader impl: attempt to build a shader based on the current frame |
| 357 // SkImage. | 353 // SkImage. |
| 358 sk_sp<SkImage> image = ImageForCurrentFrame(); | 354 sk_sp<SkImage> image = ImageForCurrentFrame(); |
| 359 if (!image) | 355 if (!image) |
| 360 return false; | 356 return false; |
| 361 | 357 |
| 362 flags.setShader(image->makeShader(SkShader::kRepeat_TileMode, | 358 flags.setShader(image->makeShader(SkShader::kRepeat_TileMode, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 FloatRect subset = dest; | 394 FloatRect subset = dest; |
| 399 subset.SetX((dest.X() - tile.X()) / scale.Width()); | 395 subset.SetX((dest.X() - tile.X()) / scale.Width()); |
| 400 subset.SetY((dest.Y() - tile.Y()) / scale.Height()); | 396 subset.SetY((dest.Y() - tile.Y()) / scale.Height()); |
| 401 subset.SetWidth(dest.Width() / scale.Width()); | 397 subset.SetWidth(dest.Width() / scale.Width()); |
| 402 subset.SetHeight(dest.Height() / scale.Height()); | 398 subset.SetHeight(dest.Height() / scale.Height()); |
| 403 | 399 |
| 404 return subset; | 400 return subset; |
| 405 } | 401 } |
| 406 | 402 |
| 407 } // namespace blink | 403 } // namespace blink |
| OLD | NEW |