Chromium Code Reviews| 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), image_observer_(observer) {} | 55 : image_observer_disabled_(false), |
| 56 image_observer_(observer), | |
| 57 stable_image_id_(PaintImage::GetNextId()) {} | |
|
chrishtr
2017/05/10 22:56:11
How about making Image the class which creates its
vmpstr
2017/05/10 23:21:47
Hm.. You mean have the id generation happen from I
| |
| 56 | 58 |
| 57 Image::~Image() {} | 59 Image::~Image() {} |
| 58 | 60 |
| 59 Image* Image::NullImage() { | 61 Image* Image::NullImage() { |
| 60 DCHECK(IsMainThread()); | 62 DCHECK(IsMainThread()); |
| 61 DEFINE_STATIC_REF(Image, null_image, (BitmapImage::Create())); | 63 DEFINE_STATIC_REF(Image, null_image, (BitmapImage::Create())); |
| 62 return null_image; | 64 return null_image; |
| 63 } | 65 } |
| 64 | 66 |
| 65 PassRefPtr<Image> Image::LoadPlatformResource(const char* name) { | 67 PassRefPtr<Image> Image::LoadPlatformResource(const char* name) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 SkFloatToScalar(adjusted_y)); | 292 SkFloatToScalar(adjusted_y)); |
| 291 | 293 |
| 292 // Because no resizing occurred, the shader transform should be | 294 // Because no resizing occurred, the shader transform should be |
| 293 // set to the pattern's transform, which just includes scale. | 295 // set to the pattern's transform, which just includes scale. |
| 294 local_matrix.preScale(scale.Width(), scale.Height()); | 296 local_matrix.preScale(scale.Width(), scale.Height()); |
| 295 | 297 |
| 296 // Fetch this now as subsetting may swap the image. | 298 // Fetch this now as subsetting may swap the image. |
| 297 auto image_id = image.sk_image()->uniqueID(); | 299 auto image_id = image.sk_image()->uniqueID(); |
| 298 | 300 |
| 299 image = | 301 image = |
| 300 PaintImage(image.sk_image()->makeSubset(EnclosingIntRect(norm_src_rect)), | 302 PaintImage(stable_image_id_, |
| 303 image.sk_image()->makeSubset(EnclosingIntRect(norm_src_rect)), | |
| 301 image.animation_type(), image.completion_state()); | 304 image.animation_type(), image.completion_state()); |
| 302 if (!image) | 305 if (!image) |
| 303 return; | 306 return; |
| 304 | 307 |
| 305 const FloatSize tile_size( | 308 const FloatSize tile_size( |
| 306 image.sk_image()->width() * scale.Width() + repeat_spacing.Width(), | 309 image.sk_image()->width() * scale.Width() + repeat_spacing.Width(), |
| 307 image.sk_image()->height() * scale.Height() + repeat_spacing.Height()); | 310 image.sk_image()->height() * scale.Height() + repeat_spacing.Height()); |
| 308 const auto tmx = ComputeTileMode(dest_rect.X(), dest_rect.MaxX(), adjusted_x, | 311 const auto tmx = ComputeTileMode(dest_rect.X(), dest_rect.MaxX(), adjusted_x, |
| 309 adjusted_x + tile_size.Width()); | 312 adjusted_x + tile_size.Width()); |
| 310 const auto tmy = ComputeTileMode(dest_rect.Y(), dest_rect.MaxY(), adjusted_y, | 313 const auto tmy = ComputeTileMode(dest_rect.Y(), dest_rect.MaxY(), adjusted_y, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 338 | 341 |
| 339 return image.Release(); | 342 return image.Release(); |
| 340 } | 343 } |
| 341 | 344 |
| 342 PaintImage Image::PaintImageForCurrentFrame() { | 345 PaintImage Image::PaintImageForCurrentFrame() { |
| 343 auto animation_type = MaybeAnimated() ? PaintImage::AnimationType::ANIMATED | 346 auto animation_type = MaybeAnimated() ? PaintImage::AnimationType::ANIMATED |
| 344 : PaintImage::AnimationType::STATIC; | 347 : PaintImage::AnimationType::STATIC; |
| 345 auto completion_state = CurrentFrameIsComplete() | 348 auto completion_state = CurrentFrameIsComplete() |
| 346 ? PaintImage::CompletionState::DONE | 349 ? PaintImage::CompletionState::DONE |
| 347 : PaintImage::CompletionState::PARTIALLY_DONE; | 350 : PaintImage::CompletionState::PARTIALLY_DONE; |
| 348 return PaintImage(ImageForCurrentFrame(), animation_type, completion_state); | 351 return PaintImage(stable_image_id_, ImageForCurrentFrame(), animation_type, |
| 352 completion_state); | |
| 349 } | 353 } |
| 350 | 354 |
| 351 bool Image::ApplyShader(PaintFlags& flags, const SkMatrix& local_matrix) { | 355 bool Image::ApplyShader(PaintFlags& flags, const SkMatrix& local_matrix) { |
| 352 // Default shader impl: attempt to build a shader based on the current frame | 356 // Default shader impl: attempt to build a shader based on the current frame |
| 353 // SkImage. | 357 // SkImage. |
| 354 sk_sp<SkImage> image = ImageForCurrentFrame(); | 358 sk_sp<SkImage> image = ImageForCurrentFrame(); |
| 355 if (!image) | 359 if (!image) |
| 356 return false; | 360 return false; |
| 357 | 361 |
| 358 flags.setShader(image->makeShader(SkShader::kRepeat_TileMode, | 362 flags.setShader(image->makeShader(SkShader::kRepeat_TileMode, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 FloatRect subset = dest; | 398 FloatRect subset = dest; |
| 395 subset.SetX((dest.X() - tile.X()) / scale.Width()); | 399 subset.SetX((dest.X() - tile.X()) / scale.Width()); |
| 396 subset.SetY((dest.Y() - tile.Y()) / scale.Height()); | 400 subset.SetY((dest.Y() - tile.Y()) / scale.Height()); |
| 397 subset.SetWidth(dest.Width() / scale.Width()); | 401 subset.SetWidth(dest.Width() / scale.Width()); |
| 398 subset.SetHeight(dest.Height() / scale.Height()); | 402 subset.SetHeight(dest.Height() / scale.Height()); |
| 399 | 403 |
| 400 return subset; | 404 return subset; |
| 401 } | 405 } |
| 402 | 406 |
| 403 } // namespace blink | 407 } // namespace blink |
| OLD | NEW |