Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp

Issue 2559013002: Add ColorBehavior to blink::Image draw methods (Closed)
Patch Set: Rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 imageElement, cropRect, &(imageElement->document()), defaultOptions); 95 imageElement, cropRect, &(imageElement->document()), defaultOptions);
96 cropRect = IntRect(-m_image->width() / 2, -m_image->height() / 2, 96 cropRect = IntRect(-m_image->width() / 2, -m_image->height() / 2,
97 m_image->width(), m_image->height()); 97 m_image->width(), m_image->height());
98 ImageBitmap* imageBitmapExteriorCrop = ImageBitmap::create( 98 ImageBitmap* imageBitmapExteriorCrop = ImageBitmap::create(
99 imageElement, cropRect, &(imageElement->document()), defaultOptions); 99 imageElement, cropRect, &(imageElement->document()), defaultOptions);
100 cropRect = IntRect(-m_image->width(), -m_image->height(), m_image->width(), 100 cropRect = IntRect(-m_image->width(), -m_image->height(), m_image->width(),
101 m_image->height()); 101 m_image->height());
102 ImageBitmap* imageBitmapOutsideCrop = ImageBitmap::create( 102 ImageBitmap* imageBitmapOutsideCrop = ImageBitmap::create(
103 imageElement, cropRect, &(imageElement->document()), defaultOptions); 103 imageElement, cropRect, &(imageElement->document()), defaultOptions);
104 104
105 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), 105 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(
106 imageElement->cachedImage()->getImage()->imageForCurrentFrame()); 106 ColorBehavior::transformToTargetForTesting()),
107 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), 107 imageElement->cachedImage()->getImage()->imageForCurrentFrame(
108 imageElement->cachedImage()->getImage()->imageForCurrentFrame()); 108 ColorBehavior::transformToTargetForTesting()));
109 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), 109 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(
110 imageElement->cachedImage()->getImage()->imageForCurrentFrame()); 110 ColorBehavior::transformToTargetForTesting()),
111 imageElement->cachedImage()->getImage()->imageForCurrentFrame(
112 ColorBehavior::transformToTargetForTesting()));
113 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(
114 ColorBehavior::transformToTargetForTesting()),
115 imageElement->cachedImage()->getImage()->imageForCurrentFrame(
116 ColorBehavior::transformToTargetForTesting()));
111 117
112 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); 118 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage();
113 ASSERT_NE(emptyImage->imageForCurrentFrame(), 119 ASSERT_NE(emptyImage->imageForCurrentFrame(
114 imageElement->cachedImage()->getImage()->imageForCurrentFrame()); 120 ColorBehavior::transformToTargetForTesting()),
121 imageElement->cachedImage()->getImage()->imageForCurrentFrame(
122 ColorBehavior::transformToTargetForTesting()));
115 } 123 }
116 124
117 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a 125 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a
118 // reference to the original Image if the HTMLImageElement src is changed. 126 // reference to the original Image if the HTMLImageElement src is changed.
119 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) { 127 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) {
120 HTMLImageElement* image = HTMLImageElement::create(*Document::create()); 128 HTMLImageElement* image = HTMLImageElement::create(*Document::create());
121 ImageResource* originalImageResource = 129 ImageResource* originalImageResource =
122 ImageResource::create(StaticBitmapImage::create(m_image).get()); 130 ImageResource::create(StaticBitmapImage::create(m_image).get());
123 image->setImageResource(originalImageResource); 131 image->setImageResource(originalImageResource);
124 132
125 const ImageBitmapOptions defaultOptions; 133 const ImageBitmapOptions defaultOptions;
126 Optional<IntRect> cropRect = 134 Optional<IntRect> cropRect =
127 IntRect(0, 0, m_image->width(), m_image->height()); 135 IntRect(0, 0, m_image->width(), m_image->height());
128 ImageBitmap* imageBitmap = ImageBitmap::create( 136 ImageBitmap* imageBitmap = ImageBitmap::create(
129 image, cropRect, &(image->document()), defaultOptions); 137 image, cropRect, &(image->document()), defaultOptions);
130 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), 138 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(
131 originalImageResource->getImage()->imageForCurrentFrame()); 139 ColorBehavior::transformToTargetForTesting()),
140 originalImageResource->getImage()->imageForCurrentFrame(
141 ColorBehavior::transformToTargetForTesting()));
132 142
133 ImageResource* newImageResource = 143 ImageResource* newImageResource =
134 ImageResource::create(StaticBitmapImage::create(m_image2).get()); 144 ImageResource::create(StaticBitmapImage::create(m_image2).get());
135 image->setImageResource(newImageResource); 145 image->setImageResource(newImageResource);
136 146
137 // The ImageBitmap should contain the same data as the original cached image 147 // The ImageBitmap should contain the same data as the original cached image
138 { 148 {
139 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), 149 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(
140 originalImageResource->getImage()->imageForCurrentFrame()); 150 ColorBehavior::transformToTargetForTesting()),
141 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get(); 151 originalImageResource->getImage()->imageForCurrentFrame(
152 ColorBehavior::transformToTargetForTesting()));
153 SkImage* image1 =
154 imageBitmap->bitmapImage()
155 ->imageForCurrentFrame(ColorBehavior::transformToTargetForTesting())
156 .get();
142 ASSERT_NE(image1, nullptr); 157 ASSERT_NE(image1, nullptr);
143 SkImage* image2 = 158 SkImage* image2 =
144 originalImageResource->getImage()->imageForCurrentFrame().get(); 159 originalImageResource->getImage()
160 ->imageForCurrentFrame(ColorBehavior::transformToTargetForTesting())
161 .get();
145 ASSERT_NE(image2, nullptr); 162 ASSERT_NE(image2, nullptr);
146 ASSERT_EQ(image1, image2); 163 ASSERT_EQ(image1, image2);
147 } 164 }
148 165
149 { 166 {
150 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), 167 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(
151 newImageResource->getImage()->imageForCurrentFrame()); 168 ColorBehavior::transformToTargetForTesting()),
152 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get(); 169 newImageResource->getImage()->imageForCurrentFrame(
170 ColorBehavior::transformToTargetForTesting()));
171 SkImage* image1 =
172 imageBitmap->bitmapImage()
173 ->imageForCurrentFrame(ColorBehavior::transformToTargetForTesting())
174 .get();
153 ASSERT_NE(image1, nullptr); 175 ASSERT_NE(image1, nullptr);
154 SkImage* image2 = 176 SkImage* image2 =
155 newImageResource->getImage()->imageForCurrentFrame().get(); 177 newImageResource->getImage()
178 ->imageForCurrentFrame(ColorBehavior::transformToTargetForTesting())
179 .get();
156 ASSERT_NE(image2, nullptr); 180 ASSERT_NE(image2, nullptr);
157 ASSERT_NE(image1, image2); 181 ASSERT_NE(image1, image2);
158 } 182 }
159 } 183 }
160 184
161 } // namespace blink 185 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/ImageBitmap.cpp ('k') | third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698