1/*
2 Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18 */
19
20#pragma once
21
22#if USE(COORDINATED_GRAPHICS)
23
24#include "TextureMapper.h"
25#include "TextureMapperBackingStore.h"
26#include "TextureMapperTile.h"
27#include <wtf/HashMap.h>
28#include <wtf/HashSet.h>
29#include <wtf/RefCounted.h>
30#include <wtf/Vector.h>
31
32namespace Nicosia {
33class Buffer;
34}
35
36namespace WebCore {
37
38class CoordinatedBackingStoreTile : public TextureMapperTile {
39public:
40 explicit CoordinatedBackingStoreTile(float scale = 1)
41 : TextureMapperTile(FloatRect())
42 , m_scale(scale)
43 {
44 }
45
46 float scale() const { return m_scale; }
47
48 struct Update {
49 RefPtr<Nicosia::Buffer> buffer;
50 IntRect sourceRect;
51 IntRect tileRect;
52 IntPoint bufferOffset;
53 };
54 void addUpdate(Update&&);
55
56 void swapBuffers(TextureMapper&);
57
58private:
59 Vector<Update> m_updates;
60 float m_scale;
61};
62
63class CoordinatedBackingStore : public RefCounted<CoordinatedBackingStore>, public TextureMapperBackingStore {
64public:
65 void createTile(uint32_t tileID, float);
66 void removeTile(uint32_t tileID);
67 void removeAllTiles();
68 void updateTile(uint32_t tileID, const IntRect&, const IntRect&, RefPtr<Nicosia::Buffer>&&, const IntPoint&);
69 static Ref<CoordinatedBackingStore> create() { return adoptRef(*new CoordinatedBackingStore); }
70 void commitTileOperations(TextureMapper&);
71 void setSize(const FloatSize&);
72 void paintToTextureMapper(TextureMapper&, const FloatRect&, const TransformationMatrix&, float) override;
73 void drawBorder(TextureMapper&, const Color&, float borderWidth, const FloatRect&, const TransformationMatrix&) override;
74 void drawRepaintCounter(TextureMapper&, int repaintCount, const Color&, const FloatRect&, const TransformationMatrix&) override;
75
76private:
77 CoordinatedBackingStore()
78 : m_scale(1.)
79 { }
80 void paintTilesToTextureMapper(Vector<TextureMapperTile*>&, TextureMapper&, const TransformationMatrix&, float, const FloatRect&);
81 TransformationMatrix adjustedTransformForRect(const FloatRect&);
82 FloatRect rect() const { return FloatRect(FloatPoint::zero(), m_size); }
83
84 typedef HashMap<uint32_t, CoordinatedBackingStoreTile> CoordinatedBackingStoreTileMap;
85 CoordinatedBackingStoreTileMap m_tiles;
86 HashSet<uint32_t> m_tilesToRemove;
87 // FIXME: m_pendingSize should be removed after the following bug is fixed: https://bugs.webkit.org/show_bug.cgi?id=108294
88 FloatSize m_pendingSize;
89 FloatSize m_size;
90 float m_scale;
91};
92
93} // namespace WebKit
94
95#endif // USE(COORDINATED_GRAPHICS)
96