OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CCProxy_h |
| 6 #define CCProxy_h |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include <public/WebCompositorOutputSurface.h> |
| 10 #include <wtf/PassOwnPtr.h> |
| 11 #include <wtf/PassRefPtr.h> |
| 12 |
| 13 namespace cc { |
| 14 |
| 15 class CCThread; |
| 16 class IntRect; |
| 17 class IntSize; |
| 18 struct CCRenderingStats; |
| 19 struct RendererCapabilities; |
| 20 |
| 21 // Abstract class responsible for proxying commands from the main-thread side of |
| 22 // the compositor over to the compositor implementation. |
| 23 class CCProxy { |
| 24 public: |
| 25 static void setMainThread(CCThread*); |
| 26 static CCThread* mainThread(); |
| 27 |
| 28 static bool hasImplThread(); |
| 29 static void setImplThread(CCThread*); |
| 30 static CCThread* implThread(); |
| 31 |
| 32 // Returns 0 if the current thread is neither the main thread nor the impl t
hread. |
| 33 static CCThread* currentThread(); |
| 34 |
| 35 virtual ~CCProxy(); |
| 36 |
| 37 virtual bool compositeAndReadback(void *pixels, const IntRect&) = 0; |
| 38 |
| 39 virtual void startPageScaleAnimation(const IntSize& targetPosition, bool use
Anchor, float scale, double durationSec) = 0; |
| 40 |
| 41 virtual void finishAllRendering() = 0; |
| 42 |
| 43 virtual bool isStarted() const = 0; |
| 44 |
| 45 // Attempts to initialize a context to use for rendering. Returns false if t
he context could not be created. |
| 46 // The context will not be used and no frames may be produced until initiali
zeRenderer() is called. |
| 47 virtual bool initializeContext() = 0; |
| 48 |
| 49 // Indicates that the compositing surface associated with our context is rea
dy to use. |
| 50 virtual void setSurfaceReady() = 0; |
| 51 |
| 52 virtual void setVisible(bool) = 0; |
| 53 |
| 54 // Attempts to initialize the layer renderer. Returns false if the context i
sn't usable for compositing. |
| 55 virtual bool initializeRenderer() = 0; |
| 56 |
| 57 // Attempts to recreate the context and layer renderer after a context lost.
Returns false if the renderer couldn't be |
| 58 // reinitialized. |
| 59 virtual bool recreateContext() = 0; |
| 60 |
| 61 virtual void renderingStats(CCRenderingStats*) = 0; |
| 62 |
| 63 virtual const RendererCapabilities& rendererCapabilities() const = 0; |
| 64 |
| 65 virtual void setNeedsAnimate() = 0; |
| 66 virtual void setNeedsCommit() = 0; |
| 67 virtual void setNeedsRedraw() = 0; |
| 68 |
| 69 virtual void didAddAnimation() = 0; |
| 70 |
| 71 virtual bool commitRequested() const = 0; |
| 72 |
| 73 virtual void start() = 0; // Must be called before using the proxy. |
| 74 virtual void stop() = 0; // Must be called before deleting the proxy. |
| 75 |
| 76 // Forces 3D commands on all contexts to wait for all previous SwapBuffers t
o finish before executing in the GPU |
| 77 // process. |
| 78 virtual void forceSerializeOnSwapBuffers() = 0; |
| 79 |
| 80 // Maximum number of sub-region texture updates supported for each commit. |
| 81 virtual size_t maxPartialTextureUpdates() const = 0; |
| 82 |
| 83 virtual void acquireLayerTextures() = 0; |
| 84 |
| 85 // Debug hooks |
| 86 #ifndef NDEBUG |
| 87 static bool isMainThread(); |
| 88 static bool isImplThread(); |
| 89 static bool isMainThreadBlocked(); |
| 90 static void setMainThreadBlocked(bool); |
| 91 #endif |
| 92 |
| 93 // Testing hooks |
| 94 virtual void loseContext() = 0; |
| 95 |
| 96 #ifndef NDEBUG |
| 97 static void setCurrentThreadIsImplThread(bool); |
| 98 #endif |
| 99 |
| 100 protected: |
| 101 CCProxy(); |
| 102 friend class DebugScopedSetImplThread; |
| 103 friend class DebugScopedSetMainThreadBlocked; |
| 104 |
| 105 private: |
| 106 DISALLOW_COPY_AND_ASSIGN(CCProxy); |
| 107 }; |
| 108 |
| 109 class DebugScopedSetMainThreadBlocked { |
| 110 public: |
| 111 DebugScopedSetMainThreadBlocked() |
| 112 { |
| 113 #if !ASSERT_DISABLED |
| 114 ASSERT(!CCProxy::isMainThreadBlocked()); |
| 115 CCProxy::setMainThreadBlocked(true); |
| 116 #endif |
| 117 } |
| 118 ~DebugScopedSetMainThreadBlocked() |
| 119 { |
| 120 #if !ASSERT_DISABLED |
| 121 ASSERT(CCProxy::isMainThreadBlocked()); |
| 122 CCProxy::setMainThreadBlocked(false); |
| 123 #endif |
| 124 } |
| 125 }; |
| 126 |
| 127 } |
| 128 |
| 129 #endif |
OLD | NEW |