up spin button is now shown
[framework/web/webkit-efl.git] / Source / WebKit / blackberry / WebKitSupport / BackingStoreCompositingSurface.cpp
1 /*
2  * Copyright (C) 2009, 2010, 2011, 2012 Research In Motion Limited. 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 Lesser 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #include "config.h"
20 #include "BackingStoreCompositingSurface.h"
21
22 #include "GraphicsContext.h"
23 #include "SurfacePool.h"
24
25 #if USE(ACCELERATED_COMPOSITING)
26
27 #include <BlackBerryPlatformGraphics.h>
28
29 namespace BlackBerry {
30 namespace WebKit {
31
32 CompositingSurfaceBuffer::CompositingSurfaceBuffer(const Platform::IntSize& size)
33     : m_size(size)
34     , m_buffer(0)
35 {
36 }
37
38 CompositingSurfaceBuffer::~CompositingSurfaceBuffer()
39 {
40     destroyBuffer(m_buffer);
41 }
42
43 Platform::IntSize CompositingSurfaceBuffer::surfaceSize() const
44 {
45     return m_size;
46 }
47
48 Platform::Graphics::Buffer* CompositingSurfaceBuffer::nativeBuffer() const
49 {
50     if (!m_buffer) {
51         m_buffer = createBuffer(m_size,
52                                 Platform::Graphics::TileBuffer,
53                                 Platform::Graphics::GLES2);
54     }
55     return m_buffer;
56 }
57
58 BackingStoreCompositingSurface::BackingStoreCompositingSurface(const Platform::IntSize& size, bool doubleBuffered)
59     : m_isDoubleBuffered(doubleBuffered)
60     , m_needsSync(true)
61 {
62     m_frontBuffer = new CompositingSurfaceBuffer(size);
63     m_backBuffer = !doubleBuffered ? 0 : new CompositingSurfaceBuffer(size);
64 }
65
66 BackingStoreCompositingSurface::~BackingStoreCompositingSurface()
67 {
68     delete m_frontBuffer;
69     m_frontBuffer = 0;
70
71     delete m_backBuffer;
72     m_backBuffer = 0;
73 }
74
75 CompositingSurfaceBuffer* BackingStoreCompositingSurface::frontBuffer() const
76 {
77     ASSERT(m_frontBuffer);
78     return m_frontBuffer;
79 }
80
81 CompositingSurfaceBuffer* BackingStoreCompositingSurface::backBuffer() const
82 {
83     if (!m_isDoubleBuffered)
84         return frontBuffer();
85
86     ASSERT(m_backBuffer);
87     return m_backBuffer;
88 }
89
90 void BackingStoreCompositingSurface::swapBuffers()
91 {
92     if (!m_isDoubleBuffered)
93         return;
94
95     // Store temps.
96     unsigned front = reinterpret_cast<unsigned>(frontBuffer());
97     unsigned back = reinterpret_cast<unsigned>(backBuffer());
98
99     // Atomic change.
100     _smp_xchg(reinterpret_cast<unsigned*>(&m_frontBuffer), back);
101     _smp_xchg(reinterpret_cast<unsigned*>(&m_backBuffer), front);
102 }
103
104 } // namespace WebKit
105 } // namespace BlackBerry
106 #endif // USE(ACCELERATED_COMPOSITING)