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

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

Issue 2035113002: Implement ImageBitmapOptions resize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 months 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/frame/ImageBitmap.h" 5 #include "core/frame/ImageBitmap.h"
6 6
7 #include "core/html/HTMLCanvasElement.h" 7 #include "core/html/HTMLCanvasElement.h"
8 #include "core/html/HTMLVideoElement.h" 8 #include "core/html/HTMLVideoElement.h"
9 #include "core/html/ImageData.h" 9 #include "core/html/ImageData.h"
10 #include "platform/graphics/skia/SkiaUtils.h" 10 #include "platform/graphics/skia/SkiaUtils.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 SkBitmap bitmap = frame->bitmap(); 110 SkBitmap bitmap = frame->bitmap();
111 if (!frameIsValid(bitmap)) 111 if (!frameIsValid(bitmap))
112 return nullptr; 112 return nullptr;
113 return fromSkSp(SkImage::MakeFromBitmap(bitmap)); 113 return fromSkSp(SkImage::MakeFromBitmap(bitmap));
114 } 114 }
115 115
116 // The parameter imageFormat indicates whether the first parameter "image" is un premultiplied or not. 116 // The parameter imageFormat indicates whether the first parameter "image" is un premultiplied or not.
117 // imageFormat = PremultiplyAlpha means the image is in premuliplied format 117 // imageFormat = PremultiplyAlpha means the image is in premuliplied format
118 // For example, if the image is already in unpremultiplied format and we want th e created ImageBitmap 118 // For example, if the image is already in unpremultiplied format and we want th e created ImageBitmap
119 // in the same format, then we don't need to use the ImageDecoder to decode the image. 119 // in the same format, then we don't need to use the ImageDecoder to decode the image.
120 static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop Rect, bool flipY, bool premultiplyAlpha, AlphaDisposition imageFormat = Premulti plyAlpha, ImageDecoder::GammaAndColorProfileOption colorSpaceOp = ImageDecoder:: GammaAndColorProfileApplied) 120 static PassRefPtr<StaticBitmapImage> cropImage(Image* image, IntRect& cropRect, bool flipY, bool premultiplyAlpha, AlphaDisposition imageFormat = PremultiplyAlp ha, ImageDecoder::GammaAndColorProfileOption colorSpaceOp = ImageDecoder::GammaA ndColorProfileApplied)
121 { 121 {
122 ASSERT(image); 122 ASSERT(image);
123 123
124 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height())); 124 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height()));
125 const IntRect srcRect = intersection(imgRect, cropRect); 125 const IntRect srcRect = intersection(imgRect, cropRect);
126 126
127 // In the case when cropRect doesn't intersect the source image and it requi res a umpremul image 127 // In the case when cropRect doesn't intersect the source image and it requi res a umpremul image
128 // We immediately return a transparent black image with cropRect.size() 128 // We immediately return a transparent black image with cropRect.size()
129 if (srcRect.isEmpty() && !premultiplyAlpha) { 129 if (srcRect.isEmpty() && !premultiplyAlpha) {
130 SkImageInfo info = SkImageInfo::Make(cropRect.width(), cropRect.height() , kN32_SkColorType, kUnpremul_SkAlphaType); 130 SkImageInfo info = SkImageInfo::Make(cropRect.width(), cropRect.height() , kN32_SkColorType, kUnpremul_SkAlphaType);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 skiaImage = flipSkImageVertically(skiaImage.get(), PremultiplyAlpha); 176 skiaImage = flipSkImageVertically(skiaImage.get(), PremultiplyAlpha);
177 177
178 if (premultiplyAlpha) { 178 if (premultiplyAlpha) {
179 if (imageFormat == PremultiplyAlpha) 179 if (imageFormat == PremultiplyAlpha)
180 return StaticBitmapImage::create(unPremulSkImageToPremul(skiaImage.g et())); 180 return StaticBitmapImage::create(unPremulSkImageToPremul(skiaImage.g et()));
181 return StaticBitmapImage::create(skiaImage.release()); 181 return StaticBitmapImage::create(skiaImage.release());
182 } 182 }
183 return StaticBitmapImage::create(premulSkImageToUnPremul(skiaImage.get())); 183 return StaticBitmapImage::create(premulSkImageToUnPremul(skiaImage.get()));
184 } 184 }
185 185
186 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect, Docum ent* document, const ImageBitmapOptions& options) 186 static PassRefPtr<Image> scaleInput(Image* input, unsigned resizeWidth, unsigned resizeHeight, SkFilterQuality resizeQuality)
187 {
188 RefPtr<SkImage> skiaImage = input->imageForCurrentFrame();
189 SkImageInfo scaledInfo = SkImageInfo::MakeN32Premul(resizeWidth, resizeHeigh t);
190 std::unique_ptr<uint8_t[]> scaledPixels = wrapArrayUnique(new uint8_t[resize Width * resizeHeight * scaledInfo.bytesPerPixel()]);
191 SkPixmap scaledPixmap(scaledInfo, scaledPixels.release(), scaledInfo.minRowB ytes());
192 if (!skiaImage->scalePixels(scaledPixmap, resizeQuality))
193 return nullptr;
194 RefPtr<SkImage> scaledImage = fromSkSp(SkImage::MakeFromRaster(scaledPixmap, [](const void* pixels, void*)
jbroman 2016/06/29 21:14:41 Doing a special pixmap allocation here seems sligh
xidachen 2016/06/30 15:23:11 Done.
195 {
196 delete[] static_cast<const uint8_t*>(pixels);
197 }, nullptr));
198 return StaticBitmapImage::create(scaledImage);
199 }
200
201 static void scaleCropRect(IntRect& cropRect, int width, int height, unsigned res izeWidth, unsigned resizeHeight)
202 {
203 if (cropRect.x() == 0 && cropRect.y() == 0 && cropRect.width() == width && c ropRect.height() == height) {
204 cropRect.setWidth(resizeWidth);
205 cropRect.setHeight(resizeHeight);
206 }
207 }
208
209 ImageBitmap::ImageBitmap(HTMLImageElement* image, IntRect& cropRect, Document* d ocument, const ImageBitmapOptions& options)
187 { 210 {
188 bool flipY; 211 bool flipY;
189 bool premultiplyAlpha; 212 bool premultiplyAlpha;
190 parseOptions(options, flipY, premultiplyAlpha); 213 unsigned resizeWidth = 0;
214 unsigned resizeHeight = 0;
215 SkFilterQuality resizeQuality = kLow_SkFilterQuality;
216 parseOptions(options, flipY, premultiplyAlpha, resizeWidth, resizeHeight, re sizeQuality);
217
218 RefPtr<Image> input = image->cachedImage()->getImage();
219 if (options.hasResizeWidth() && options.hasResizeHeight()
220 && (static_cast<int>(resizeWidth) != input->width() || static_cast<int>( resizeHeight) != input->height())) {
221 scaleCropRect(cropRect, input->width(), input->height(), resizeWidth, re sizeHeight);
222 input = scaleInput(input.get(), resizeWidth, resizeHeight, resizeQuality );
223 }
191 224
192 if (options.colorSpaceConversion() == "none") 225 if (options.colorSpaceConversion() == "none")
193 m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, p remultiplyAlpha, PremultiplyAlpha, ImageDecoder::GammaAndColorProfileIgnored); 226 m_image = cropImage(input.get(), cropRect, flipY, premultiplyAlpha, Prem ultiplyAlpha, ImageDecoder::GammaAndColorProfileIgnored);
194 else 227 else
195 m_image = cropImage(image->cachedImage()->getImage(), cropRect, flipY, p remultiplyAlpha, PremultiplyAlpha, ImageDecoder::GammaAndColorProfileApplied); 228 m_image = cropImage(input.get(), cropRect, flipY, premultiplyAlpha, Prem ultiplyAlpha, ImageDecoder::GammaAndColorProfileApplied);
196 if (!m_image) 229 if (!m_image)
197 return; 230 return;
198 // In the case where the source image is lazy-decoded, m_image may not be in 231 // In the case where the source image is lazy-decoded, m_image may not be in
199 // a decoded state, we trigger it here. 232 // a decoded state, we trigger it here.
200 RefPtr<SkImage> skImage = m_image->imageForCurrentFrame(); 233 RefPtr<SkImage> skImage = m_image->imageForCurrentFrame();
201 SkPixmap pixmap; 234 SkPixmap pixmap;
202 if (!skImage->isTextureBacked() && !skImage->peekPixels(&pixmap)) { 235 if (!skImage->isTextureBacked() && !skImage->peekPixels(&pixmap)) {
203 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(skImage->width (), skImage->height()); 236 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(skImage->width (), skImage->height());
204 surface->getCanvas()->drawImage(skImage.get(), 0, 0); 237 surface->getCanvas()->drawImage(skImage.get(), 0, 0);
205 m_image = StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot( ))); 238 m_image = StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot( )));
206 } 239 }
207 m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin ())); 240 m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin ()));
208 m_image->setPremultiplied(premultiplyAlpha); 241 m_image->setPremultiplied(premultiplyAlpha);
209 } 242 }
210 243
211 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, Docum ent* document, const ImageBitmapOptions& options) 244 ImageBitmap::ImageBitmap(HTMLVideoElement* video, IntRect& cropRect, Document* d ocument, const ImageBitmapOptions& options)
212 { 245 {
213 IntSize playerSize; 246 IntSize playerSize;
214 if (video->webMediaPlayer()) 247 if (video->webMediaPlayer())
215 playerSize = video->webMediaPlayer()->naturalSize(); 248 playerSize = video->webMediaPlayer()->naturalSize();
216 249
217 IntRect videoRect = IntRect(IntPoint(), playerSize); 250 IntRect videoRect = IntRect(IntPoint(), playerSize);
218 IntRect srcRect = intersection(cropRect, videoRect); 251 IntRect srcRect = intersection(cropRect, videoRect);
219 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), N onOpaque, DoNotInitializeImagePixels); 252 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), N onOpaque, DoNotInitializeImagePixels);
220 if (!buffer) 253 if (!buffer)
221 return; 254 return;
222 255
223 IntPoint dstPoint = IntPoint(std::max(0, -cropRect.x()), std::max(0, -cropRe ct.y())); 256 IntPoint dstPoint = IntPoint(std::max(0, -cropRect.x()), std::max(0, -cropRe ct.y()));
224 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size()) , nullptr); 257 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size()) , nullptr);
225 258
226 bool flipY; 259 bool flipY;
227 bool premultiplyAlpha; 260 bool premultiplyAlpha;
228 parseOptions(options, flipY, premultiplyAlpha); 261 unsigned resizeWidth = 0;
262 unsigned resizeHeight = 0;
263 SkFilterQuality resizeQuality = kLow_SkFilterQuality;
264 parseOptions(options, flipY, premultiplyAlpha, resizeWidth, resizeHeight, re sizeQuality);
229 265
230 if (flipY || !premultiplyAlpha) { 266 if (flipY || !premultiplyAlpha) {
231 RefPtr<SkImage> skiaImage = buffer->newSkImageSnapshot(PreferNoAccelerat ion, SnapshotReasonUnknown); 267 RefPtr<SkImage> skiaImage = buffer->newSkImageSnapshot(PreferNoAccelerat ion, SnapshotReasonUnknown);
232 if (flipY) 268 if (flipY)
233 skiaImage = flipSkImageVertically(skiaImage.get(), PremultiplyAlpha) ; 269 skiaImage = flipSkImageVertically(skiaImage.get(), PremultiplyAlpha) ;
234 if (!premultiplyAlpha) 270 if (!premultiplyAlpha)
235 skiaImage = premulSkImageToUnPremul(skiaImage.get()); 271 skiaImage = premulSkImageToUnPremul(skiaImage.get());
236 m_image = StaticBitmapImage::create(skiaImage.release()); 272 m_image = StaticBitmapImage::create(skiaImage.release());
237 } else { 273 } else {
238 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA cceleration, SnapshotReasonUnknown)); 274 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA cceleration, SnapshotReasonUnknown));
239 } 275 }
240 m_image->setOriginClean(!video->wouldTaintOrigin(document->getSecurityOrigin ())); 276 m_image->setOriginClean(!video->wouldTaintOrigin(document->getSecurityOrigin ()));
241 m_image->setPremultiplied(premultiplyAlpha); 277 m_image->setPremultiplied(premultiplyAlpha);
242 } 278 }
243 279
244 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect, con st ImageBitmapOptions& options) 280 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, IntRect& cropRect, const Ima geBitmapOptions& options)
245 { 281 {
246 ASSERT(canvas->isPaintable()); 282 ASSERT(canvas->isPaintable());
247 bool flipY; 283 bool flipY;
248 bool premultiplyAlpha; 284 bool premultiplyAlpha;
249 parseOptions(options, flipY, premultiplyAlpha); 285 unsigned resizeWidth = 0;
286 unsigned resizeHeight = 0;
287 SkFilterQuality resizeQuality = kLow_SkFilterQuality;
288 parseOptions(options, flipY, premultiplyAlpha, resizeWidth, resizeHeight, re sizeQuality);
289
290 RefPtr<Image> input = canvas->copiedImage(BackBuffer, PreferAcceleration);
291 if (options.hasResizeWidth() && options.hasResizeHeight()
292 && (static_cast<int>(resizeWidth) != input->width() || static_cast<int>( resizeHeight) != input->height())) {
293 scaleCropRect(cropRect, input->width(), input->height(), resizeWidth, re sizeHeight);
294 input = scaleInput(input.get(), resizeWidth, resizeHeight, resizeQuality );
295 }
250 296
251 // canvas is always premultiplied, so set the last parameter to true and con vert to un-premul later 297 // canvas is always premultiplied, so set the last parameter to true and con vert to un-premul later
252 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).get( ), cropRect, flipY, true); 298 m_image = cropImage(input.get(), cropRect, flipY, true);
253 if (!m_image) 299 if (!m_image)
254 return; 300 return;
255 if (!premultiplyAlpha) 301 if (!premultiplyAlpha)
256 m_image = StaticBitmapImage::create(premulSkImageToUnPremul(m_image->ima geForCurrentFrame().get())); 302 m_image = StaticBitmapImage::create(premulSkImageToUnPremul(m_image->ima geForCurrentFrame().get()));
257 m_image->setOriginClean(canvas->originClean()); 303 m_image->setOriginClean(canvas->originClean());
258 m_image->setPremultiplied(premultiplyAlpha); 304 m_image->setPremultiplied(premultiplyAlpha);
259 } 305 }
260 306
261 // The last two parameters are used for structure-cloning. 307 // The last two parameters are used for structure-cloning.
262 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect, const ImageBi tmapOptions& options, const bool& isImageDataPremultiplied, const bool& isImageD ataOriginClean) 308 ImageBitmap::ImageBitmap(ImageData* data, IntRect& cropRect, const ImageBitmapOp tions& options, const bool& isImageDataPremultiplied, const bool& isImageDataOri ginClean)
263 { 309 {
264 bool flipY; 310 bool flipY;
265 bool premultiplyAlpha; 311 bool premultiplyAlpha;
266 parseOptions(options, flipY, premultiplyAlpha); 312 unsigned resizeWidth = 0;
313 unsigned resizeHeight = 0;
314 SkFilterQuality resizeQuality = kLow_SkFilterQuality;
315 parseOptions(options, flipY, premultiplyAlpha, resizeWidth, resizeHeight, re sizeQuality);
267 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); 316 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size()));
268 317
269 // treat non-premultiplyAlpha as a special case 318 // treat non-premultiplyAlpha as a special case
270 if (!premultiplyAlpha) { 319 if (!premultiplyAlpha) {
271 unsigned char* srcAddr = data->data()->data(); 320 unsigned char* srcAddr = data->data()->data();
272 int srcHeight = data->size().height(); 321 int srcHeight = data->size().height();
273 int dstHeight = cropRect.height(); 322 int dstHeight = cropRect.height();
274 // TODO (xidachen): skia doesn't support SkImage::NewRasterCopy from a k RGBA color type. 323 // TODO (xidachen): skia doesn't support SkImage::NewRasterCopy from a k RGBA color type.
275 // For now, we swap R and B channel and uses kBGRA color type. 324 // For now, we swap R and B channel and uses kBGRA color type.
276 SkImageInfo info; 325 SkImageInfo info;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 dstPoint.setX(-cropRect.x()); 384 dstPoint.setX(-cropRect.x());
336 if (cropRect.y() < 0) 385 if (cropRect.y() < 0)
337 dstPoint.setY(-cropRect.y()); 386 dstPoint.setY(-cropRect.y());
338 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe ct, dstPoint); 387 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe ct, dstPoint);
339 if (flipY) 388 if (flipY)
340 m_image = StaticBitmapImage::create(flipSkImageVertically(buffer->newSkI mageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown).get(), PremultiplyAlph a)); 389 m_image = StaticBitmapImage::create(flipSkImageVertically(buffer->newSkI mageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown).get(), PremultiplyAlph a));
341 else 390 else
342 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA cceleration, SnapshotReasonUnknown)); 391 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA cceleration, SnapshotReasonUnknown));
343 } 392 }
344 393
345 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect, const Ima geBitmapOptions& options) 394 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, IntRect& cropRect, const ImageBitm apOptions& options)
346 { 395 {
347 bool flipY; 396 bool flipY;
348 bool premultiplyAlpha; 397 bool premultiplyAlpha;
349 parseOptions(options, flipY, premultiplyAlpha); 398 unsigned resizeWidth = 0;
350 m_image = cropImage(bitmap->bitmapImage(), cropRect, flipY, premultiplyAlpha , bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha); 399 unsigned resizeHeight = 0;
400 SkFilterQuality resizeQuality = kLow_SkFilterQuality;
401 parseOptions(options, flipY, premultiplyAlpha, resizeWidth, resizeHeight, re sizeQuality);
402
403 RefPtr<Image> input = bitmap->bitmapImage();
404 if (options.hasResizeWidth() && options.hasResizeHeight()
405 && (static_cast<int>(resizeWidth) != input->width() || static_cast<int>( resizeHeight) != input->height())) {
406 scaleCropRect(cropRect, input->width(), input->height(), resizeWidth, re sizeHeight);
407 input = scaleInput(input.get(), resizeWidth, resizeHeight, resizeQuality );
408 }
409
410 m_image = cropImage(input.get(), cropRect, flipY, premultiplyAlpha, bitmap-> isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha);
351 if (!m_image) 411 if (!m_image)
352 return; 412 return;
353 m_image->setOriginClean(bitmap->originClean()); 413 m_image->setOriginClean(bitmap->originClean());
354 m_image->setPremultiplied(premultiplyAlpha); 414 m_image->setPremultiplied(premultiplyAlpha);
355 } 415 }
356 416
357 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image, const IntRect& cro pRect, const ImageBitmapOptions& options) 417 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image, IntRect& cropRect, const ImageBitmapOptions& options)
358 { 418 {
359 bool flipY; 419 bool flipY;
360 bool premultiplyAlpha; 420 bool premultiplyAlpha;
361 parseOptions(options, flipY, premultiplyAlpha); 421 unsigned resizeWidth = 0;
362 m_image = cropImage(image.get(), cropRect, flipY, premultiplyAlpha, DontPrem ultiplyAlpha); 422 unsigned resizeHeight = 0;
423 SkFilterQuality resizeQuality = kLow_SkFilterQuality;
424 parseOptions(options, flipY, premultiplyAlpha, resizeWidth, resizeHeight, re sizeQuality);
jbroman 2016/06/29 21:14:42 This is getting to be quite a few options; have yo
xidachen 2016/06/30 15:23:12 Done.
425
426 bool originClean = image->originClean();
427 RefPtr<Image> input = image;
428 if (options.hasResizeWidth() && options.hasResizeHeight()
jbroman 2016/06/29 21:14:41 nit: It seems a little odd to duplicate the "shoul
xidachen 2016/06/30 15:23:11 Done.
429 && (static_cast<int>(resizeWidth) != input->width() || static_cast<int>( resizeHeight) != input->height())) {
430 scaleCropRect(cropRect, input->width(), input->height(), resizeWidth, re sizeHeight);
jbroman 2016/06/29 21:14:41 A lot of this logic is duplicated with the above f
xidachen 2016/06/30 15:23:11 Done.
431 input = scaleInput(input.get(), resizeWidth, resizeHeight, resizeQuality );
432 }
433
434 m_image = cropImage(input.get(), cropRect, flipY, premultiplyAlpha, DontPrem ultiplyAlpha);
363 if (!m_image) 435 if (!m_image)
364 return; 436 return;
365 m_image->setOriginClean(image->originClean()); 437 m_image->setOriginClean(originClean);
366 m_image->setPremultiplied(premultiplyAlpha); 438 m_image->setPremultiplied(premultiplyAlpha);
367 } 439 }
368 440
369 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image) 441 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image)
370 { 442 {
371 m_image = image; 443 m_image = image;
372 } 444 }
373 445
374 ImageBitmap::ImageBitmap(WebExternalTextureMailbox& mailbox) 446 ImageBitmap::ImageBitmap(WebExternalTextureMailbox& mailbox)
375 { 447 {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 557
486 ScriptPromise ImageBitmap::createImageBitmap(ScriptState* scriptState, EventTarg et& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& optio ns, ExceptionState& exceptionState) 558 ScriptPromise ImageBitmap::createImageBitmap(ScriptState* scriptState, EventTarg et& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& optio ns, ExceptionState& exceptionState)
487 { 559 {
488 if (!sw || !sh) { 560 if (!sw || !sh) {
489 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s provided is 0.", sw ? "height" : "width")); 561 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s provided is 0.", sw ? "height" : "width"));
490 return ScriptPromise(); 562 return ScriptPromise();
491 } 563 }
492 return ImageBitmapSource::fulfillImageBitmap(scriptState, create(this, IntRe ct(sx, sy, sw, sh), options)); 564 return ImageBitmapSource::fulfillImageBitmap(scriptState, create(this, IntRe ct(sx, sy, sw, sh), options));
493 } 565 }
494 566
495 void ImageBitmap::parseOptions(const ImageBitmapOptions& options, bool& flipY, b ool& premultiplyAlpha) 567 void ImageBitmap::parseOptions(const ImageBitmapOptions& options, bool& flipY, b ool& premultiplyAlpha, unsigned& resizeWidth, unsigned& resizeHeight, SkFilterQu ality& resizeQuality)
496 { 568 {
497 if (options.imageOrientation() == imageOrientationFlipY) { 569 if (options.imageOrientation() == imageOrientationFlipY) {
498 flipY = true; 570 flipY = true;
499 } else { 571 } else {
500 flipY = false; 572 flipY = false;
501 ASSERT(options.imageOrientation() == imageBitmapOptionNone); 573 ASSERT(options.imageOrientation() == imageBitmapOptionNone);
502 } 574 }
503 if (options.premultiplyAlpha() == imageBitmapOptionNone) { 575 if (options.premultiplyAlpha() == imageBitmapOptionNone) {
504 premultiplyAlpha = false; 576 premultiplyAlpha = false;
505 } else { 577 } else {
506 premultiplyAlpha = true; 578 premultiplyAlpha = true;
507 ASSERT(options.premultiplyAlpha() == "default" || options.premultiplyAlp ha() == "premultiply"); 579 ASSERT(options.premultiplyAlpha() == "default" || options.premultiplyAlp ha() == "premultiply");
508 } 580 }
581 if (options.hasResizeWidth() && options.hasResizeHeight()) {
jbroman 2016/06/29 21:14:41 What if one is provided but not the other? Your sp
xidachen 2016/06/30 15:23:11 Changed to scale proportionally, will have a pull
582 resizeWidth = options.resizeWidth();
583 resizeHeight = options.resizeHeight();
584 if (options.resizeQuality() == "high")
585 resizeQuality = kHigh_SkFilterQuality;
586 else if (options.resizeQuality() == "medium")
587 resizeQuality = kMedium_SkFilterQuality;
588 else if (options.resizeQuality() == "pixelated")
589 resizeQuality = kNone_SkFilterQuality;
590 else
591 DCHECK_EQ(options.resizeQuality(), "low");
592 }
509 } 593 }
510 594
511 PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageStatus* status , AccelerationHint, SnapshotReason, const FloatSize&) const 595 PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageStatus* status , AccelerationHint, SnapshotReason, const FloatSize&) const
512 { 596 {
513 *status = NormalSourceImageStatus; 597 *status = NormalSourceImageStatus;
514 return m_image ? m_image : nullptr; 598 return m_image ? m_image : nullptr;
515 } 599 }
516 600
517 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const 601 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const
518 { 602 {
519 } 603 }
520 604
521 FloatSize ImageBitmap::elementSize(const FloatSize&) const 605 FloatSize ImageBitmap::elementSize(const FloatSize&) const
522 { 606 {
523 return FloatSize(width(), height()); 607 return FloatSize(width(), height());
524 } 608 }
525 609
526 DEFINE_TRACE(ImageBitmap) 610 DEFINE_TRACE(ImageBitmap)
527 { 611 {
528 } 612 }
529 613
530 } // namespace blink 614 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698