OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/graphics/gpu/SharedContextRateLimiter.h" | 5 #include "platform/graphics/gpu/SharedContextRateLimiter.h" |
6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_interface.h" |
7 #include "platform/graphics/gpu/Extensions3DUtil.h" | 8 #include "platform/graphics/gpu/Extensions3DUtil.h" |
8 #include "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
9 #include "public/platform/WebGraphicsContext3D.h" | 10 #include "public/platform/WebGraphicsContext3D.h" |
10 #include "public/platform/WebGraphicsContext3DProvider.h" | 11 #include "public/platform/WebGraphicsContext3DProvider.h" |
11 | 12 |
12 #ifndef GL_COMMANDS_COMPLETED_CHROMIUM | 13 #ifndef GL_COMMANDS_COMPLETED_CHROMIUM |
13 #define GL_COMMANDS_COMPLETED_CHROMIUM 0x84F7 | 14 #define GL_COMMANDS_COMPLETED_CHROMIUM 0x84F7 |
14 #endif | 15 #endif |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
18 PassOwnPtr<SharedContextRateLimiter> SharedContextRateLimiter::create(unsigned m
axPendingTicks) | 19 PassOwnPtr<SharedContextRateLimiter> SharedContextRateLimiter::create(unsigned m
axPendingTicks) |
19 { | 20 { |
20 return adoptPtr(new SharedContextRateLimiter(maxPendingTicks)); | 21 return adoptPtr(new SharedContextRateLimiter(maxPendingTicks)); |
21 } | 22 } |
22 | 23 |
23 SharedContextRateLimiter::SharedContextRateLimiter(unsigned maxPendingTicks) | 24 SharedContextRateLimiter::SharedContextRateLimiter(unsigned maxPendingTicks) |
24 : m_maxPendingTicks(maxPendingTicks) | 25 : m_maxPendingTicks(maxPendingTicks) |
25 , m_canUseSyncQueries(false) | 26 , m_canUseSyncQueries(false) |
26 { | 27 { |
27 m_contextProvider = adoptPtr(Platform::current()->createSharedOffscreenGraph
icsContext3DProvider()); | 28 m_contextProvider = adoptPtr(Platform::current()->createSharedOffscreenGraph
icsContext3DProvider()); |
28 if (!m_contextProvider) | 29 if (!m_contextProvider) |
29 return; | 30 return; |
30 | 31 |
31 WebGraphicsContext3D* context = m_contextProvider->context3d(); | 32 gpu::gles2::GLES2Interface* gl = m_contextProvider->getGLInterface(); |
32 if (context && !context->isContextLost()) { | 33 if (gl && gl->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { |
33 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(conte
xt); | 34 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(m_con
textProvider->context3d(), gl); |
34 // TODO(junov): when the GLES 3.0 command buffer is ready, we could use
fenceSync instead | 35 // TODO(junov): when the GLES 3.0 command buffer is ready, we could use
fenceSync instead |
35 m_canUseSyncQueries = extensionsUtil->supportsExtension("GL_CHROMIUM_syn
c_query"); | 36 m_canUseSyncQueries = extensionsUtil->supportsExtension("GL_CHROMIUM_syn
c_query"); |
36 } | 37 } |
37 } | 38 } |
38 | 39 |
39 void SharedContextRateLimiter::tick() | 40 void SharedContextRateLimiter::tick() |
40 { | 41 { |
41 if (!m_contextProvider) | 42 if (!m_contextProvider) |
42 return; | 43 return; |
43 | 44 |
44 WebGraphicsContext3D* context = m_contextProvider->context3d(); | 45 gpu::gles2::GLES2Interface* gl = m_contextProvider->getGLInterface(); |
45 | 46 |
46 if (!context || context->isContextLost()) | 47 if (!gl || gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR) |
47 return; | 48 return; |
48 | 49 |
| 50 WebGraphicsContext3D* context = m_contextProvider->context3d(); |
49 m_queries.append(m_canUseSyncQueries ? context->createQueryEXT() : 0); | 51 m_queries.append(m_canUseSyncQueries ? context->createQueryEXT() : 0); |
50 if (m_canUseSyncQueries) { | 52 if (m_canUseSyncQueries) { |
51 context->beginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, m_queries.last())
; | 53 context->beginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, m_queries.last())
; |
52 context->endQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 54 context->endQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
53 } | 55 } |
54 if (m_queries.size() > m_maxPendingTicks) { | 56 if (m_queries.size() > m_maxPendingTicks) { |
55 if (m_canUseSyncQueries) { | 57 if (m_canUseSyncQueries) { |
56 WGC3Duint result; | 58 WGC3Duint result; |
57 context->getQueryObjectuivEXT(m_queries.first(), GL_QUERY_RESULT_EXT
, &result); | 59 context->getQueryObjectuivEXT(m_queries.first(), GL_QUERY_RESULT_EXT
, &result); |
58 context->deleteQueryEXT(m_queries.first()); | 60 context->deleteQueryEXT(m_queries.first()); |
59 m_queries.removeFirst(); | 61 m_queries.removeFirst(); |
60 } else { | 62 } else { |
61 context->finish(); | 63 context->finish(); |
62 reset(); | 64 reset(); |
63 } | 65 } |
64 } | 66 } |
65 } | 67 } |
66 | 68 |
67 void SharedContextRateLimiter::reset() | 69 void SharedContextRateLimiter::reset() |
68 { | 70 { |
69 if (!m_contextProvider) | 71 if (!m_contextProvider) |
70 return; | 72 return; |
71 | 73 |
72 WebGraphicsContext3D* context = m_contextProvider->context3d(); | 74 gpu::gles2::GLES2Interface* gl = m_contextProvider->getGLInterface(); |
73 if (context && !context->isContextLost()) { | 75 if (gl && gl->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { |
| 76 WebGraphicsContext3D* context = m_contextProvider->context3d(); |
74 while (m_queries.size() > 0) { | 77 while (m_queries.size() > 0) { |
75 context->deleteQueryEXT(m_queries.first()); | 78 context->deleteQueryEXT(m_queries.first()); |
76 m_queries.removeFirst(); | 79 m_queries.removeFirst(); |
77 } | 80 } |
78 } else { | 81 } else { |
79 m_queries.clear(); | 82 m_queries.clear(); |
80 } | 83 } |
81 } | 84 } |
82 | 85 |
83 } // namespace blink | 86 } // namespace blink |
OLD | NEW |