OSDN Git Service

Remove locks in BaseTile. Also fix the bug where the browser hangs when closing a...
[android-x86/external-webkit.git] / WebCore / platform / graphics / android / BaseTile.h
1 /*
2  * Copyright 2010, The Android Open Source Project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *  * Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef BaseTile_h
27 #define BaseTile_h
28
29 #if USE(ACCELERATED_COMPOSITING)
30
31 #include "HashMap.h"
32 #include "SkBitmap.h"
33 #include "SkCanvas.h"
34 #include "SkRect.h"
35
36 #include <EGL/egl.h>
37 #include <EGL/eglext.h>
38 #include <GLES2/gl2.h>
39
40 namespace WebCore {
41
42 class BackedDoubleBufferedTexture;
43 class TiledPage;
44
45 /**
46  * An individual tile that is used to construct part of a webpage's BaseLayer of
47  * content.  Each tile is assigned to a TiledPage and is responsible for drawing
48  * and displaying their section of the page.  The lifecycle of a tile is:
49  *
50  * 1. Each tile is created on the main GL thread and assigned to a specific
51  *    location within a TiledPage.
52  * 2. When needed the tile is passed to the background thread where it paints
53  *    the BaseLayer's most recent PictureSet to a bitmap which is then uploaded
54  *    to the GPU.
55  * 3. After the bitmap is uploaded to the GPU the main GL thread then uses the
56  *    tile's draw() function to display the tile to the screen.
57  * 4. Steps 2-3 are repeated as necessary.
58  * 5. The tile is destroyed when the user navigates to a new page.
59  *
60  */
61 class BaseTile {
62 public:
63 #ifdef DEBUG_COUNT
64     static int count();
65 #endif
66     BaseTile(TiledPage* page, int x, int y);
67     ~BaseTile();
68
69     void reserveTexture();
70     void removeTexture();
71     void setUsedLevel(int);
72     bool isBitmapReady();
73     void draw(float transparency, SkRect& rect);
74
75     // the only thread-safe function called by the background thread
76     void paintBitmap();
77
78     float scale() const { return m_scale; }
79     void setScale(float scale);
80
81     TiledPage* page() { return m_page; }
82     int x() const { return m_x; }
83     int y() const { return m_y; }
84     BackedDoubleBufferedTexture* texture() { return m_texture; }
85
86 private:
87     // these variables are only set when the object is constructed
88     TiledPage* m_page;
89     int m_x;
90     int m_y;
91
92     // these variables can be updated throughout the lifetime of the object
93     BackedDoubleBufferedTexture* m_texture;
94     float m_scale;
95 };
96
97 } // namespace WebCore
98
99 #endif // USE(ACCELERATED_COMPOSITING)
100 #endif // BaseTile_h