gfx/layers/basic/BasicLayers.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/basic/BasicLayers.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,203 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef GFX_BASICLAYERS_H
    1.10 +#define GFX_BASICLAYERS_H
    1.11 +
    1.12 +#include <stdint.h>                     // for INT32_MAX, int32_t
    1.13 +#include "Layers.h"                     // for Layer (ptr only), etc
    1.14 +#include "gfxTypes.h"
    1.15 +#include "gfxCachedTempSurface.h"       // for gfxCachedTempSurface
    1.16 +#include "gfxContext.h"                 // for gfxContext
    1.17 +#include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
    1.18 +#include "mozilla/WidgetUtils.h"        // for ScreenRotation
    1.19 +#include "mozilla/layers/LayersTypes.h"  // for BufferMode, LayersBackend, etc
    1.20 +#include "nsAString.h"
    1.21 +#include "nsAutoPtr.h"                  // for nsRefPtr
    1.22 +#include "nsCOMPtr.h"                   // for already_AddRefed
    1.23 +#include "nsISupportsImpl.h"            // for gfxContext::AddRef, etc
    1.24 +#include "nsRegion.h"                   // for nsIntRegion
    1.25 +#include "nscore.h"                     // for nsAString, etc
    1.26 +
    1.27 +class gfxPattern;
    1.28 +class nsIWidget;
    1.29 +
    1.30 +namespace mozilla {
    1.31 +namespace layers {
    1.32 +
    1.33 +class BasicShadowableLayer;
    1.34 +class ImageFactory;
    1.35 +class ImageLayer;
    1.36 +class PaintLayerContext;
    1.37 +class ReadbackLayer;
    1.38 +class ReadbackProcessor;
    1.39 +
    1.40 +/**
    1.41 + * This is a cairo/Thebes-only, main-thread-only implementation of layers.
    1.42 + * 
    1.43 + * In each transaction, the client sets up the layer tree and then during
    1.44 + * the drawing phase, each ThebesLayer is painted directly into the target
    1.45 + * context (with appropriate clipping and Push/PopGroups performed
    1.46 + * between layers).
    1.47 + */
    1.48 +class BasicLayerManager :
    1.49 +    public LayerManager
    1.50 +{
    1.51 +public:
    1.52 +  /**
    1.53 +   * Construct a BasicLayerManager which will have no default
    1.54 +   * target context. SetDefaultTarget or BeginTransactionWithTarget
    1.55 +   * must be called for any rendering to happen. ThebesLayers will not
    1.56 +   * be retained.
    1.57 +   */
    1.58 +  BasicLayerManager();
    1.59 +  /**
    1.60 +   * Construct a BasicLayerManager which will have no default
    1.61 +   * target context. SetDefaultTarget or BeginTransactionWithTarget
    1.62 +   * must be called for any rendering to happen. ThebesLayers will be
    1.63 +   * retained; that is, we will try to retain the visible contents of
    1.64 +   * ThebesLayers as cairo surfaces. We create ThebesLayer buffers by
    1.65 +   * creating similar surfaces to the default target context, or to
    1.66 +   * aWidget's GetThebesSurface if there is no default target context, or
    1.67 +   * to the passed-in context if there is no widget and no default
    1.68 +   * target context.
    1.69 +   * 
    1.70 +   * This does not keep a strong reference to the widget, so the caller
    1.71 +   * must ensure that the widget outlives the layer manager or call
    1.72 +   * ClearWidget before the widget dies.
    1.73 +   */
    1.74 +  BasicLayerManager(nsIWidget* aWidget);
    1.75 +  virtual ~BasicLayerManager();
    1.76 +
    1.77 +  /**
    1.78 +   * Set the default target context that will be used when BeginTransaction
    1.79 +   * is called. This can only be called outside a transaction.
    1.80 +   * 
    1.81 +   * aDoubleBuffering can request double-buffering for drawing to the
    1.82 +   * default target. When BUFFERED, the layer manager avoids blitting
    1.83 +   * temporary results to aContext and then overpainting them with final
    1.84 +   * results, by using a temporary buffer when necessary. In BUFFERED
    1.85 +   * mode we always completely overwrite the contents of aContext's
    1.86 +   * destination surface (within the clip region) using OPERATOR_SOURCE.
    1.87 +   */
    1.88 +  void SetDefaultTarget(gfxContext* aContext);
    1.89 +  virtual void SetDefaultTargetConfiguration(BufferMode aDoubleBuffering, ScreenRotation aRotation);
    1.90 +  gfxContext* GetDefaultTarget() { return mDefaultTarget; }
    1.91 +
    1.92 +  nsIWidget* GetRetainerWidget() { return mWidget; }
    1.93 +  void ClearRetainerWidget() { mWidget = nullptr; }
    1.94 +
    1.95 +  virtual bool IsWidgetLayerManager() { return mWidget != nullptr; }
    1.96 +
    1.97 +  virtual void BeginTransaction();
    1.98 +  virtual void BeginTransactionWithTarget(gfxContext* aTarget);
    1.99 +  virtual bool EndEmptyTransaction(EndTransactionFlags aFlags = END_DEFAULT);
   1.100 +  virtual void EndTransaction(DrawThebesLayerCallback aCallback,
   1.101 +                              void* aCallbackData,
   1.102 +                              EndTransactionFlags aFlags = END_DEFAULT);
   1.103 +  virtual bool AreComponentAlphaLayersEnabled() { return !IsWidgetLayerManager(); }
   1.104 +
   1.105 +  void AbortTransaction();
   1.106 +
   1.107 +  virtual void SetRoot(Layer* aLayer);
   1.108 +
   1.109 +  virtual already_AddRefed<ThebesLayer> CreateThebesLayer();
   1.110 +  virtual already_AddRefed<ContainerLayer> CreateContainerLayer();
   1.111 +  virtual already_AddRefed<ImageLayer> CreateImageLayer();
   1.112 +  virtual already_AddRefed<CanvasLayer> CreateCanvasLayer();
   1.113 +  virtual already_AddRefed<ColorLayer> CreateColorLayer();
   1.114 +  virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer();
   1.115 +  virtual ImageFactory *GetImageFactory();
   1.116 +
   1.117 +  virtual LayersBackend GetBackendType() { return LayersBackend::LAYERS_BASIC; }
   1.118 +  virtual void GetBackendName(nsAString& name) { name.AssignLiteral("Basic"); }
   1.119 +
   1.120 +  bool InConstruction() { return mPhase == PHASE_CONSTRUCTION; }
   1.121 +#ifdef DEBUG
   1.122 +  bool InDrawing() { return mPhase == PHASE_DRAWING; }
   1.123 +  bool InForward() { return mPhase == PHASE_FORWARD; }
   1.124 +#endif
   1.125 +  bool InTransaction() { return mPhase != PHASE_NONE; }
   1.126 +
   1.127 +  gfxContext* GetTarget() { return mTarget; }
   1.128 +  void SetTarget(gfxContext* aTarget) { mUsingDefaultTarget = false; mTarget = aTarget; }
   1.129 +  bool IsRetained() { return mWidget != nullptr; }
   1.130 +
   1.131 +  virtual const char* Name() const { return "Basic"; }
   1.132 +
   1.133 +  // Clear the cached contents of this layer tree.
   1.134 +  virtual void ClearCachedResources(Layer* aSubtree = nullptr) MOZ_OVERRIDE;
   1.135 +
   1.136 +  void SetTransactionIncomplete() { mTransactionIncomplete = true; }
   1.137 +  bool IsTransactionIncomplete() { return mTransactionIncomplete; }
   1.138 +
   1.139 +  already_AddRefed<gfxContext> PushGroupForLayer(gfxContext* aContext, Layer* aLayer,
   1.140 +                                                 const nsIntRegion& aRegion,
   1.141 +                                                 bool* aNeedsClipToVisibleRegion);
   1.142 +  already_AddRefed<gfxContext> PushGroupWithCachedSurface(gfxContext *aTarget,
   1.143 +                                                          gfxContentType aContent);
   1.144 +  void PopGroupToSourceWithCachedSurface(gfxContext *aTarget, gfxContext *aPushed);
   1.145 +
   1.146 +  virtual bool IsCompositingCheap() { return false; }
   1.147 +  virtual int32_t GetMaxTextureSize() const { return INT32_MAX; }
   1.148 +  bool CompositorMightResample() { return mCompositorMightResample; }
   1.149 +
   1.150 +protected:
   1.151 +  enum TransactionPhase {
   1.152 +    PHASE_NONE, PHASE_CONSTRUCTION, PHASE_DRAWING, PHASE_FORWARD
   1.153 +  };
   1.154 +  TransactionPhase mPhase;
   1.155 +
   1.156 +  // This is the main body of the PaintLayer routine which will if it has
   1.157 +  // children, recurse into PaintLayer() otherwise it will paint using the
   1.158 +  // underlying Paint() method of the Layer. It will not do both.
   1.159 +  void PaintSelfOrChildren(PaintLayerContext& aPaintContext, gfxContext* aGroupTarget);
   1.160 +
   1.161 +  // Paint the group onto the underlying target. This is used by PaintLayer to
   1.162 +  // flush the group to the underlying target.
   1.163 +  void FlushGroup(PaintLayerContext& aPaintContext, bool aNeedsClipToVisibleRegion);
   1.164 +
   1.165 +  // Paints aLayer to mTarget.
   1.166 +  void PaintLayer(gfxContext* aTarget,
   1.167 +                  Layer* aLayer,
   1.168 +                  DrawThebesLayerCallback aCallback,
   1.169 +                  void* aCallbackData,
   1.170 +                  ReadbackProcessor* aReadback);
   1.171 +
   1.172 +  // Clear the contents of a layer
   1.173 +  void ClearLayer(Layer* aLayer);
   1.174 +
   1.175 +  bool EndTransactionInternal(DrawThebesLayerCallback aCallback,
   1.176 +                              void* aCallbackData,
   1.177 +                              EndTransactionFlags aFlags = END_DEFAULT);
   1.178 +
   1.179 +  void FlashWidgetUpdateArea(gfxContext* aContext);
   1.180 +
   1.181 +  void RenderDebugOverlay();
   1.182 +
   1.183 +  // Widget whose surface should be used as the basis for ThebesLayer
   1.184 +  // buffers.
   1.185 +  nsIWidget* mWidget;
   1.186 +  // The default context for BeginTransaction.
   1.187 +  nsRefPtr<gfxContext> mDefaultTarget;
   1.188 +  // The context to draw into.
   1.189 +  nsRefPtr<gfxContext> mTarget;
   1.190 +  // Image factory we use.
   1.191 +  nsRefPtr<ImageFactory> mFactory;
   1.192 +
   1.193 +  // Cached surface for double buffering
   1.194 +  gfxCachedTempSurface mCachedSurface;
   1.195 +
   1.196 +  BufferMode mDoubleBuffering;
   1.197 +  bool mUsingDefaultTarget;
   1.198 +  bool mCachedSurfaceInUse;
   1.199 +  bool mTransactionIncomplete;
   1.200 +  bool mCompositorMightResample;
   1.201 +};
   1.202 +
   1.203 +}
   1.204 +}
   1.205 +
   1.206 +#endif /* GFX_BASICLAYERS_H */

mercurial