| 1 | /* |
| 2 | Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) |
| 3 | Copyright (C) 2013 Company 100, Inc. |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Library General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Library General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Library General Public License |
| 16 | along with this library; see the file COPYING.LIB. If not, write to |
| 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #pragma once |
| 22 | |
| 23 | #if USE(COORDINATED_GRAPHICS) |
| 24 | |
| 25 | #include <WebCore/CoordinatedGraphicsState.h> |
| 26 | #include <WebCore/GraphicsContext.h> |
| 27 | #include <WebCore/GraphicsLayer.h> |
| 28 | #include <WebCore/IntRect.h> |
| 29 | #include <WebCore/IntSize.h> |
| 30 | #include <WebCore/NicosiaPlatformLayer.h> |
| 31 | #include <WebCore/TextureMapper.h> |
| 32 | #include <WebCore/TextureMapperBackingStore.h> |
| 33 | #include <WebCore/TextureMapperFPSCounter.h> |
| 34 | #include <WebCore/TextureMapperLayer.h> |
| 35 | #include <WebCore/TextureMapperPlatformLayerProxy.h> |
| 36 | #include <WebCore/Timer.h> |
| 37 | #include <wtf/Function.h> |
| 38 | #include <wtf/HashSet.h> |
| 39 | #include <wtf/Lock.h> |
| 40 | #include <wtf/RunLoop.h> |
| 41 | #include <wtf/ThreadingPrimitives.h> |
| 42 | #include <wtf/Vector.h> |
| 43 | |
| 44 | namespace Nicosia { |
| 45 | class Buffer; |
| 46 | } |
| 47 | |
| 48 | namespace WebCore { |
| 49 | class CoordinatedBackingStore; |
| 50 | class TextureMapperGL; |
| 51 | } |
| 52 | |
| 53 | namespace WebKit { |
| 54 | |
| 55 | class CoordinatedGraphicsSceneClient { |
| 56 | public: |
| 57 | virtual ~CoordinatedGraphicsSceneClient() { } |
| 58 | virtual void updateViewport() = 0; |
| 59 | }; |
| 60 | |
| 61 | class CoordinatedGraphicsScene : public ThreadSafeRefCounted<CoordinatedGraphicsScene>, public WebCore::TextureMapperPlatformLayerProxy::Compositor { |
| 62 | public: |
| 63 | explicit CoordinatedGraphicsScene(CoordinatedGraphicsSceneClient*); |
| 64 | virtual ~CoordinatedGraphicsScene(); |
| 65 | |
| 66 | void applyStateChanges(const Vector<WebCore::CoordinatedGraphicsState>&); |
| 67 | void paintToCurrentGLContext(const WebCore::TransformationMatrix&, const WebCore::FloatRect&, WebCore::TextureMapper::PaintFlags = 0); |
| 68 | void detach(); |
| 69 | |
| 70 | // The painting thread must lock the main thread to use below two methods, because two methods access members that the main thread manages. See m_client. |
| 71 | // Currently, QQuickWebPage::updatePaintNode() locks the main thread before calling both methods. |
| 72 | void purgeGLResources(); |
| 73 | |
| 74 | bool isActive() const { return m_isActive; } |
| 75 | void setActive(bool active) { m_isActive = active; } |
| 76 | |
| 77 | private: |
| 78 | void commitSceneState(const WebCore::CoordinatedGraphicsState::NicosiaState&); |
| 79 | void updateSceneState(); |
| 80 | |
| 81 | WebCore::TextureMapperLayer* rootLayer() { return m_rootLayer.get(); } |
| 82 | |
| 83 | void updateViewport(); |
| 84 | |
| 85 | void ensureRootLayer(); |
| 86 | |
| 87 | void onNewBufferAvailable() override; |
| 88 | |
| 89 | struct { |
| 90 | RefPtr<Nicosia::Scene> scene; |
| 91 | Nicosia::Scene::State state; |
| 92 | } m_nicosia; |
| 93 | |
| 94 | std::unique_ptr<WebCore::TextureMapper> m_textureMapper; |
| 95 | |
| 96 | // Below two members are accessed by only the main thread. The painting thread must lock the main thread to access both members. |
| 97 | CoordinatedGraphicsSceneClient* m_client; |
| 98 | bool m_isActive { false }; |
| 99 | |
| 100 | std::unique_ptr<WebCore::TextureMapperLayer> m_rootLayer; |
| 101 | |
| 102 | Nicosia::PlatformLayer::LayerID m_rootLayerID { 0 }; |
| 103 | |
| 104 | WebCore::TextureMapperFPSCounter m_fpsCounter; |
| 105 | }; |
| 106 | |
| 107 | } // namespace WebKit |
| 108 | |
| 109 | #endif // USE(COORDINATED_GRAPHICS) |
| 110 | |
| 111 | |
| 112 | |