[chromium] Merge updates and idle updates into one pass
[WebKit-https.git] / Source / WebKit / chromium / tests / CCTiledLayerTestCommon.h
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
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  * 1.  Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  * 2.  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 APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #ifndef CCTiledLayerTestCommon_h
26 #define CCTiledLayerTestCommon_h
27
28 #include "IntRect.h"
29 #include "IntSize.h"
30 #include "LayerTextureUpdater.h"
31 #include "Region.h"
32 #include "TextureCopier.h"
33 #include "TextureUploader.h"
34 #include "TiledLayerChromium.h"
35 #include "cc/CCGraphicsContext.h"
36 #include "cc/CCPrioritizedTexture.h"
37 #include "cc/CCTextureUpdater.h"
38 #include "cc/CCTiledLayerImpl.h"
39
40 namespace WebKitTests {
41
42 class FakeTiledLayerChromium;
43
44 class FakeLayerTextureUpdater : public WebCore::LayerTextureUpdater {
45 public:
46     class Texture : public WebCore::LayerTextureUpdater::Texture {
47     public:
48         Texture(FakeLayerTextureUpdater*, PassOwnPtr<WebCore::CCPrioritizedTexture>);
49         virtual ~Texture();
50
51         virtual void updateRect(WebCore::CCGraphicsContext*, WebCore::TextureAllocator* , const WebCore::IntRect&, const WebCore::IntRect&) OVERRIDE;
52         virtual void prepareRect(const WebCore::IntRect&) OVERRIDE;
53
54     private:
55         FakeLayerTextureUpdater* m_layer;
56     };
57
58     FakeLayerTextureUpdater();
59     virtual ~FakeLayerTextureUpdater();
60
61     virtual PassOwnPtr<WebCore::LayerTextureUpdater::Texture> createTexture(WebCore::CCPrioritizedTextureManager*) OVERRIDE;
62     virtual SampledTexelFormat sampledTexelFormat(GC3Denum) OVERRIDE { return SampledTexelFormatRGBA; }
63
64     virtual void prepareToUpdate(const WebCore::IntRect& contentRect, const WebCore::IntSize&, float, float, WebCore::IntRect& resultingOpaqueRect) OVERRIDE;
65     // Sets the rect to invalidate during the next call to prepareToUpdate(). After the next
66     // call to prepareToUpdate() the rect is reset.
67     void setRectToInvalidate(const WebCore::IntRect&, FakeTiledLayerChromium*);
68     // Last rect passed to prepareToUpdate().
69     const WebCore::IntRect& lastUpdateRect()  const { return m_lastUpdateRect; }
70
71     // Number of times prepareToUpdate has been invoked.
72     int prepareCount() const { return m_prepareCount; }
73     void clearPrepareCount() { m_prepareCount = 0; }
74
75     // Number of times updateRect has been invoked.
76     int updateCount() const { return m_updateCount; }
77     void clearUpdateCount() { m_updateCount = 0; }
78     void updateRect() { m_updateCount++; }
79
80     // Number of times prepareRect() has been invoked on a texture.
81     int prepareRectCount() const { return m_prepareRectCount; }
82     void clearPrepareRectCount() { m_prepareRectCount = 0; }
83     void prepareRect() { m_prepareRectCount++; }
84
85     void setOpaquePaintRect(const WebCore::IntRect& opaquePaintRect) { m_opaquePaintRect = opaquePaintRect; }
86
87 private:
88     int m_prepareCount;
89     int m_updateCount;
90     int m_prepareRectCount;
91     WebCore::IntRect m_rectToInvalidate;
92     WebCore::IntRect m_lastUpdateRect;
93     WebCore::IntRect m_opaquePaintRect;
94     RefPtr<FakeTiledLayerChromium> m_layer;
95 };
96
97 class FakeCCTiledLayerImpl : public WebCore::CCTiledLayerImpl {
98 public:
99     explicit FakeCCTiledLayerImpl(int id);
100     virtual ~FakeCCTiledLayerImpl();
101
102     using WebCore::CCTiledLayerImpl::hasTileAt;
103     using WebCore::CCTiledLayerImpl::hasTextureIdForTileAt;
104 };
105
106 class FakeTiledLayerChromium : public WebCore::TiledLayerChromium {
107 public:
108     explicit FakeTiledLayerChromium(WebCore::CCPrioritizedTextureManager*);
109     virtual ~FakeTiledLayerChromium();
110
111     static WebCore::IntSize tileSize() { return WebCore::IntSize(100, 100); }
112
113     using WebCore::TiledLayerChromium::invalidateRect;
114     using WebCore::TiledLayerChromium::updateLayerRect;
115     using WebCore::TiledLayerChromium::needsIdlePaint;
116     using WebCore::TiledLayerChromium::skipsDraw;
117     using WebCore::TiledLayerChromium::numPaintedTiles;
118     using WebCore::TiledLayerChromium::idlePaintRect;
119
120     virtual void setNeedsDisplayRect(const WebCore::FloatRect&) OVERRIDE;
121     const WebCore::FloatRect& lastNeedsDisplayRect() const { return m_lastNeedsDisplayRect; }
122
123     // Updates the visibleLayerRect().
124     virtual void update(WebCore::CCTextureUpdater&, const WebCore::CCOcclusionTracker*) OVERRIDE;
125
126     virtual void setTexturePriorities(const WebCore::CCPriorityCalculator&) OVERRIDE;
127
128     virtual WebCore::CCPrioritizedTextureManager* textureManager() const OVERRIDE { return m_textureManager; }
129     FakeLayerTextureUpdater* fakeLayerTextureUpdater() { return m_fakeTextureUpdater.get(); }
130     WebCore::FloatRect updateRect() { return m_updateRect; }
131
132 protected:
133     virtual WebCore::LayerTextureUpdater* textureUpdater() const OVERRIDE { return m_fakeTextureUpdater.get(); }
134     virtual void createTextureUpdaterIfNeeded() OVERRIDE { }
135
136 private:
137     RefPtr<FakeLayerTextureUpdater> m_fakeTextureUpdater;
138     WebCore::CCPrioritizedTextureManager* m_textureManager;
139     WebCore::FloatRect m_lastNeedsDisplayRect;
140 };
141
142 class FakeTiledLayerWithScaledBounds : public FakeTiledLayerChromium {
143 public:
144     explicit FakeTiledLayerWithScaledBounds(WebCore::CCPrioritizedTextureManager*);
145
146     void setContentBounds(const WebCore::IntSize& contentBounds) { m_forcedContentBounds = contentBounds; }
147     virtual WebCore::IntSize contentBounds() const OVERRIDE { return m_forcedContentBounds; }
148
149 protected:
150     WebCore::IntSize m_forcedContentBounds;
151 };
152
153 class FakeTextureAllocator : public WebCore::TextureAllocator {
154 public:
155     virtual unsigned createTexture(const WebCore::IntSize&, GC3Denum) OVERRIDE { return 1; }
156     virtual void deleteTexture(unsigned, const WebCore::IntSize&, GC3Denum) OVERRIDE { }
157     virtual void deleteAllTextures() OVERRIDE { }
158 };
159
160 class FakeTextureCopier : public WebCore::TextureCopier {
161 public:
162     virtual void copyTexture(WebCore::CCGraphicsContext*, unsigned, unsigned, const WebCore::IntSize&) { }
163     virtual void copyToTexture(WebCore::CCGraphicsContext*, const void*, unsigned, const WebCore::IntSize&, GC3Denum) { }
164 };
165
166 class FakeTextureUploader : public WebCore::TextureUploader {
167 public:
168     virtual bool isBusy() { return false; }
169     virtual void beginUploads() { }
170     virtual void endUploads() { }
171     virtual void uploadTexture(WebCore::CCGraphicsContext* context, WebCore::LayerTextureUpdater::Texture* texture, WebCore::TextureAllocator* allocator, const WebCore::IntRect sourceRect, const WebCore::IntRect destRect) { texture->updateRect(context, allocator, sourceRect, destRect); }
172 };
173
174 }
175 #endif // CCTiledLayerTestCommon_h