2
* Copyright (C) 2011, 2012 Research In Motion Limited. All rights reserved.
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.
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.
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
22
#if USE(ACCELERATED_COMPOSITING)
26
#include <wtf/PassRefPtr.h>
27
#include <wtf/RefCounted.h>
35
class TextureCacheCompositingThread;
37
// Texture encapsulates a volatile texture - at any time, the underlying OpenGL
38
// texture may be deleted by the TextureCacheCompositingThread. The user must
39
// check using Texture::isDirty() immediately before using it, every time.
40
// The only way to prevent eviction this is to call Texture::protect().
41
// If the texture isDirty(), you must updateContents() before you can use it.
42
class Texture : public RefCounted<Texture> {
44
static PassRefPtr<Texture> create(bool isColor = false)
46
return adoptRef(new Texture(isColor));
51
unsigned textureId() const { return m_textureId; }
53
bool isDirty() const { return !m_textureId; }
54
bool hasTexture() const { return m_textureId; }
56
bool isColor() const { return m_isColor; }
57
bool isOpaque() const { return m_isOpaque; }
59
bool isProtected() const { return m_protectionCount > 0; }
60
void protect() { ++m_protectionCount; }
61
void unprotect() { --m_protectionCount; }
62
bool protect(const IntSize&);
64
void updateContents(const SkBitmap& contents, const IntRect& dirtyRect, const IntRect& tile, bool isOpaque);
65
void setContentsToColor(const Color&);
67
IntSize size() const { return m_size; }
68
int width() const { return m_size.width(); }
69
int height() const { return m_size.height(); }
70
static int bytesPerPixel() { return 4; }
73
friend class TextureCacheCompositingThread;
75
Texture(bool isColor = false);
77
void setTextureId(unsigned id)
81
// We assume it is a newly allocated texture,
82
// and thus empty, or 0, which would of course
87
int m_protectionCount;
94
} // namespace WebCore
96
#endif // USE(ACCELERATED_COMPOSITING)