1bd605127c7d941b2d7ca78ae71597fd78b885c2
[platform/framework/web/webkit-efl.git] / Source / WebCore / platform / graphics / surfaces / wayland / PlatformTextureWayland.cpp
1 /*
2     Copyright (C) 2013 Intel Corporation. All rights reserved.
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 #include "config.h"
21
22 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && ENABLE(TIZEN_ACCELERATED_PLATFORM_LAYER)
23
24 #include "PlatformTextureWayland.h"
25
26 namespace WebCore {
27 PlatformTextureWayland::PlatformTextureWayland(int platformSurfaceID, const IntSize& size)
28     : m_buffer(0)
29     , m_platformSurfaceID(platformSurfaceID)
30     , m_textureSize(size)
31     , m_used(false)
32 {
33 }
34
35 PlatformTextureWayland::~PlatformTextureWayland()
36 {
37     if (m_buffer) {
38         m_buffer = 0;
39         WaylandDisplay* display = WaylandDisplay::instance();
40         if (display)
41             display->unMapBuffer(m_platformSurfaceID, this);
42     }
43 }
44
45 bool PlatformTextureWayland::initialize(bool useLinearFilter)
46 {
47     if (m_buffer)
48         return true;
49
50     if (!m_platformSurfaceID) {
51         LOG_ERROR("ID is invalid!");
52         return 0;
53     }
54
55     if (!m_buffer) {
56         WaylandDisplay* display = WaylandDisplay::instance();
57         if (!display) {
58             LOG_ERROR("WaylandDisplay not initialized");
59             return false;
60         }
61
62         m_buffer = display->mapBuffer(m_platformSurfaceID, this, useLinearFilter);
63         if (!m_buffer) {
64             LOG_ERROR("Failed to map buffer for the surface");
65             return 0;
66         }
67     }
68
69     return true;
70 }
71
72 uint32_t PlatformTextureWayland::id() const
73 {
74     return m_buffer ? m_buffer->textureId() :0;
75 }
76
77 void PlatformTextureWayland::bufferDestroyed()
78 {
79     m_buffer = 0;
80     m_platformSurfaceID = 0;
81 }
82
83 };
84 #endif