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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 // Save the global memory cache to restore it upon teardown. | 69 // Save the global memory cache to restore it upon teardown. |
70 global_memory_cache_ = ReplaceMemoryCacheForTesting(MemoryCache::Create()); | 70 global_memory_cache_ = ReplaceMemoryCacheForTesting(MemoryCache::Create()); |
71 | 71 |
72 // Save the state of experimental canvas features and color correct | 72 // Save the state of experimental canvas features and color correct |
73 // rendering flags to restore them on teardown. | 73 // rendering flags to restore them on teardown. |
74 experimental_canvas_features = | 74 experimental_canvas_features = |
75 RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled(); | 75 RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled(); |
76 color_correct_rendering = | 76 color_correct_rendering = |
77 RuntimeEnabledFeatures::colorCorrectRenderingEnabled(); | 77 RuntimeEnabledFeatures::colorCorrectRenderingEnabled(); |
78 color_correct_rendering_default_mode = | 78 color_canvas_extensions = |
79 RuntimeEnabledFeatures::colorCorrectRenderingDefaultModeEnabled(); | 79 RuntimeEnabledFeatures::colorCanvasExtensionsEnabled(); |
80 } | 80 } |
81 virtual void TearDown() { | 81 virtual void TearDown() { |
82 // Garbage collection is required prior to switching out the | 82 // Garbage collection is required prior to switching out the |
83 // test's memory cache; image resources are released, evicting | 83 // test's memory cache; image resources are released, evicting |
84 // them from the cache. | 84 // them from the cache. |
85 ThreadState::Current()->CollectGarbage(BlinkGC::kNoHeapPointersOnStack, | 85 ThreadState::Current()->CollectGarbage(BlinkGC::kNoHeapPointersOnStack, |
86 BlinkGC::kGCWithSweep, | 86 BlinkGC::kGCWithSweep, |
87 BlinkGC::kForcedGC); | 87 BlinkGC::kForcedGC); |
88 | 88 |
89 ReplaceMemoryCacheForTesting(global_memory_cache_.Release()); | 89 ReplaceMemoryCacheForTesting(global_memory_cache_.Release()); |
90 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled( | 90 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled( |
91 experimental_canvas_features); | 91 experimental_canvas_features); |
92 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled( | 92 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled( |
93 color_correct_rendering); | 93 color_correct_rendering); |
94 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled( | 94 RuntimeEnabledFeatures::setColorCanvasExtensionsEnabled( |
95 color_correct_rendering_default_mode); | 95 color_canvas_extensions); |
96 } | 96 } |
97 | 97 |
98 sk_sp<SkImage> image_, image2_; | 98 sk_sp<SkImage> image_, image2_; |
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_canvas_extensions; |
103 }; | 103 }; |
104 | 104 |
105 TEST_F(ImageBitmapTest, ImageResourceConsistency) { | 105 TEST_F(ImageBitmapTest, ImageResourceConsistency) { |
| 106 RuntimeEnabledFeatures::setColorCanvasExtensionsEnabled(true); |
106 const ImageBitmapOptions default_options; | 107 const ImageBitmapOptions default_options; |
107 HTMLImageElement* image_element = | 108 HTMLImageElement* image_element = |
108 HTMLImageElement::Create(*Document::Create()); | 109 HTMLImageElement::Create(*Document::Create()); |
109 ImageResourceContent* image = ImageResourceContent::CreateLoaded( | 110 ImageResourceContent* image = ImageResourceContent::CreateLoaded( |
110 StaticBitmapImage::Create(image_).Get()); | 111 StaticBitmapImage::Create(image_).Get()); |
111 image_element->SetImageForTest(image); | 112 image_element->SetImageForTest(image); |
112 | 113 |
113 Optional<IntRect> crop_rect = | 114 Optional<IntRect> crop_rect = |
114 IntRect(0, 0, image_->width(), image_->height()); | 115 IntRect(0, 0, image_->width(), image_->height()); |
115 ImageBitmap* image_bitmap_no_crop = | 116 ImageBitmap* image_bitmap_no_crop = |
(...skipping 24 matching lines...) Expand all Loading... |
140 | 141 |
141 RefPtr<StaticBitmapImage> empty_image = | 142 RefPtr<StaticBitmapImage> empty_image = |
142 image_bitmap_outside_crop->BitmapImage(); | 143 image_bitmap_outside_crop->BitmapImage(); |
143 ASSERT_NE(empty_image->ImageForCurrentFrame(), | 144 ASSERT_NE(empty_image->ImageForCurrentFrame(), |
144 image_element->CachedImage()->GetImage()->ImageForCurrentFrame()); | 145 image_element->CachedImage()->GetImage()->ImageForCurrentFrame()); |
145 } | 146 } |
146 | 147 |
147 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a | 148 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a |
148 // reference to the original Image if the HTMLImageElement src is changed. | 149 // reference to the original Image if the HTMLImageElement src is changed. |
149 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) { | 150 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) { |
| 151 RuntimeEnabledFeatures::setColorCanvasExtensionsEnabled(true); |
150 HTMLImageElement* image = HTMLImageElement::Create(*Document::Create()); | 152 HTMLImageElement* image = HTMLImageElement::Create(*Document::Create()); |
151 ImageResourceContent* original_image_resource = | 153 ImageResourceContent* original_image_resource = |
152 ImageResourceContent::CreateLoaded( | 154 ImageResourceContent::CreateLoaded( |
153 StaticBitmapImage::Create(image_).Get()); | 155 StaticBitmapImage::Create(image_).Get()); |
154 image->SetImageForTest(original_image_resource); | 156 image->SetImageForTest(original_image_resource); |
155 | 157 |
156 const ImageBitmapOptions default_options; | 158 const ImageBitmapOptions default_options; |
157 Optional<IntRect> crop_rect = | 159 Optional<IntRect> crop_rect = |
158 IntRect(0, 0, image_->width(), image_->height()); | 160 IntRect(0, 0, image_->width(), image_->height()); |
159 ImageBitmap* image_bitmap = ImageBitmap::Create( | 161 ImageBitmap* image_bitmap = ImageBitmap::Create( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 static const Vector<String> kConversions = { | 212 static const Vector<String> kConversions = { |
211 "none", "default", "default", "srgb", "linear-rgb", "p3", "rec2020"}; | 213 "none", "default", "default", "srgb", "linear-rgb", "p3", "rec2020"}; |
212 options.setColorSpaceConversion( | 214 options.setColorSpaceConversion( |
213 kConversions[static_cast<uint8_t>(color_space_conversion)]); | 215 kConversions[static_cast<uint8_t>(color_space_conversion)]); |
214 | 216 |
215 // Set the runtime flags | 217 // Set the runtime flags |
216 bool flag = (color_space_conversion != | 218 bool flag = (color_space_conversion != |
217 ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED); | 219 ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED); |
218 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled(true); | 220 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled(true); |
219 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(flag); | 221 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(flag); |
220 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled(!flag); | 222 RuntimeEnabledFeatures::setColorCanvasExtensionsEnabled(true); |
221 | 223 |
222 return options; | 224 return options; |
223 } | 225 } |
224 | 226 |
225 TEST_F(ImageBitmapTest, ImageBitmapColorSpaceConversionHTMLImageElement) { | 227 TEST_F(ImageBitmapTest, ImageBitmapColorSpaceConversionHTMLImageElement) { |
226 HTMLImageElement* image_element = | 228 HTMLImageElement* image_element = |
227 HTMLImageElement::Create(*Document::Create()); | 229 HTMLImageElement::Create(*Document::Create()); |
228 | 230 |
229 SkPaint p; | 231 SkPaint p; |
230 p.setColor(SK_ColorRED); | 232 p.setColor(SK_ColorRED); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 color_space_xform->apply(color_format, transformed_pixel.get(), | 610 color_space_xform->apply(color_format, transformed_pixel.get(), |
609 color_format32, src_pixel.get(), 1, | 611 color_format32, src_pixel.get(), 1, |
610 SkAlphaType::kUnpremul_SkAlphaType); | 612 SkAlphaType::kUnpremul_SkAlphaType); |
611 int compare = std::memcmp(converted_pixel.get(), transformed_pixel.get(), | 613 int compare = std::memcmp(converted_pixel.get(), transformed_pixel.get(), |
612 image_info.bytesPerPixel()); | 614 image_info.bytesPerPixel()); |
613 ASSERT_EQ(compare, 0); | 615 ASSERT_EQ(compare, 0); |
614 } | 616 } |
615 } | 617 } |
616 | 618 |
617 } // namespace blink | 619 } // namespace blink |
OLD | NEW |