Home | History | Annotate | Download | only in trees
      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.
      4 
      5 #ifndef CC_TREES_PROXY_H_
      6 #define CC_TREES_PROXY_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/logging.h"
     12 #include "base/memory/ref_counted.h"
     13 #include "base/memory/scoped_ptr.h"
     14 #include "base/time/time.h"
     15 #include "base/values.h"
     16 #include "cc/base/cc_export.h"
     17 
     18 namespace base { class SingleThreadTaskRunner; }
     19 
     20 namespace gfx {
     21 class Rect;
     22 class Vector2d;
     23 }
     24 
     25 namespace cc {
     26 
     27 class OutputSurface;
     28 struct RendererCapabilities;
     29 
     30 // Abstract class responsible for proxying commands from the main-thread side of
     31 // the compositor over to the compositor implementation.
     32 class CC_EXPORT Proxy {
     33  public:
     34   base::SingleThreadTaskRunner* MainThreadTaskRunner() const;
     35   bool HasImplThread() const;
     36   base::SingleThreadTaskRunner* ImplThreadTaskRunner() const;
     37 
     38   // Debug hooks.
     39   bool IsMainThread() const;
     40   bool IsImplThread() const;
     41   bool IsMainThreadBlocked() const;
     42 #ifndef NDEBUG
     43   void SetMainThreadBlocked(bool is_main_thread_blocked);
     44   void SetCurrentThreadIsImplThread(bool is_impl_thread);
     45 #endif
     46 
     47   virtual ~Proxy();
     48 
     49   virtual bool CompositeAndReadback(void* pixels, gfx::Rect rect) = 0;
     50 
     51   virtual void FinishAllRendering() = 0;
     52 
     53   virtual bool IsStarted() const = 0;
     54 
     55   // Indicates that the compositing surface associated with our context is
     56   // ready to use.
     57   virtual void SetLayerTreeHostClientReady() = 0;
     58 
     59   virtual void SetVisible(bool visible) = 0;
     60 
     61   // Attempts to recreate the context and renderer synchronously after the
     62   // output surface is lost. Calls
     63   // LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted with the result.
     64   virtual void CreateAndInitializeOutputSurface() = 0;
     65 
     66   virtual const RendererCapabilities& GetRendererCapabilities() const = 0;
     67 
     68   virtual void SetNeedsAnimate() = 0;
     69   virtual void SetNeedsUpdateLayers() = 0;
     70   virtual void SetNeedsCommit() = 0;
     71   virtual void SetNeedsRedraw(gfx::Rect damage_rect) = 0;
     72 
     73   virtual void NotifyInputThrottledUntilCommit() = 0;
     74 
     75   // Defers commits until it is reset. It is only supported when in threaded
     76   // mode. It's an error to make a sync call like CompositeAndReadback while
     77   // commits are deferred.
     78   virtual void SetDeferCommits(bool defer_commits) = 0;
     79 
     80   virtual void MainThreadHasStoppedFlinging() = 0;
     81 
     82   virtual bool CommitRequested() const = 0;
     83 
     84   // Must be called before using the proxy.
     85   virtual void Start(scoped_ptr<OutputSurface> first_output_surface) = 0;
     86   virtual void Stop() = 0;   // Must be called before deleting the proxy.
     87 
     88   // Forces 3D commands on all contexts to wait for all previous SwapBuffers
     89   // to finish before executing in the GPU process.
     90   virtual void ForceSerializeOnSwapBuffers() = 0;
     91 
     92   // Maximum number of sub-region texture updates supported for each commit.
     93   virtual size_t MaxPartialTextureUpdates() const = 0;
     94 
     95   virtual void AcquireLayerTextures() = 0;
     96 
     97   virtual scoped_ptr<base::Value> AsValue() const = 0;
     98 
     99   // Testing hooks
    100   virtual bool CommitPendingForTesting() = 0;
    101   virtual std::string SchedulerStateAsStringForTesting();
    102 
    103  protected:
    104   explicit Proxy(
    105       scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner);
    106   friend class DebugScopedSetImplThread;
    107   friend class DebugScopedSetMainThread;
    108   friend class DebugScopedSetMainThreadBlocked;
    109 
    110  private:
    111   scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
    112   scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;
    113 #ifndef NDEBUG
    114   bool impl_thread_is_overridden_;
    115   bool is_main_thread_blocked_;
    116 #endif
    117 
    118   DISALLOW_COPY_AND_ASSIGN(Proxy);
    119 };
    120 
    121 #ifndef NDEBUG
    122 class DebugScopedSetMainThreadBlocked {
    123  public:
    124   explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) : proxy_(proxy) {
    125     DCHECK(!proxy_->IsMainThreadBlocked());
    126     proxy_->SetMainThreadBlocked(true);
    127   }
    128   ~DebugScopedSetMainThreadBlocked() {
    129     DCHECK(proxy_->IsMainThreadBlocked());
    130     proxy_->SetMainThreadBlocked(false);
    131   }
    132  private:
    133   Proxy* proxy_;
    134   DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
    135 };
    136 #else
    137 class DebugScopedSetMainThreadBlocked {
    138  public:
    139   explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) {}
    140   ~DebugScopedSetMainThreadBlocked() {}
    141  private:
    142   DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
    143 };
    144 #endif
    145 
    146 }  // namespace cc
    147 
    148 #endif  // CC_TREES_PROXY_H_
    149