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

Side by Side Diff: Source/core/html/HTMLCanvasElement.cpp

Issue 749653002: WebGL: clarify which Front or Back buffer is used by each API. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase to ToT Created 6 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) 2004, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 { 80 {
81 if (deviceSize.width() * deviceSize.height() > MaxCanvasArea) 81 if (deviceSize.width() * deviceSize.height() > MaxCanvasArea)
82 return false; 82 return false;
83 if (deviceSize.width() > MaxSkiaDim || deviceSize.height() > MaxSkiaDim) 83 if (deviceSize.width() > MaxSkiaDim || deviceSize.height() > MaxSkiaDim)
84 return false; 84 return false;
85 if (!deviceSize.width() || !deviceSize.height()) 85 if (!deviceSize.width() || !deviceSize.height())
86 return false; 86 return false;
87 return true; 87 return true;
88 } 88 }
89 89
90 CanvasRenderingContext::SourceBuffer convertSourceBuffer(HTMLCanvasElement::Sour ceBuffer sourceBuffer)
91 {
92 return static_cast<CanvasRenderingContext::SourceBuffer>(sourceBuffer);
93 }
94
90 } // namespace 95 } // namespace
91 96
92 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CanvasObserver); 97 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CanvasObserver);
93 98
94 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) 99 inline HTMLCanvasElement::HTMLCanvasElement(Document& document)
95 : HTMLElement(canvasTag, document) 100 : HTMLElement(canvasTag, document)
96 , DocumentVisibilityObserver(document) 101 , DocumentVisibilityObserver(document)
97 , m_size(DefaultWidth, DefaultHeight) 102 , m_size(DefaultWidth, DefaultHeight)
98 , m_ignoreReset(false) 103 , m_ignoreReset(false)
99 , m_accelerationDisabled(false) 104 , m_accelerationDisabled(false)
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 403
399 // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread). 404 // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread).
400 if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncod ing(lowercaseMimeType)) 405 if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncod ing(lowercaseMimeType))
401 lowercaseMimeType = "image/png"; 406 lowercaseMimeType = "image/png";
402 407
403 return lowercaseMimeType; 408 return lowercaseMimeType;
404 } 409 }
405 410
406 const AtomicString HTMLCanvasElement::imageSourceURL() const 411 const AtomicString HTMLCanvasElement::imageSourceURL() const
407 { 412 {
408 return AtomicString(toDataURLInternal("image/png", 0, true)); 413 return AtomicString(toDataURLInternal("image/png", 0, Front));
409 } 414 }
410 415
411 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double * quality, bool isSaving) const 416 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double * quality, SourceBuffer sourceBuffer) const
412 { 417 {
413 if (m_size.isEmpty() || !canCreateImageBuffer(size())) 418 if (m_size.isEmpty() || !canCreateImageBuffer(size()))
414 return String("data:,"); 419 return String("data:,");
415 420
416 String encodingMimeType = toEncodingMimeType(mimeType); 421 String encodingMimeType = toEncodingMimeType(mimeType);
417 if (!m_context) { 422 if (!m_context) {
418 RefPtrWillBeRawPtr<ImageData> imageData = ImageData::create(m_size); 423 RefPtrWillBeRawPtr<ImageData> imageData = ImageData::create(m_size);
419 return ImageDataToDataURL(ImageDataBuffer(imageData->size(), imageData-> data()), encodingMimeType, quality); 424 return ImageDataToDataURL(ImageDataBuffer(imageData->size(), imageData-> data()), encodingMimeType, quality);
420 } 425 }
421 426
422 // Try to get ImageData first, as that may avoid lossy conversions.
423 RefPtrWillBeRawPtr<ImageData> imageData = getImageData();
424
425 if (imageData)
426 return ImageDataToDataURL(ImageDataBuffer(imageData->size(), imageData-> data()), encodingMimeType, quality);
427
428 if (m_context->is3d()) { 427 if (m_context->is3d()) {
429 m_context->paintRenderingResultsToCanvas(isSaving ? CanvasRenderingConte xt::Front : CanvasRenderingContext::Back); 428 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL().
429 RefPtrWillBeRawPtr<ImageData> imageData =
430 toWebGLRenderingContext(m_context.get())->paintRenderingResultsToIma geData(convertSourceBuffer(sourceBuffer));
431 if (imageData)
432 return ImageDataToDataURL(ImageDataBuffer(imageData->size(), imageDa ta->data()), encodingMimeType, quality);
433 m_context->paintRenderingResultsToCanvas(convertSourceBuffer(sourceBuffe r));
430 } 434 }
431 435
432 return buffer()->toDataURL(encodingMimeType, quality); 436 return buffer()->toDataURL(encodingMimeType, quality);
433 } 437 }
434 438
435 String HTMLCanvasElement::toDataURL(const String& mimeType, const double* qualit y, ExceptionState& exceptionState) const 439 String HTMLCanvasElement::toDataURL(const String& mimeType, const double* qualit y, ExceptionState& exceptionState) const
436 { 440 {
437 if (!m_originClean) { 441 if (!m_originClean) {
438 exceptionState.throwSecurityError("Tainted canvases may not be exported. "); 442 exceptionState.throwSecurityError("Tainted canvases may not be exported. ");
439 return String(); 443 return String();
440 } 444 }
441 445
442 return toDataURLInternal(mimeType, quality); 446 return toDataURLInternal(mimeType, quality, Back);
443 }
444
445 PassRefPtrWillBeRawPtr<ImageData> HTMLCanvasElement::getImageData() const
446 {
447 if (!m_context || !m_context->is3d())
448 return nullptr;
449 return toWebGLRenderingContext(m_context.get())->paintRenderingResultsToImag eData();
450 } 447 }
451 448
452 SecurityOrigin* HTMLCanvasElement::securityOrigin() const 449 SecurityOrigin* HTMLCanvasElement::securityOrigin() const
453 { 450 {
454 return document().securityOrigin(); 451 return document().securityOrigin();
455 } 452 }
456 453
457 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const 454 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const
458 { 455 {
459 if (m_context && !m_context->is2d()) 456 if (m_context && !m_context->is2d())
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 void HTMLCanvasElement::ensureUnacceleratedImageBuffer() 677 void HTMLCanvasElement::ensureUnacceleratedImageBuffer()
681 { 678 {
682 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea teImageBuffer) 679 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea teImageBuffer)
683 return; 680 return;
684 discardImageBuffer(); 681 discardImageBuffer();
685 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque; 682 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque;
686 m_imageBuffer = ImageBuffer::create(size(), opacityMode); 683 m_imageBuffer = ImageBuffer::create(size(), opacityMode);
687 m_didFailToCreateImageBuffer = !m_imageBuffer; 684 m_didFailToCreateImageBuffer = !m_imageBuffer;
688 } 685 }
689 686
690 Image* HTMLCanvasElement::copiedImage() const 687 Image* HTMLCanvasElement::copiedImage(SourceBuffer sourceBuffer) const
691 { 688 {
692 if (!m_copiedImage && buffer()) { 689 if (!m_copiedImage && buffer()) {
693 if (m_context && m_context->is3d()) { 690 if (m_context && m_context->is3d())
694 m_context->paintRenderingResultsToCanvas(CanvasRenderingContext::Fro nt); 691 m_context->paintRenderingResultsToCanvas(convertSourceBuffer(sourceB uffer));
695 }
696 m_copiedImage = buffer()->copyImage(CopyBackingStore, Unscaled); 692 m_copiedImage = buffer()->copyImage(CopyBackingStore, Unscaled);
697 updateExternallyAllocatedMemory(); 693 updateExternallyAllocatedMemory();
698 } 694 }
699 return m_copiedImage.get(); 695 return m_copiedImage.get();
700 } 696 }
701 697
702 void HTMLCanvasElement::discardImageBuffer() 698 void HTMLCanvasElement::discardImageBuffer()
703 { 699 {
704 m_contextStateSaver.clear(); // uses context owned by m_imageBuffer 700 m_contextStateSaver.clear(); // uses context owned by m_imageBuffer
705 m_imageBuffer.clear(); 701 m_imageBuffer.clear();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 { 779 {
784 return !originClean(); 780 return !originClean();
785 } 781 }
786 782
787 FloatSize HTMLCanvasElement::sourceSize() const 783 FloatSize HTMLCanvasElement::sourceSize() const
788 { 784 {
789 return FloatSize(width(), height()); 785 return FloatSize(width(), height());
790 } 786 }
791 787
792 } 788 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698