| 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 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 if (m_imageBuffer) | 846 if (m_imageBuffer) |
| 847 m_imageBuffer->notifySurfaceInvalid(); | 847 m_imageBuffer->notifySurfaceInvalid(); |
| 848 CanvasMetrics::countCanvasContextUsage( | 848 CanvasMetrics::countCanvasContextUsage( |
| 849 CanvasMetrics::Accelerated2DCanvasGPUContextLost); | 849 CanvasMetrics::Accelerated2DCanvasGPUContextLost); |
| 850 } | 850 } |
| 851 return m_surface.get(); | 851 return m_surface.get(); |
| 852 } | 852 } |
| 853 | 853 |
| 854 bool Canvas2DLayerBridge::restoreSurface() { | 854 bool Canvas2DLayerBridge::restoreSurface() { |
| 855 DCHECK(!m_destructionInProgress); | 855 DCHECK(!m_destructionInProgress); |
| 856 if (m_destructionInProgress) | 856 if (m_destructionInProgress || !isAccelerated()) |
| 857 return false; | 857 return false; |
| 858 DCHECK(isAccelerated() && !m_surface); | 858 DCHECK(!m_surface); |
| 859 | 859 |
| 860 gpu::gles2::GLES2Interface* sharedGL = nullptr; | 860 gpu::gles2::GLES2Interface* sharedGL = nullptr; |
| 861 m_layer->clearTexture(); | 861 m_layer->clearTexture(); |
| 862 m_contextProvider = WTF::wrapUnique( | 862 m_contextProvider = WTF::wrapUnique( |
| 863 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); | 863 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); |
| 864 if (m_contextProvider) | 864 if (m_contextProvider) |
| 865 sharedGL = m_contextProvider->contextGL(); | 865 sharedGL = m_contextProvider->contextGL(); |
| 866 | 866 |
| 867 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { | 867 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { |
| 868 GrContext* grCtx = m_contextProvider->grContext(); | 868 GrContext* grCtx = m_contextProvider->grContext(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 892 cc::TextureMailbox* outMailbox, | 892 cc::TextureMailbox* outMailbox, |
| 893 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) { | 893 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) { |
| 894 if (m_destructionInProgress) { | 894 if (m_destructionInProgress) { |
| 895 // It can be hit in the following sequence. | 895 // It can be hit in the following sequence. |
| 896 // 1. Canvas draws something. | 896 // 1. Canvas draws something. |
| 897 // 2. The compositor begins the frame. | 897 // 2. The compositor begins the frame. |
| 898 // 3. Javascript makes a context be lost. | 898 // 3. Javascript makes a context be lost. |
| 899 // 4. Here. | 899 // 4. Here. |
| 900 return false; | 900 return false; |
| 901 } | 901 } |
| 902 DCHECK(isAccelerated() || isHibernating() || m_softwareRenderingWhileHidden); | |
| 903 | |
| 904 // if hibernating but not hidden, we want to wake up from | |
| 905 // hibernation | |
| 906 if ((isHibernating() || m_softwareRenderingWhileHidden) && isHidden()) | |
| 907 return false; | |
| 908 | 902 |
| 909 // If the context is lost, we don't know if we should be producing GPU or | 903 // If the context is lost, we don't know if we should be producing GPU or |
| 910 // software frames, until we get a new context, since the compositor will | 904 // software frames, until we get a new context, since the compositor will |
| 911 // be trying to get a new context and may change modes. | 905 // be trying to get a new context and may change modes. |
| 912 if (!m_contextProvider || | 906 if (!m_contextProvider || |
| 913 m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != | 907 m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != |
| 914 GL_NO_ERROR) | 908 GL_NO_ERROR) |
| 915 return false; | 909 return false; |
| 916 | 910 |
| 911 DCHECK(isAccelerated() || isHibernating() || m_softwareRenderingWhileHidden); |
| 912 |
| 913 // if hibernating but not hidden, we want to wake up from |
| 914 // hibernation |
| 915 if ((isHibernating() || m_softwareRenderingWhileHidden) && isHidden()) |
| 916 return false; |
| 917 |
| 917 sk_sp<SkImage> image = | 918 sk_sp<SkImage> image = |
| 918 newImageSnapshot(PreferAcceleration, SnapshotReasonUnknown); | 919 newImageSnapshot(PreferAcceleration, SnapshotReasonUnknown); |
| 919 if (!image || !image->getTexture()) | 920 if (!image || !image->getTexture()) |
| 920 return false; | 921 return false; |
| 921 | 922 |
| 922 // Early exit if canvas was not drawn to since last prepareMailbox. | 923 // Early exit if canvas was not drawn to since last prepareMailbox. |
| 923 GLenum filter = getGLFilter(); | 924 GLenum filter = getGLFilter(); |
| 924 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) | 925 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) |
| 925 return false; | 926 return false; |
| 926 m_lastImageId = image->uniqueID(); | 927 m_lastImageId = image->uniqueID(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 } | 1036 } |
| 1036 } | 1037 } |
| 1037 if (!m_isRegisteredTaskObserver) { | 1038 if (!m_isRegisteredTaskObserver) { |
| 1038 Platform::current()->currentThread()->addTaskObserver(this); | 1039 Platform::current()->currentThread()->addTaskObserver(this); |
| 1039 m_isRegisteredTaskObserver = true; | 1040 m_isRegisteredTaskObserver = true; |
| 1040 } | 1041 } |
| 1041 m_didDrawSinceLastFlush = true; | 1042 m_didDrawSinceLastFlush = true; |
| 1042 m_didDrawSinceLastGpuFlush = true; | 1043 m_didDrawSinceLastGpuFlush = true; |
| 1043 } | 1044 } |
| 1044 | 1045 |
| 1045 void Canvas2DLayerBridge::prepareSurfaceForPaintingIfNeeded() { | 1046 void Canvas2DLayerBridge::finalizeFrame() { |
| 1047 DCHECK(!m_destructionInProgress); |
| 1048 |
| 1049 // Make sure surface is ready for painting: fix the rendering mode now |
| 1050 // because it will be too late during the paint invalidation phase. |
| 1046 getOrCreateSurface(PreferAcceleration); | 1051 getOrCreateSurface(PreferAcceleration); |
| 1047 } | |
| 1048 | 1052 |
| 1049 void Canvas2DLayerBridge::finalizeFrame(const FloatRect& dirtyRect) { | |
| 1050 DCHECK(!m_destructionInProgress); | |
| 1051 if (m_layer && m_accelerationMode != DisableAcceleration) | |
| 1052 m_layer->layer()->invalidateRect(enclosingIntRect(dirtyRect)); | |
| 1053 if (m_rateLimiter) | 1053 if (m_rateLimiter) |
| 1054 m_rateLimiter->reset(); | 1054 m_rateLimiter->reset(); |
| 1055 m_renderingTaskCompletedForCurrentFrame = false; | 1055 m_renderingTaskCompletedForCurrentFrame = false; |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 void Canvas2DLayerBridge::doPaintInvalidation(const FloatRect& dirtyRect) { |
| 1059 DCHECK(!m_destructionInProgress); |
| 1060 if (m_layer && m_accelerationMode != DisableAcceleration) |
| 1061 m_layer->layer()->invalidateRect(enclosingIntRect(dirtyRect)); |
| 1062 } |
| 1063 |
| 1058 void Canvas2DLayerBridge::didProcessTask() { | 1064 void Canvas2DLayerBridge::didProcessTask() { |
| 1059 TRACE_EVENT0("cc", "Canvas2DLayerBridge::didProcessTask"); | 1065 TRACE_EVENT0("cc", "Canvas2DLayerBridge::didProcessTask"); |
| 1060 DCHECK(m_isRegisteredTaskObserver); | 1066 DCHECK(m_isRegisteredTaskObserver); |
| 1061 // If m_renderTaskProcessedForCurrentFrame is already set to true, | 1067 // If m_renderTaskProcessedForCurrentFrame is already set to true, |
| 1062 // it means that rendering tasks are not synchronized with the compositor | 1068 // it means that rendering tasks are not synchronized with the compositor |
| 1063 // (i.e. not using requestAnimationFrame), so we are at risk of posting | 1069 // (i.e. not using requestAnimationFrame), so we are at risk of posting |
| 1064 // a multi-frame backlog to the GPU | 1070 // a multi-frame backlog to the GPU |
| 1065 if (m_renderingTaskCompletedForCurrentFrame) { | 1071 if (m_renderingTaskCompletedForCurrentFrame) { |
| 1066 if (isAccelerated()) { | 1072 if (isAccelerated()) { |
| 1067 flushGpu(); | 1073 flushGpu(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 default; | 1135 default; |
| 1130 | 1136 |
| 1131 void Canvas2DLayerBridge::Logger::reportHibernationEvent( | 1137 void Canvas2DLayerBridge::Logger::reportHibernationEvent( |
| 1132 HibernationEvent event) { | 1138 HibernationEvent event) { |
| 1133 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, | 1139 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, |
| 1134 ("Canvas.HibernationEvents", HibernationEventCount)); | 1140 ("Canvas.HibernationEvents", HibernationEventCount)); |
| 1135 hibernationHistogram.count(event); | 1141 hibernationHistogram.count(event); |
| 1136 } | 1142 } |
| 1137 | 1143 |
| 1138 } // namespace blink | 1144 } // namespace blink |
| OLD | NEW |