1/*
2 Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
3 Copyright (C) 2012 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#ifndef UpdateAtlas_h
22#define UpdateAtlas_h
23
24#include "AreaAllocator.h"
25#include "CoordinatedSurface.h"
26#include "IntSize.h"
27#include <wtf/PassRefPtr.h>
28#include <wtf/RefPtr.h>
29
30#if USE(COORDINATED_GRAPHICS)
31
32namespace WebCore {
33class GraphicsContext;
34class IntPoint;
35
36class UpdateAtlas {
37    WTF_MAKE_NONCOPYABLE(UpdateAtlas);
38public:
39    class Client {
40    public:
41        virtual void createUpdateAtlas(uint32_t /* id */, PassRefPtr<CoordinatedSurface>) = 0;
42        virtual void removeUpdateAtlas(uint32_t /* id */) = 0;
43    };
44
45    UpdateAtlas(Client*, int dimension, CoordinatedSurface::Flags);
46    ~UpdateAtlas();
47
48    inline IntSize size() const { return m_surface->size(); }
49
50    // Returns false if there is no available buffer.
51    bool paintOnAvailableBuffer(const IntSize&, uint32_t& atlasID, IntPoint& offset, CoordinatedSurface::Client*);
52    void didSwapBuffers();
53    bool supportsAlpha() const { return m_surface->supportsAlpha(); }
54
55    void addTimeInactive(double seconds)
56    {
57        ASSERT(!isInUse());
58        m_inactivityInSeconds += seconds;
59    }
60    bool isInactive() const
61    {
62        const double inactiveSecondsTolerance = 3;
63        return m_inactivityInSeconds > inactiveSecondsTolerance;
64    }
65    bool isInUse() const { return !!m_areaAllocator; }
66
67private:
68    void buildLayoutIfNeeded();
69
70private:
71    Client* m_client;
72    std::unique_ptr<GeneralAreaAllocator> m_areaAllocator;
73    RefPtr<CoordinatedSurface> m_surface;
74    double m_inactivityInSeconds;
75    uint32_t m_ID;
76};
77
78} // namespace WebCore
79#endif // USE(COORDINATED_GRAPHICS)
80#endif // UpdateAtlas_h
81