OLD | NEW |
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 |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 if (m_imageBuffer) | 839 if (m_imageBuffer) |
840 m_imageBuffer->notifySurfaceInvalid(); | 840 m_imageBuffer->notifySurfaceInvalid(); |
841 CanvasMetrics::countCanvasContextUsage( | 841 CanvasMetrics::countCanvasContextUsage( |
842 CanvasMetrics::Accelerated2DCanvasGPUContextLost); | 842 CanvasMetrics::Accelerated2DCanvasGPUContextLost); |
843 } | 843 } |
844 return m_surface.get(); | 844 return m_surface.get(); |
845 } | 845 } |
846 | 846 |
847 bool Canvas2DLayerBridge::restoreSurface() { | 847 bool Canvas2DLayerBridge::restoreSurface() { |
848 DCHECK(!m_destructionInProgress); | 848 DCHECK(!m_destructionInProgress); |
849 if (m_destructionInProgress) | 849 if (m_destructionInProgress || !isAccelerated()) |
850 return false; | 850 return false; |
851 DCHECK(isAccelerated() && !m_surface); | 851 DCHECK(!m_surface); |
852 | 852 |
853 gpu::gles2::GLES2Interface* sharedGL = nullptr; | 853 gpu::gles2::GLES2Interface* sharedGL = nullptr; |
854 m_layer->clearTexture(); | 854 m_layer->clearTexture(); |
855 m_contextProvider = WTF::wrapUnique( | 855 m_contextProvider = WTF::wrapUnique( |
856 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); | 856 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); |
857 if (m_contextProvider) | 857 if (m_contextProvider) |
858 sharedGL = m_contextProvider->contextGL(); | 858 sharedGL = m_contextProvider->contextGL(); |
859 | 859 |
860 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { | 860 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { |
861 GrContext* grCtx = m_contextProvider->grContext(); | 861 GrContext* grCtx = m_contextProvider->grContext(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 cc::TextureMailbox* outMailbox, | 911 cc::TextureMailbox* outMailbox, |
912 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) { | 912 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) { |
913 if (m_destructionInProgress) { | 913 if (m_destructionInProgress) { |
914 // It can be hit in the following sequence. | 914 // It can be hit in the following sequence. |
915 // 1. Canvas draws something. | 915 // 1. Canvas draws something. |
916 // 2. The compositor begins the frame. | 916 // 2. The compositor begins the frame. |
917 // 3. Javascript makes a context be lost. | 917 // 3. Javascript makes a context be lost. |
918 // 4. Here. | 918 // 4. Here. |
919 return false; | 919 return false; |
920 } | 920 } |
921 DCHECK(isAccelerated() || isHibernating() || m_softwareRenderingWhileHidden); | |
922 | |
923 // if hibernating but not hidden, we want to wake up from | |
924 // hibernation | |
925 if ((isHibernating() || m_softwareRenderingWhileHidden) && isHidden()) | |
926 return false; | |
927 | 921 |
928 // If the context is lost, we don't know if we should be producing GPU or | 922 // If the context is lost, we don't know if we should be producing GPU or |
929 // software frames, until we get a new context, since the compositor will | 923 // software frames, until we get a new context, since the compositor will |
930 // be trying to get a new context and may change modes. | 924 // be trying to get a new context and may change modes. |
931 if (!m_contextProvider || | 925 if (!m_contextProvider || |
932 m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != | 926 m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != |
933 GL_NO_ERROR) | 927 GL_NO_ERROR) |
934 return false; | 928 return false; |
935 | 929 |
| 930 DCHECK(isAccelerated() || isHibernating() || m_softwareRenderingWhileHidden); |
| 931 |
| 932 // if hibernating but not hidden, we want to wake up from |
| 933 // hibernation |
| 934 if ((isHibernating() || m_softwareRenderingWhileHidden) && isHidden()) |
| 935 return false; |
| 936 |
936 sk_sp<SkImage> image = | 937 sk_sp<SkImage> image = |
937 newImageSnapshot(PreferAcceleration, SnapshotReasonUnknown); | 938 newImageSnapshot(PreferAcceleration, SnapshotReasonUnknown); |
938 if (!image || !image->getTexture()) | 939 if (!image || !image->getTexture()) |
939 return false; | 940 return false; |
940 | 941 |
941 // Early exit if canvas was not drawn to since last prepareMailbox. | 942 // Early exit if canvas was not drawn to since last prepareMailbox. |
942 GLenum filter = getGLFilter(); | 943 GLenum filter = getGLFilter(); |
943 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) | 944 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) |
944 return false; | 945 return false; |
945 m_lastImageId = image->uniqueID(); | 946 m_lastImageId = image->uniqueID(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 } | 1056 } |
1056 } | 1057 } |
1057 if (!m_isRegisteredTaskObserver) { | 1058 if (!m_isRegisteredTaskObserver) { |
1058 Platform::current()->currentThread()->addTaskObserver(this); | 1059 Platform::current()->currentThread()->addTaskObserver(this); |
1059 m_isRegisteredTaskObserver = true; | 1060 m_isRegisteredTaskObserver = true; |
1060 } | 1061 } |
1061 m_didDrawSinceLastFlush = true; | 1062 m_didDrawSinceLastFlush = true; |
1062 m_didDrawSinceLastGpuFlush = true; | 1063 m_didDrawSinceLastGpuFlush = true; |
1063 } | 1064 } |
1064 | 1065 |
1065 void Canvas2DLayerBridge::prepareSurfaceForPaintingIfNeeded() { | 1066 void Canvas2DLayerBridge::finalizeFrame() { |
| 1067 DCHECK(!m_destructionInProgress); |
| 1068 |
| 1069 // Make sure surface is ready for painting: fix the rendering mode now |
| 1070 // because it will be too late during the paint invalidation phase. |
1066 getOrCreateSurface(PreferAcceleration); | 1071 getOrCreateSurface(PreferAcceleration); |
1067 } | |
1068 | 1072 |
1069 void Canvas2DLayerBridge::finalizeFrame(const FloatRect& dirtyRect) { | |
1070 DCHECK(!m_destructionInProgress); | |
1071 if (m_layer && m_accelerationMode != DisableAcceleration) | |
1072 m_layer->layer()->invalidateRect(enclosingIntRect(dirtyRect)); | |
1073 if (m_rateLimiter) | 1073 if (m_rateLimiter) |
1074 m_rateLimiter->reset(); | 1074 m_rateLimiter->reset(); |
1075 m_renderingTaskCompletedForCurrentFrame = false; | 1075 m_renderingTaskCompletedForCurrentFrame = false; |
1076 } | 1076 } |
1077 | 1077 |
| 1078 void Canvas2DLayerBridge::doPaintInvalidation(const FloatRect& dirtyRect) { |
| 1079 DCHECK(!m_destructionInProgress); |
| 1080 if (m_layer && m_accelerationMode != DisableAcceleration) |
| 1081 m_layer->layer()->invalidateRect(enclosingIntRect(dirtyRect)); |
| 1082 } |
| 1083 |
1078 void Canvas2DLayerBridge::didProcessTask() { | 1084 void Canvas2DLayerBridge::didProcessTask() { |
1079 TRACE_EVENT0("cc", "Canvas2DLayerBridge::didProcessTask"); | 1085 TRACE_EVENT0("cc", "Canvas2DLayerBridge::didProcessTask"); |
1080 DCHECK(m_isRegisteredTaskObserver); | 1086 DCHECK(m_isRegisteredTaskObserver); |
1081 // If m_renderTaskProcessedForCurrentFrame is already set to true, | 1087 // If m_renderTaskProcessedForCurrentFrame is already set to true, |
1082 // it means that rendering tasks are not synchronized with the compositor | 1088 // it means that rendering tasks are not synchronized with the compositor |
1083 // (i.e. not using requestAnimationFrame), so we are at risk of posting | 1089 // (i.e. not using requestAnimationFrame), so we are at risk of posting |
1084 // a multi-frame backlog to the GPU | 1090 // a multi-frame backlog to the GPU |
1085 if (m_renderingTaskCompletedForCurrentFrame) { | 1091 if (m_renderingTaskCompletedForCurrentFrame) { |
1086 if (isAccelerated()) { | 1092 if (isAccelerated()) { |
1087 flushGpu(); | 1093 flushGpu(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 default; | 1155 default; |
1150 | 1156 |
1151 void Canvas2DLayerBridge::Logger::reportHibernationEvent( | 1157 void Canvas2DLayerBridge::Logger::reportHibernationEvent( |
1152 HibernationEvent event) { | 1158 HibernationEvent event) { |
1153 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, | 1159 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, |
1154 ("Canvas.HibernationEvents", HibernationEventCount)); | 1160 ("Canvas.HibernationEvents", HibernationEventCount)); |
1155 hibernationHistogram.count(event); | 1161 hibernationHistogram.count(event); |
1156 } | 1162 } |
1157 | 1163 |
1158 } // namespace blink | 1164 } // namespace blink |
OLD | NEW |