1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "base/basictypes.h"
9 #include <public/WebCompositorOutputSurface.h>
16 struct CCRenderingStats
;
17 struct RendererCapabilities
;
19 // Abstract class responsible for proxying commands from the main-thread side of
20 // the compositor over to the compositor implementation.
23 static void setMainThread(CCThread
*);
24 static CCThread
* mainThread();
26 static bool hasImplThread();
27 static void setImplThread(CCThread
*);
28 static CCThread
* implThread();
30 // Returns 0 if the current thread is neither the main thread nor the impl thread.
31 static CCThread
* currentThread();
35 virtual bool compositeAndReadback(void *pixels
, const IntRect
&) = 0;
37 virtual void startPageScaleAnimation(const IntSize
& targetPosition
, bool useAnchor
, float scale
, double durationSec
) = 0;
39 virtual void finishAllRendering() = 0;
41 virtual bool isStarted() const = 0;
43 // Attempts to initialize a context to use for rendering. Returns false if the context could not be created.
44 // The context will not be used and no frames may be produced until initializeRenderer() is called.
45 virtual bool initializeContext() = 0;
47 // Indicates that the compositing surface associated with our context is ready to use.
48 virtual void setSurfaceReady() = 0;
50 virtual void setVisible(bool) = 0;
52 // Attempts to initialize the layer renderer. Returns false if the context isn't usable for compositing.
53 virtual bool initializeRenderer() = 0;
55 // Attempts to recreate the context and layer renderer after a context lost. Returns false if the renderer couldn't be
57 virtual bool recreateContext() = 0;
59 virtual void renderingStats(CCRenderingStats
*) = 0;
61 virtual const RendererCapabilities
& rendererCapabilities() const = 0;
63 virtual void setNeedsAnimate() = 0;
64 virtual void setNeedsCommit() = 0;
65 virtual void setNeedsRedraw() = 0;
67 virtual void didAddAnimation() = 0;
69 virtual bool commitRequested() const = 0;
71 virtual void start() = 0; // Must be called before using the proxy.
72 virtual void stop() = 0; // Must be called before deleting the proxy.
74 // Forces 3D commands on all contexts to wait for all previous SwapBuffers to finish before executing in the GPU
76 virtual void forceSerializeOnSwapBuffers() = 0;
78 // Maximum number of sub-region texture updates supported for each commit.
79 virtual size_t maxPartialTextureUpdates() const = 0;
81 virtual void acquireLayerTextures() = 0;
85 static bool isMainThread();
86 static bool isImplThread();
87 static bool isMainThreadBlocked();
88 static void setMainThreadBlocked(bool);
92 virtual void loseContext() = 0;
95 static void setCurrentThreadIsImplThread(bool);
100 friend class DebugScopedSetImplThread
;
101 friend class DebugScopedSetMainThreadBlocked
;
104 DISALLOW_COPY_AND_ASSIGN(CCProxy
);
107 class DebugScopedSetMainThreadBlocked
{
109 DebugScopedSetMainThreadBlocked()
112 ASSERT(!CCProxy::isMainThreadBlocked());
113 CCProxy::setMainThreadBlocked(true);
116 ~DebugScopedSetMainThreadBlocked()
119 ASSERT(CCProxy::isMainThreadBlocked());
120 CCProxy::setMainThreadBlocked(false);