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

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

Issue 562583002: Implement image-rendering:pixelated for accelerated 2D canvases. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove printfs, update test comments. Created 6 years, 1 month 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 : HTMLElement(canvasTag, document) 80 : HTMLElement(canvasTag, document)
81 , DocumentVisibilityObserver(document) 81 , DocumentVisibilityObserver(document)
82 , m_size(DefaultWidth, DefaultHeight) 82 , m_size(DefaultWidth, DefaultHeight)
83 , m_ignoreReset(false) 83 , m_ignoreReset(false)
84 , m_accelerationDisabled(false) 84 , m_accelerationDisabled(false)
85 , m_externallyAllocatedMemory(0) 85 , m_externallyAllocatedMemory(0)
86 , m_originClean(true) 86 , m_originClean(true)
87 , m_didFailToCreateImageBuffer(false) 87 , m_didFailToCreateImageBuffer(false)
88 , m_didClearImageBuffer(false) 88 , m_didClearImageBuffer(false)
89 { 89 {
90 setHasCustomStyleCallbacks();
90 } 91 }
91 92
92 DEFINE_NODE_FACTORY(HTMLCanvasElement) 93 DEFINE_NODE_FACTORY(HTMLCanvasElement)
93 94
94 HTMLCanvasElement::~HTMLCanvasElement() 95 HTMLCanvasElement::~HTMLCanvasElement()
95 { 96 {
96 resetDirtyRect(); 97 resetDirtyRect();
97 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory); 98 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory);
98 #if !ENABLE(OILPAN) 99 #if !ENABLE(OILPAN)
99 HashSet<RawPtr<CanvasObserver> >::iterator end = m_observers.end(); 100 HashSet<RawPtr<CanvasObserver> >::iterator end = m_observers.end();
(...skipping 13 matching lines...) Expand all
113 } 114 }
114 115
115 RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style) 116 RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style)
116 { 117 {
117 LocalFrame* frame = document().frame(); 118 LocalFrame* frame = document().frame();
118 if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript)) 119 if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript))
119 return new RenderHTMLCanvas(this); 120 return new RenderHTMLCanvas(this);
120 return HTMLElement::createRenderer(style); 121 return HTMLElement::createRenderer(style);
121 } 122 }
122 123
124 void HTMLCanvasElement::didRecalcStyle(StyleRecalcChange)
125 {
126 if (!hasImageBuffer())
127 return;
128 m_imageBuffer->setFilterLevel(computedStyle()->imageRendering() == ImageRend eringPixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel);
129 }
130
123 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node) 131 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node)
124 { 132 {
125 setIsInCanvasSubtree(true); 133 setIsInCanvasSubtree(true);
126 return HTMLElement::insertedInto(node); 134 return HTMLElement::insertedInto(node);
127 } 135 }
128 136
129 void HTMLCanvasElement::addObserver(CanvasObserver* observer) 137 void HTMLCanvasElement::addObserver(CanvasObserver* observer)
130 { 138 {
131 m_observers.add(observer); 139 m_observers.add(observer);
132 } 140 }
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 // pixel readback, but that is unavoidable in this case. 535 // pixel readback, but that is unavoidable in this case.
528 // FIXME: Actually, avoid setting m_accelerationDisabled at all when 536 // FIXME: Actually, avoid setting m_accelerationDisabled at all when
529 // doing GPU-based rasterization. 537 // doing GPU-based rasterization.
530 if (m_accelerationDisabled) 538 if (m_accelerationDisabled)
531 return adoptPtr(new UnacceleratedImageBufferSurface(deviceSize, opac ityMode)); 539 return adoptPtr(new UnacceleratedImageBufferSurface(deviceSize, opac ityMode));
532 return adoptPtr(new WebGLImageBufferSurface(deviceSize, opacityMode)); 540 return adoptPtr(new WebGLImageBufferSurface(deviceSize, opacityMode));
533 } 541 }
534 542
535 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = createSu rfaceFactory(deviceSize, msaaSampleCount); 543 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = createSu rfaceFactory(deviceSize, msaaSampleCount);
536 544
537 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) { 545 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled() && false) {
Justin Novosad 2014/11/18 16:32:50 Do not hard-code disable the displayList2dCanvas f
jackhou1 2014/12/01 07:00:08 Removed. Sorry, added this when I was debugging.
538 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu rface(deviceSize, surfaceFactory.release(), opacityMode)); 546 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu rface(deviceSize, surfaceFactory.release(), opacityMode));
539 if (surface->isValid()) 547 if (surface->isValid())
540 return surface.release(); 548 return surface.release();
541 surfaceFactory = createSurfaceFactory(deviceSize, msaaSampleCount); // r ecreate because old previous one was released 549 surfaceFactory = createSurfaceFactory(deviceSize, msaaSampleCount); // r ecreate because old previous one was released
542 } 550 }
543 551
544 return surfaceFactory->createSurface(deviceSize, opacityMode); 552 return surfaceFactory->createSurface(deviceSize, opacityMode);
545 } 553 }
546 554
547 void HTMLCanvasElement::createImageBuffer() 555 void HTMLCanvasElement::createImageBuffer()
(...skipping 21 matching lines...) Expand all
569 if (!deviceSize.width() || !deviceSize.height()) 577 if (!deviceSize.width() || !deviceSize.height())
570 return; 578 return;
571 579
572 int msaaSampleCount; 580 int msaaSampleCount;
573 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(deviceSize, &m saaSampleCount); 581 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(deviceSize, &m saaSampleCount);
574 if (!surface->isValid()) 582 if (!surface->isValid())
575 return; 583 return;
576 584
577 m_imageBuffer = ImageBuffer::create(surface.release()); 585 m_imageBuffer = ImageBuffer::create(surface.release());
578 m_imageBuffer->setClient(this); 586 m_imageBuffer->setClient(this);
587 m_imageBuffer->setFilterLevel(computedStyle()->imageRendering() == ImageRend eringPixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel);
579 588
580 m_didFailToCreateImageBuffer = false; 589 m_didFailToCreateImageBuffer = false;
581 590
582 updateExternallyAllocatedMemory(); 591 updateExternallyAllocatedMemory();
583 592
584 if (is3D()) { 593 if (is3D()) {
585 // Early out for WebGL canvases 594 // Early out for WebGL canvases
586 return; 595 return;
587 } 596 }
588 597
589 m_imageBuffer->setClient(this); 598 m_imageBuffer->setClient(this);
590 m_imageBuffer->context()->setShouldClampToSourceRect(false); 599 m_imageBuffer->context()->setShouldClampToSourceRect(false);
591 m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages() ; 600 m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages() ;
592 m_imageBuffer->context()->setImageInterpolationQuality(CanvasDefaultInterpol ationQuality); 601 m_imageBuffer->context()->setImageInterpolationQuality(computedStyle()->imag eRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaul tInterpolationQuality);
593 // Enabling MSAA overrides a request to disable antialiasing. This is true r egardless of whether the 602 // Enabling MSAA overrides a request to disable antialiasing. This is true r egardless of whether the
594 // rendering mode is accelerated or not. For consistency, we don't want to a pply AA in accelerated 603 // rendering mode is accelerated or not. For consistency, we don't want to a pply AA in accelerated
595 // canvases but not in unaccelerated canvases. 604 // canvases but not in unaccelerated canvases.
596 if (!msaaSampleCount && document().settings() && !document().settings()->ant ialiased2dCanvasEnabled()) 605 if (!msaaSampleCount && document().settings() && !document().settings()->ant ialiased2dCanvasEnabled())
597 m_imageBuffer->context()->setShouldAntialias(false); 606 m_imageBuffer->context()->setShouldAntialias(false);
598 // GraphicsContext's defaults don't always agree with the 2d canvas spec. 607 // GraphicsContext's defaults don't always agree with the 2d canvas spec.
599 // See CanvasRenderingContext2D::State::State() for more information. 608 // See CanvasRenderingContext2D::State::State() for more information.
600 m_imageBuffer->context()->setMiterLimit(10); 609 m_imageBuffer->context()->setMiterLimit(10);
601 m_imageBuffer->context()->setStrokeThickness(1); 610 m_imageBuffer->context()->setStrokeThickness(1);
602 #if ENABLE(ASSERT) 611 #if ENABLE(ASSERT)
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 if (!width() || !height()) { 771 if (!width() || !height()) {
763 *status = ZeroSizeCanvasSourceImageStatus; 772 *status = ZeroSizeCanvasSourceImageStatus;
764 return nullptr; 773 return nullptr;
765 } 774 }
766 775
767 if (!buffer()) { 776 if (!buffer()) {
768 *status = InvalidSourceImageStatus; 777 *status = InvalidSourceImageStatus;
769 return nullptr; 778 return nullptr;
770 } 779 }
771 780
781 m_imageBuffer->willAccessPixels();
782
772 if (m_context && m_context->is3d()) { 783 if (m_context && m_context->is3d()) {
773 m_context->paintRenderingResultsToCanvas(); 784 m_context->paintRenderingResultsToCanvas();
774 *status = ExternalSourceImageStatus; 785 *status = ExternalSourceImageStatus;
775 786
776 // can't create SkImage from WebGLImageBufferSurface (contains only SkBi tmap) 787 // can't create SkImage from WebGLImageBufferSurface (contains only SkBi tmap)
777 return m_imageBuffer->copyImage(DontCopyBackingStore, Unscaled); 788 return m_imageBuffer->copyImage(DontCopyBackingStore, Unscaled);
778 } 789 }
779 790
780 RefPtr<SkImage> image = m_imageBuffer->newImageSnapshot(); 791 RefPtr<SkImage> image = m_imageBuffer->newImageSnapshot();
781 if (image) { 792 if (image) {
(...skipping 12 matching lines...) Expand all
794 { 805 {
795 return !originClean(); 806 return !originClean();
796 } 807 }
797 808
798 FloatSize HTMLCanvasElement::sourceSize() const 809 FloatSize HTMLCanvasElement::sourceSize() const
799 { 810 {
800 return FloatSize(width(), height()); 811 return FloatSize(width(), height());
801 } 812 }
802 813
803 } 814 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698