~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/graphics/blackberry/Texture.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 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
#ifndef Texture_h
 
20
#define Texture_h
 
21
 
 
22
#if USE(ACCELERATED_COMPOSITING)
 
23
 
 
24
#include "IntSize.h"
 
25
 
 
26
#include <wtf/PassRefPtr.h>
 
27
#include <wtf/RefCounted.h>
 
28
 
 
29
class SkBitmap;
 
30
 
 
31
namespace WebCore {
 
32
 
 
33
class Color;
 
34
class IntRect;
 
35
class TextureCacheCompositingThread;
 
36
 
 
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> {
 
43
public:
 
44
    static PassRefPtr<Texture> create(bool isColor = false)
 
45
    {
 
46
        return adoptRef(new Texture(isColor));
 
47
    }
 
48
 
 
49
    ~Texture();
 
50
 
 
51
    unsigned textureId() const { return m_textureId; }
 
52
 
 
53
    bool isDirty() const { return !m_textureId; }
 
54
    bool hasTexture() const { return m_textureId; }
 
55
 
 
56
    bool isColor() const { return m_isColor; }
 
57
    bool isOpaque() const { return m_isOpaque; }
 
58
 
 
59
    bool isProtected() const { return m_protectionCount > 0; }
 
60
    void protect() { ++m_protectionCount; }
 
61
    void unprotect() { --m_protectionCount; }
 
62
    bool protect(const IntSize&);
 
63
 
 
64
    void updateContents(const SkBitmap& contents, const IntRect& dirtyRect, const IntRect& tile, bool isOpaque);
 
65
    void setContentsToColor(const Color&);
 
66
 
 
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; }
 
71
 
 
72
private:
 
73
    friend class TextureCacheCompositingThread;
 
74
 
 
75
    Texture(bool isColor = false);
 
76
 
 
77
    void setTextureId(unsigned id)
 
78
    {
 
79
        m_textureId = id;
 
80
 
 
81
        // We assume it is a newly allocated texture,
 
82
        // and thus empty, or 0, which would of course
 
83
        // be empty.
 
84
        m_size = IntSize();
 
85
    }
 
86
 
 
87
    int m_protectionCount;
 
88
    unsigned m_textureId;
 
89
    IntSize m_size;
 
90
    bool m_isColor;
 
91
    bool m_isOpaque;
 
92
};
 
93
 
 
94
} // namespace WebCore
 
95
 
 
96
#endif // USE(ACCELERATED_COMPOSITING)
 
97
 
 
98
#endif // Texture_h