OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 Persistent<MemoryCache> global_memory_cache_; | 99 Persistent<MemoryCache> global_memory_cache_; |
100 bool experimental_canvas_features; | 100 bool experimental_canvas_features; |
101 bool color_correct_rendering; | 101 bool color_correct_rendering; |
102 bool color_correct_rendering_default_mode; | 102 bool color_correct_rendering_default_mode; |
103 }; | 103 }; |
104 | 104 |
105 TEST_F(ImageBitmapTest, ImageResourceConsistency) { | 105 TEST_F(ImageBitmapTest, ImageResourceConsistency) { |
106 const ImageBitmapOptions default_options; | 106 const ImageBitmapOptions default_options; |
107 HTMLImageElement* image_element = | 107 HTMLImageElement* image_element = |
108 HTMLImageElement::Create(*Document::Create()); | 108 HTMLImageElement::Create(*Document::Create()); |
109 ImageResourceContent* image = | 109 ImageResourceContent* image = ImageResourceContent::CreateLoaded( |
110 ImageResourceContent::Create(StaticBitmapImage::Create(image_).Get()); | 110 StaticBitmapImage::Create(image_).Get()); |
111 image_element->SetImageResource(image); | 111 image_element->SetImageResource(image); |
112 | 112 |
113 Optional<IntRect> crop_rect = | 113 Optional<IntRect> crop_rect = |
114 IntRect(0, 0, image_->width(), image_->height()); | 114 IntRect(0, 0, image_->width(), image_->height()); |
115 ImageBitmap* image_bitmap_no_crop = | 115 ImageBitmap* image_bitmap_no_crop = |
116 ImageBitmap::Create(image_element, crop_rect, | 116 ImageBitmap::Create(image_element, crop_rect, |
117 &(image_element->GetDocument()), default_options); | 117 &(image_element->GetDocument()), default_options); |
118 crop_rect = IntRect(image_->width() / 2, image_->height() / 2, | 118 crop_rect = IntRect(image_->width() / 2, image_->height() / 2, |
119 image_->width() / 2, image_->height() / 2); | 119 image_->width() / 2, image_->height() / 2); |
120 ImageBitmap* image_bitmap_interior_crop = | 120 ImageBitmap* image_bitmap_interior_crop = |
(...skipping 21 matching lines...) Expand all Loading... |
142 image_bitmap_outside_crop->BitmapImage(); | 142 image_bitmap_outside_crop->BitmapImage(); |
143 ASSERT_NE(empty_image->ImageForCurrentFrame(), | 143 ASSERT_NE(empty_image->ImageForCurrentFrame(), |
144 image_element->CachedImage()->GetImage()->ImageForCurrentFrame()); | 144 image_element->CachedImage()->GetImage()->ImageForCurrentFrame()); |
145 } | 145 } |
146 | 146 |
147 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a | 147 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a |
148 // reference to the original Image if the HTMLImageElement src is changed. | 148 // reference to the original Image if the HTMLImageElement src is changed. |
149 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) { | 149 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) { |
150 HTMLImageElement* image = HTMLImageElement::Create(*Document::Create()); | 150 HTMLImageElement* image = HTMLImageElement::Create(*Document::Create()); |
151 ImageResourceContent* original_image_resource = | 151 ImageResourceContent* original_image_resource = |
152 ImageResourceContent::Create(StaticBitmapImage::Create(image_).Get()); | 152 ImageResourceContent::CreateLoaded( |
| 153 StaticBitmapImage::Create(image_).Get()); |
153 image->SetImageResource(original_image_resource); | 154 image->SetImageResource(original_image_resource); |
154 | 155 |
155 const ImageBitmapOptions default_options; | 156 const ImageBitmapOptions default_options; |
156 Optional<IntRect> crop_rect = | 157 Optional<IntRect> crop_rect = |
157 IntRect(0, 0, image_->width(), image_->height()); | 158 IntRect(0, 0, image_->width(), image_->height()); |
158 ImageBitmap* image_bitmap = ImageBitmap::Create( | 159 ImageBitmap* image_bitmap = ImageBitmap::Create( |
159 image, crop_rect, &(image->GetDocument()), default_options); | 160 image, crop_rect, &(image->GetDocument()), default_options); |
160 // As we are applying color space conversion for the "default" mode, | 161 // As we are applying color space conversion for the "default" mode, |
161 // this verifies that the color corrected image is not the same as the | 162 // this verifies that the color corrected image is not the same as the |
162 // source. | 163 // source. |
163 ASSERT_NE(image_bitmap->BitmapImage()->ImageForCurrentFrame(), | 164 ASSERT_NE(image_bitmap->BitmapImage()->ImageForCurrentFrame(), |
164 original_image_resource->GetImage()->ImageForCurrentFrame()); | 165 original_image_resource->GetImage()->ImageForCurrentFrame()); |
165 | 166 |
166 ImageResourceContent* new_image_resource = | 167 ImageResourceContent* new_image_resource = ImageResourceContent::CreateLoaded( |
167 ImageResourceContent::Create(StaticBitmapImage::Create(image2_).Get()); | 168 StaticBitmapImage::Create(image2_).Get()); |
168 image->SetImageResource(new_image_resource); | 169 image->SetImageResource(new_image_resource); |
169 | 170 |
170 { | 171 { |
171 ASSERT_NE(image_bitmap->BitmapImage()->ImageForCurrentFrame(), | 172 ASSERT_NE(image_bitmap->BitmapImage()->ImageForCurrentFrame(), |
172 original_image_resource->GetImage()->ImageForCurrentFrame()); | 173 original_image_resource->GetImage()->ImageForCurrentFrame()); |
173 SkImage* image1 = image_bitmap->BitmapImage()->ImageForCurrentFrame().get(); | 174 SkImage* image1 = image_bitmap->BitmapImage()->ImageForCurrentFrame().get(); |
174 ASSERT_NE(image1, nullptr); | 175 ASSERT_NE(image1, nullptr); |
175 SkImage* image2 = | 176 SkImage* image2 = |
176 original_image_resource->GetImage()->ImageForCurrentFrame().get(); | 177 original_image_resource->GetImage()->ImageForCurrentFrame().get(); |
177 ASSERT_NE(image2, nullptr); | 178 ASSERT_NE(image2, nullptr); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 sk_sp<SkSurface> surface(SkSurface::MakeRaster(raster_image_info)); | 235 sk_sp<SkSurface> surface(SkSurface::MakeRaster(raster_image_info)); |
235 surface->getCanvas()->drawCircle(5, 5, 5, p); | 236 surface->getCanvas()->drawCircle(5, 5, 5, p); |
236 sk_sp<SkImage> image = surface->makeImageSnapshot(); | 237 sk_sp<SkImage> image = surface->makeImageSnapshot(); |
237 | 238 |
238 std::unique_ptr<uint8_t[]> src_pixel( | 239 std::unique_ptr<uint8_t[]> src_pixel( |
239 new uint8_t[raster_image_info.bytesPerPixel()]()); | 240 new uint8_t[raster_image_info.bytesPerPixel()]()); |
240 image->readPixels(raster_image_info.makeWH(1, 1), src_pixel.get(), | 241 image->readPixels(raster_image_info.makeWH(1, 1), src_pixel.get(), |
241 image->width() * raster_image_info.bytesPerPixel(), 5, 5); | 242 image->width() * raster_image_info.bytesPerPixel(), 5, 5); |
242 | 243 |
243 ImageResourceContent* original_image_resource = | 244 ImageResourceContent* original_image_resource = |
244 ImageResourceContent::Create(StaticBitmapImage::Create(image).Get()); | 245 ImageResourceContent::CreateLoaded( |
| 246 StaticBitmapImage::Create(image).Get()); |
245 image_element->SetImageResource(original_image_resource); | 247 image_element->SetImageResource(original_image_resource); |
246 | 248 |
247 Optional<IntRect> crop_rect = IntRect(0, 0, image->width(), image->height()); | 249 Optional<IntRect> crop_rect = IntRect(0, 0, image->width(), image->height()); |
248 | 250 |
249 // Create and test the ImageBitmap objects. | 251 // Create and test the ImageBitmap objects. |
250 // We don't check "none" color space conversion as it requires the encoded | 252 // We don't check "none" color space conversion as it requires the encoded |
251 // data in a format readable by ImageDecoder. Furthermore, the code path for | 253 // data in a format readable by ImageDecoder. Furthermore, the code path for |
252 // "none" color space conversion is not affected by this CL. | 254 // "none" color space conversion is not affected by this CL. |
253 | 255 |
254 sk_sp<SkColorSpace> color_space = nullptr; | 256 sk_sp<SkColorSpace> color_space = nullptr; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 sk_sp<SkSurface> surface(SkSurface::MakeRaster(raster_image_info)); | 347 sk_sp<SkSurface> surface(SkSurface::MakeRaster(raster_image_info)); |
346 surface->getCanvas()->drawCircle(5, 5, 5, p); | 348 surface->getCanvas()->drawCircle(5, 5, 5, p); |
347 sk_sp<SkImage> image = surface->makeImageSnapshot(); | 349 sk_sp<SkImage> image = surface->makeImageSnapshot(); |
348 | 350 |
349 std::unique_ptr<uint8_t[]> src_pixel( | 351 std::unique_ptr<uint8_t[]> src_pixel( |
350 new uint8_t[raster_image_info.bytesPerPixel()]()); | 352 new uint8_t[raster_image_info.bytesPerPixel()]()); |
351 image->readPixels(raster_image_info.makeWH(1, 1), src_pixel.get(), | 353 image->readPixels(raster_image_info.makeWH(1, 1), src_pixel.get(), |
352 image->width() * raster_image_info.bytesPerPixel(), 5, 5); | 354 image->width() * raster_image_info.bytesPerPixel(), 5, 5); |
353 | 355 |
354 ImageResourceContent* source_image_resource = | 356 ImageResourceContent* source_image_resource = |
355 ImageResourceContent::Create(StaticBitmapImage::Create(image).Get()); | 357 ImageResourceContent::CreateLoaded( |
| 358 StaticBitmapImage::Create(image).Get()); |
356 image_element->SetImageResource(source_image_resource); | 359 image_element->SetImageResource(source_image_resource); |
357 | 360 |
358 Optional<IntRect> crop_rect = IntRect(0, 0, image->width(), image->height()); | 361 Optional<IntRect> crop_rect = IntRect(0, 0, image->width(), image->height()); |
359 ImageBitmapOptions options = | 362 ImageBitmapOptions options = |
360 PrepareBitmapOptionsAndSetRuntimeFlags(ColorSpaceConversion::SRGB); | 363 PrepareBitmapOptionsAndSetRuntimeFlags(ColorSpaceConversion::SRGB); |
361 ImageBitmap* source_image_bitmap = ImageBitmap::Create( | 364 ImageBitmap* source_image_bitmap = ImageBitmap::Create( |
362 image_element, crop_rect, &(image_element->GetDocument()), options); | 365 image_element, crop_rect, &(image_element->GetDocument()), options); |
363 | 366 |
364 sk_sp<SkColorSpace> color_space = nullptr; | 367 sk_sp<SkColorSpace> color_space = nullptr; |
365 SkColorType color_type = SkColorType::kN32_SkColorType; | 368 SkColorType color_type = SkColorType::kN32_SkColorType; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 color_space_xform->apply(color_format, transformed_pixel.get(), | 608 color_space_xform->apply(color_format, transformed_pixel.get(), |
606 color_format32, src_pixel.get(), 1, | 609 color_format32, src_pixel.get(), 1, |
607 SkAlphaType::kUnpremul_SkAlphaType); | 610 SkAlphaType::kUnpremul_SkAlphaType); |
608 int compare = std::memcmp(converted_pixel.get(), transformed_pixel.get(), | 611 int compare = std::memcmp(converted_pixel.get(), transformed_pixel.get(), |
609 image_info.bytesPerPixel()); | 612 image_info.bytesPerPixel()); |
610 ASSERT_EQ(compare, 0); | 613 ASSERT_EQ(compare, 0); |
611 } | 614 } |
612 } | 615 } |
613 | 616 |
614 } // namespace blink | 617 } // namespace blink |
OLD | NEW |