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 CoordinatedSurface_h
22#define CoordinatedSurface_h
23
24#if USE(COORDINATED_GRAPHICS)
25#include "IntRect.h"
26#include <wtf/PassRefPtr.h>
27#include <wtf/ThreadSafeRefCounted.h>
28
29namespace WebCore {
30class BitmapTexture;
31class GraphicsContext;
32
33class CoordinatedSurface : public ThreadSafeRefCounted<CoordinatedSurface> {
34public:
35    enum Flag {
36        NoFlags = 0,
37        SupportsAlpha = 1 << 0,
38    };
39    typedef unsigned Flags;
40
41    class Client {
42    public:
43        virtual ~Client() { }
44        virtual void paintToSurfaceContext(GraphicsContext*) = 0;
45    };
46
47    typedef PassRefPtr<CoordinatedSurface> Factory(const IntSize&, Flags);
48    static void setFactory(Factory);
49    static PassRefPtr<CoordinatedSurface> create(const IntSize&, Flags);
50
51    virtual ~CoordinatedSurface() { }
52
53    bool supportsAlpha() const { return flags() & SupportsAlpha; }
54    IntSize size() const { return m_size; }
55
56    virtual void paintToSurface(const IntRect&, Client*) = 0;
57
58#if USE(TEXTURE_MAPPER)
59    virtual void copyToTexture(PassRefPtr<BitmapTexture>, const IntRect& target, const IntPoint& sourceOffset) = 0;
60#endif
61
62protected:
63    CoordinatedSurface(const IntSize&, Flags);
64    Flags flags() const { return m_flags; }
65
66    IntSize m_size;
67    Flags m_flags;
68
69private:
70    static CoordinatedSurface::Factory* s_factory;
71};
72
73} // namespace WebCore
74
75#endif // USE(COORDINATED_GRAPHICS)
76#endif // CoordinatedSurface_h
77