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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp

Issue 1790753002: Expose GLES2Interface to blink, and delete isContextLost() from WGC3D. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wgc3d: deps-for-tests Created 4 years, 9 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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "platform/graphics/Canvas2DLayerBridge.h" 26 #include "platform/graphics/Canvas2DLayerBridge.h"
27 27
28 #include "gpu/command_buffer/client/gles2_interface.h"
28 #include "platform/Histogram.h" 29 #include "platform/Histogram.h"
29 #include "platform/RuntimeEnabledFeatures.h" 30 #include "platform/RuntimeEnabledFeatures.h"
30 #include "platform/TraceEvent.h" 31 #include "platform/TraceEvent.h"
31 #include "platform/graphics/CanvasMetrics.h" 32 #include "platform/graphics/CanvasMetrics.h"
32 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" 33 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h"
33 #include "platform/graphics/GraphicsLayer.h" 34 #include "platform/graphics/GraphicsLayer.h"
34 #include "platform/graphics/ImageBuffer.h" 35 #include "platform/graphics/ImageBuffer.h"
35 #include "platform/graphics/gpu/SharedContextRateLimiter.h" 36 #include "platform/graphics/gpu/SharedContextRateLimiter.h"
36 #include "public/platform/Platform.h" 37 #include "public/platform/Platform.h"
37 #include "public/platform/WebCompositorSupport.h" 38 #include "public/platform/WebCompositorSupport.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 bool accelerate; 172 bool accelerate;
172 if (m_softwareRenderingWhileHidden) 173 if (m_softwareRenderingWhileHidden)
173 accelerate = false; 174 accelerate = false;
174 else if (m_accelerationMode == ForceAccelerationForTesting) 175 else if (m_accelerationMode == ForceAccelerationForTesting)
175 accelerate = true; 176 accelerate = true;
176 else if (m_accelerationMode == DisableAcceleration) 177 else if (m_accelerationMode == DisableAcceleration)
177 accelerate = false; 178 accelerate = false;
178 else 179 else
179 accelerate = hint == PreferAcceleration || hint == PreferAccelerationAft erVisibilityChange; 180 accelerate = hint == PreferAcceleration || hint == PreferAccelerationAft erVisibilityChange;
180 181
181 if (accelerate && (!m_contextProvider || m_contextProvider->context3d()->isC ontextLost())) 182 if (accelerate && (!m_contextProvider || m_contextProvider->contextGL()->Get GraphicsResetStatusKHR() != GL_NO_ERROR))
182 accelerate = false; 183 accelerate = false;
183 return accelerate; 184 return accelerate;
184 } 185 }
185 186
186 bool Canvas2DLayerBridge::isAccelerated() const 187 bool Canvas2DLayerBridge::isAccelerated() const
187 { 188 {
188 if (isHibernating()) 189 if (isHibernating())
189 return false; 190 return false;
190 if (m_softwareRenderingWhileHidden) 191 if (m_softwareRenderingWhileHidden)
191 return false; 192 return false;
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 { 721 {
721 ASSERT(!m_destructionInProgress); 722 ASSERT(!m_destructionInProgress);
722 if (m_destructionInProgress) 723 if (m_destructionInProgress)
723 return false; 724 return false;
724 if (isHibernating()) 725 if (isHibernating())
725 return true; 726 return true;
726 if (!m_layer) 727 if (!m_layer)
727 return true; 728 return true;
728 if (!m_surface) 729 if (!m_surface)
729 return false; 730 return false;
730 if (m_contextProvider->context3d()->isContextLost()) { 731 if (m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERR OR) {
731 m_surface.clear(); 732 m_surface.clear();
732 for (auto mailboxInfo = m_mailboxes.begin(); mailboxInfo != m_mailboxes. end(); ++mailboxInfo) { 733 for (auto mailboxInfo = m_mailboxes.begin(); mailboxInfo != m_mailboxes. end(); ++mailboxInfo) {
733 if (mailboxInfo->m_image) 734 if (mailboxInfo->m_image)
734 mailboxInfo->m_image.clear(); 735 mailboxInfo->m_image.clear();
735 } 736 }
736 if (m_imageBuffer) 737 if (m_imageBuffer)
737 m_imageBuffer->notifySurfaceInvalid(); 738 m_imageBuffer->notifySurfaceInvalid();
738 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Accelerated2DCanva sGPUContextLost); 739 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Accelerated2DCanva sGPUContextLost);
739 } 740 }
740 return m_surface; 741 return m_surface;
741 } 742 }
742 743
743 bool Canvas2DLayerBridge::restoreSurface() 744 bool Canvas2DLayerBridge::restoreSurface()
744 { 745 {
745 ASSERT(!m_destructionInProgress); 746 ASSERT(!m_destructionInProgress);
746 if (m_destructionInProgress) 747 if (m_destructionInProgress)
747 return false; 748 return false;
748 ASSERT(isAccelerated() && !m_surface); 749 ASSERT(isAccelerated() && !m_surface);
749 750
750 WebGraphicsContext3D* sharedContext = 0; 751 gpu::gles2::GLES2Interface* sharedGL = nullptr;
751 m_layer->clearTexture(); 752 m_layer->clearTexture();
752 m_contextProvider = adoptPtr(Platform::current()->createSharedOffscreenGraph icsContext3DProvider()); 753 m_contextProvider = adoptPtr(Platform::current()->createSharedOffscreenGraph icsContext3DProvider());
753 if (m_contextProvider) 754 if (m_contextProvider)
754 sharedContext = m_contextProvider->context3d(); 755 sharedGL = m_contextProvider->contextGL();
755 756
756 if (sharedContext && !sharedContext->isContextLost()) { 757 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) {
757 GrContext* grCtx = m_contextProvider->grContext(); 758 GrContext* grCtx = m_contextProvider->grContext();
758 bool surfaceIsAccelerated; 759 bool surfaceIsAccelerated;
759 RefPtr<SkSurface> surface(createSkSurface(grCtx, m_size, m_msaaSampleCou nt, m_opacityMode, &surfaceIsAccelerated)); 760 RefPtr<SkSurface> surface(createSkSurface(grCtx, m_size, m_msaaSampleCou nt, m_opacityMode, &surfaceIsAccelerated));
760 761
761 if (!m_surface) 762 if (!m_surface)
762 reportSurfaceCreationFailure(); 763 reportSurfaceCreationFailure();
763 764
764 // Current paradigm does support switching from accelerated to non-accel erated, which would be tricky 765 // Current paradigm does support switching from accelerated to non-accel erated, which would be tricky
765 // due to changes to the layer tree, which can only happen at specific t imes during the document lifecycle. 766 // due to changes to the layer tree, which can only happen at specific t imes during the document lifecycle.
766 // Therefore, we can only accept the restored surface if it is accelerat ed. 767 // Therefore, we can only accept the restored surface if it is accelerat ed.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 return false; 813 return false;
813 m_lastImageId = image->uniqueID(); 814 m_lastImageId = image->uniqueID();
814 m_lastFilter = filter; 815 m_lastFilter = filter;
815 816
816 return prepareMailboxFromImage(image.release(), outMailbox); 817 return prepareMailboxFromImage(image.release(), outMailbox);
817 } 818 }
818 819
819 void Canvas2DLayerBridge::mailboxReleased(const WebExternalTextureMailbox& mailb ox, bool lostResource) 820 void Canvas2DLayerBridge::mailboxReleased(const WebExternalTextureMailbox& mailb ox, bool lostResource)
820 { 821 {
821 ASSERT(isAccelerated() || isHibernating()); 822 ASSERT(isAccelerated() || isHibernating());
822 bool contextLost = !isHibernating() && (!m_surface || m_contextProvider->con text3d()->isContextLost()); 823 bool contextLost = !isHibernating() && (!m_surface || m_contextProvider->con textGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR);
823 ASSERT(m_mailboxes.last().m_parentLayerBridge.get() == this); 824 ASSERT(m_mailboxes.last().m_parentLayerBridge.get() == this);
824 825
825 // Mailboxes are typically released in FIFO order, so we iterate 826 // Mailboxes are typically released in FIFO order, so we iterate
826 // from the end of m_mailboxes. 827 // from the end of m_mailboxes.
827 auto releasedMailboxInfo = m_mailboxes.end(); 828 auto releasedMailboxInfo = m_mailboxes.end();
828 auto firstMailbox = m_mailboxes.begin(); 829 auto firstMailbox = m_mailboxes.begin();
829 830
830 while (true) { 831 while (true) {
831 --releasedMailboxInfo; 832 --releasedMailboxInfo;
832 if (nameEquals(releasedMailboxInfo->m_mailbox, mailbox)) { 833 if (nameEquals(releasedMailboxInfo->m_mailbox, mailbox)) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 #endif // USE_IOSURFACE_FOR_2D_CANVAS 990 #endif // USE_IOSURFACE_FOR_2D_CANVAS
990 } 991 }
991 992
992 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) 993 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event)
993 { 994 {
994 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib ernationEvents", HibernationEventCount)); 995 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib ernationEvents", HibernationEventCount));
995 hibernationHistogram.count(event); 996 hibernationHistogram.count(event);
996 } 997 }
997 998
998 } // namespace blink 999 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698