Reduce PassRefPtr in WebKit2 - 3
[WebKit-https.git] / Source / WebKit2 / Shared / CoordinatedGraphics / WebCoordinatedSurface.h
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 WebCoordinatedSurface_h
22 #define WebCoordinatedSurface_h
23
24 #if USE(COORDINATED_GRAPHICS)
25 #include "ShareableBitmap.h"
26 #include <WebCore/CoordinatedSurface.h>
27
28 #if USE(GRAPHICS_SURFACE)
29 #include "GraphicsSurface.h"
30 #endif
31
32 namespace WebCore {
33 class BitmapTexture;
34 class GraphicsContext;
35 }
36
37 namespace WebKit {
38
39 class WebCoordinatedSurface : public WebCore::CoordinatedSurface {
40 public:
41     class Handle {
42         WTF_MAKE_NONCOPYABLE(Handle);
43     public:
44         Handle();
45
46         void encode(IPC::ArgumentEncoder&) const;
47         static bool decode(IPC::ArgumentDecoder&, Handle&);
48
49 #if USE(GRAPHICS_SURFACE)
50         WebCore::GraphicsSurfaceToken graphicsSurfaceToken() const { return m_graphicsSurfaceToken; }
51 #endif
52
53     private:
54         friend class WebCoordinatedSurface;
55         mutable ShareableBitmap::Handle m_bitmapHandle;
56 #if USE(GRAPHICS_SURFACE)
57         WebCore::GraphicsSurfaceToken m_graphicsSurfaceToken;
58 #endif
59         WebCore::IntSize m_size;
60         WebCore::CoordinatedSurface::Flags m_flags;
61     };
62
63     // Create a new WebCoordinatedSurface, and allocate either a GraphicsSurface or a ShareableBitmap as backing.
64     static RefPtr<WebCoordinatedSurface> create(const WebCore::IntSize&, Flags);
65
66     // Create a shareable surface from a handle.
67     static RefPtr<WebCoordinatedSurface> create(const Handle&);
68
69     // Create a handle.
70     bool createHandle(Handle&);
71
72     virtual ~WebCoordinatedSurface();
73
74     virtual void paintToSurface(const WebCore::IntRect&, WebCore::CoordinatedSurface::Client*) override;
75
76 #if USE(TEXTURE_MAPPER)
77     virtual void copyToTexture(PassRefPtr<WebCore::BitmapTexture>, const WebCore::IntRect& target, const WebCore::IntPoint& sourceOffset) override;
78 #endif
79
80 private:
81     WebCoordinatedSurface(const WebCore::IntSize&, Flags, PassRefPtr<ShareableBitmap>);
82
83     // Create a WebCoordinatedSurface referencing an existing ShareableBitmap.
84     static Ref<WebCoordinatedSurface> create(const WebCore::IntSize&, Flags, PassRefPtr<ShareableBitmap>);
85
86     std::unique_ptr<WebCore::GraphicsContext> createGraphicsContext(const WebCore::IntRect&);
87 #if USE(GRAPHICS_SURFACE)
88     WebCoordinatedSurface(const WebCore::IntSize&, Flags, PassRefPtr<WebCore::GraphicsSurface>);
89     // Create a shareable bitmap backed by a graphics surface.
90     static RefPtr<WebCoordinatedSurface> createWithSurface(const WebCore::IntSize&, Flags);
91     // Create a WebCoordinatedSurface referencing an existing GraphicsSurface.
92     static Ref<WebCoordinatedSurface> create(const WebCore::IntSize&, Flags, PassRefPtr<WebCore::GraphicsSurface>);
93
94     bool isBackedByGraphicsSurface() const { return !!m_graphicsSurface; }
95 #endif
96
97     RefPtr<ShareableBitmap> m_bitmap;
98
99 #if USE(GRAPHICS_SURFACE)
100     RefPtr<WebCore::GraphicsSurface> m_graphicsSurface;
101 #endif
102 };
103
104 } // namespace WebKit
105
106 #endif // USE(COORDINATED_GRAPHICS)
107 #endif // WebCoordinatedSurface_h