5de1c5fb3c41e67eea9c510d6c09e5c475757d6c
[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 "CCGraphicsContext.h"
29 #include "CCPrioritizedTexture.h"
30 #include "CCResourceProvider.h"
31 #include "CCTextureUpdateQueue.h"
32 #include "CCTiledLayerImpl.h"
33 #include "IntRect.h"
34 #include "IntSize.h"
35 #include "LayerTextureUpdater.h"
36 #include "Region.h"
37 #include "TextureCopier.h"
38 #include "TextureUploader.h"
39 #include "TiledLayerChromium.h"
40
41 namespace WebKitTests {
42
43 class FakeTiledLayerChromium;
44
45 class FakeLayerTextureUpdater : public WebCore::LayerTextureUpdater {
46 public:
47     class Texture : public WebCore::LayerTextureUpdater::Texture {
48     public:
49         Texture(FakeLayerTextureUpdater*, PassOwnPtr<WebCore::CCPrioritizedTexture>);
50         virtual ~Texture();
51
52         virtual void updateRect(WebCore::CCResourceProvider* , const WebCore::IntRect&, const WebCore::IntSize&) OVERRIDE;
53         virtual void prepareRect(const WebCore::IntRect&, WebCore::CCRenderingStats&) OVERRIDE;
54
55     private:
56         FakeLayerTextureUpdater* m_layer;
57     };
58
59     FakeLayerTextureUpdater();
60     virtual ~FakeLayerTextureUpdater();
61
62     virtual PassOwnPtr<WebCore::LayerTextureUpdater::Texture> createTexture(WebCore::CCPrioritizedTextureManager*) OVERRIDE;
63     virtual SampledTexelFormat sampledTexelFormat(GC3Denum) OVERRIDE { return SampledTexelFormatRGBA; }
64
65     virtual void prepareToUpdate(const WebCore::IntRect& contentRect, const WebCore::IntSize&, float, float, WebCore::IntRect& resultingOpaqueRect, WebCore::CCRenderingStats&) OVERRIDE;
66     // Sets the rect to invalidate during the next call to prepareToUpdate(). After the next
67     // call to prepareToUpdate() the rect is reset.
68     void setRectToInvalidate(const WebCore::IntRect&, FakeTiledLayerChromium*);
69     // Last rect passed to prepareToUpdate().
70     const WebCore::IntRect& lastUpdateRect()  const { return m_lastUpdateRect; }
71
72     // Number of times prepareToUpdate has been invoked.
73     int prepareCount() const { return m_prepareCount; }
74     void clearPrepareCount() { m_prepareCount = 0; }
75
76     // Number of times updateRect has been invoked.
77     int updateCount() const { return m_updateCount; }
78     void clearUpdateCount() { m_updateCount = 0; }
79     void updateRect() { m_updateCount++; }
80
81     // Number of times prepareRect() has been invoked on a texture.
82     int prepareRectCount() const { return m_prepareRectCount; }
83     void clearPrepareRectCount() { m_prepareRectCount = 0; }
84     void prepareRect() { m_prepareRectCount++; }
85
86     void setOpaquePaintRect(const WebCore::IntRect& opaquePaintRect) { m_opaquePaintRect = opaquePaintRect; }
87
88 private:
89     int m_prepareCount;
90     int m_updateCount;
91     int m_prepareRectCount;
92     WebCore::IntRect m_rectToInvalidate;
93     WebCore::IntRect m_lastUpdateRect;
94     WebCore::IntRect m_opaquePaintRect;
95     RefPtr<FakeTiledLayerChromium> m_layer;
96 };
97
98 class FakeCCTiledLayerImpl : public WebCore::CCTiledLayerImpl {
99 public:
100     explicit FakeCCTiledLayerImpl(int id);
101     virtual ~FakeCCTiledLayerImpl();
102
103     using WebCore::CCTiledLayerImpl::hasTileAt;
104     using WebCore::CCTiledLayerImpl::hasTextureIdForTileAt;
105 };
106
107 class FakeTiledLayerChromium : public WebCore::TiledLayerChromium {
108 public:
109     explicit FakeTiledLayerChromium(WebCore::CCPrioritizedTextureManager*);
110     virtual ~FakeTiledLayerChromium();
111
112     static WebCore::IntSize tileSize() { return WebCore::IntSize(100, 100); }
113
114     using WebCore::TiledLayerChromium::invalidateContentRect;
115     using WebCore::TiledLayerChromium::updateContentRect;
116     using WebCore::TiledLayerChromium::needsIdlePaint;
117     using WebCore::TiledLayerChromium::skipsDraw;
118     using WebCore::TiledLayerChromium::numPaintedTiles;
119     using WebCore::TiledLayerChromium::idlePaintRect;
120
121     virtual void setNeedsDisplayRect(const WebCore::FloatRect&) OVERRIDE;
122     const WebCore::FloatRect& lastNeedsDisplayRect() const { return m_lastNeedsDisplayRect; }
123
124     // Updates the visibleContentRect().
125     virtual void update(WebCore::CCTextureUpdateQueue&, const WebCore::CCOcclusionTracker*, WebCore::CCRenderingStats&) OVERRIDE;
126
127     virtual void setTexturePriorities(const WebCore::CCPriorityCalculator&) OVERRIDE;
128
129     virtual WebCore::CCPrioritizedTextureManager* textureManager() const OVERRIDE { return m_textureManager; }
130     FakeLayerTextureUpdater* fakeLayerTextureUpdater() { return m_fakeTextureUpdater.get(); }
131     WebCore::FloatRect updateRect() { return m_updateRect; }
132
133 protected:
134     virtual WebCore::LayerTextureUpdater* textureUpdater() const OVERRIDE { return m_fakeTextureUpdater.get(); }
135     virtual void createTextureUpdaterIfNeeded() OVERRIDE { }
136
137 private:
138     RefPtr<FakeLayerTextureUpdater> m_fakeTextureUpdater;
139     WebCore::CCPrioritizedTextureManager* m_textureManager;
140     WebCore::FloatRect m_lastNeedsDisplayRect;
141 };
142
143 class FakeTiledLayerWithScaledBounds : public FakeTiledLayerChromium {
144 public:
145     explicit FakeTiledLayerWithScaledBounds(WebCore::CCPrioritizedTextureManager*);
146
147     void setContentBounds(const WebCore::IntSize& contentBounds) { m_forcedContentBounds = contentBounds; }
148     virtual WebCore::IntSize contentBounds() const OVERRIDE { return m_forcedContentBounds; }
149
150 protected:
151     WebCore::IntSize m_forcedContentBounds;
152 };
153
154 class FakeTextureCopier : public WebCore::TextureCopier {
155 public:
156     virtual void copyTexture(Parameters) { }
157     virtual void flush() { }
158 };
159
160 class FakeTextureUploader : public WebCore::TextureUploader {
161 public:
162     virtual bool isBusy() { return false; }
163     virtual void beginUploads() { }
164     virtual void endUploads() { }
165     virtual void uploadTexture(WebCore::CCResourceProvider* resourceProvider, Parameters upload) { upload.texture->updateRect(resourceProvider, upload.sourceRect, upload.destOffset); }
166 };
167
168 }
169 #endif // CCTiledLayerTestCommon_h