gfx/layers/mlgpu/LayerManagerMLGPU.h
author Alexis Beingessner <a.beingessner@gmail.com>
Thu, 07 Dec 2017 17:13:05 -0500
changeset 715489 5e9ee7bdc25ec15785dbd4ad1d70b292fc4ba48d
parent 710079 1f8dab2a495e6df770c0d3fe1be8eab84c449a4d
child 766350 efbc1e3f92eaf23c1d00f636853b0726e8a6a3c0
permissions -rw-r--r--
Bug 1406231 - remove the TextLayer class, and all remaining traces of it. r?mattwoodrow MozReview-Commit-ID: 5fmKfkO6hnO

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef MOZILLA_GFX_LAYERMANAGERMLGPU_H
#define MOZILLA_GFX_LAYERMANAGERMLGPU_H

#include "Layers.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "LayerMLGPU.h"

namespace mozilla {
namespace layers {

class FrameBuilder;
class LayerManagerMLGPU;
class RenderPassMLGPU;
class SharedBufferMLGPU;
class RenderViewMLGPU;
class TextRenderer;
class TextureSourceProviderMLGPU;
class MLGBuffer;
class MLGDevice;
class MLGSwapChain;
class MLGTileBuffer;
struct LayerProperties;

class LayerManagerMLGPU final : public HostLayerManager
{
public:
  explicit LayerManagerMLGPU(widget::CompositorWidget* aWidget);
  ~LayerManagerMLGPU();

  bool Initialize();
  void Destroy() override;

  // LayerManager methods
  bool BeginTransaction() override;
  void BeginTransactionWithDrawTarget(gfx::DrawTarget* aTarget, const gfx::IntRect& aRect) override;
  void SetRoot(Layer* aLayer) override;
  already_AddRefed<PaintedLayer> CreatePaintedLayer() override;
  already_AddRefed<ContainerLayer> CreateContainerLayer() override;
  already_AddRefed<ImageLayer> CreateImageLayer() override;
  already_AddRefed<ColorLayer> CreateColorLayer() override;
  already_AddRefed<CanvasLayer> CreateCanvasLayer() override;
  already_AddRefed<RefLayer> CreateRefLayer() override;
  already_AddRefed<BorderLayer> CreateBorderLayer() override;

  bool AreComponentAlphaLayersEnabled() override;
  bool BlendingRequiresIntermediateSurface() override;

  // HostLayerManager methods
  void ForcePresent() override;
  TextureFactoryIdentifier GetTextureFactoryIdentifier() override;
  LayersBackend GetBackendType() override;
  void AddInvalidRegion(const nsIntRegion& aRegion) override;
  void ClearApproximatelyVisibleRegions(uint64_t aLayersId,
                                                const Maybe<uint32_t>& aPresShellId) override {}
  void UpdateApproximatelyVisibleRegion(const ScrollableLayerGuid& aGuid,
                                                const CSSIntRegion& aRegion) override {}
  void EndTransaction(const TimeStamp& aTimeStamp, EndTransactionFlags aFlags) override;
  void EndTransaction(DrawPaintedLayerCallback aCallback,
                      void* aCallbackData,
                      EndTransactionFlags aFlags) override;
  Compositor* GetCompositor() const override {
    return nullptr;
  }
  bool IsCompositingToScreen() const override;
  TextureSourceProvider* GetTextureSourceProvider() const override;
  void ClearCachedResources(Layer* aSubtree = nullptr) override;
  void NotifyShadowTreeTransaction() override;
  void UpdateRenderBounds(const gfx::IntRect& aRect) override;

  LayerManagerMLGPU* AsLayerManagerMLGPU() override {
    return this;
  }
  const char* Name() const override {
    return "";
  }

  // This should only be called while a FrameBuilder is live.
  FrameBuilder* GetCurrentFrame() const {
    MOZ_ASSERT(mCurrentFrame);
    return mCurrentFrame;
  }
  MLGDevice* GetDevice() {
    return mDevice;
  }

  TimeStamp GetLastCompositionEndTime() const {
    return mLastCompositionEndTime;
  }
  const nsIntRegion& GetRegionToClear() const {
    return mRegionToClear;
  }
  uint32_t GetDebugFrameNumber() const {
    return mDebugFrameNumber;
  }

private:
  void Composite();
  void ComputeInvalidRegion();
  void RenderLayers();
  void DrawDebugOverlay();
  bool PreRender();
  void PostRender();

private:
  RefPtr<MLGDevice> mDevice;
  RefPtr<MLGSwapChain> mSwapChain;
  RefPtr<TextureSourceProviderMLGPU> mTextureSourceProvider;
  RefPtr<TextRenderer> mTextRenderer;
  widget::CompositorWidget* mWidget;

  UniquePtr<LayerProperties> mClonedLayerTreeProperties;
  nsIntRegion mNextFrameInvalidRegion;
  gfx::IntRect mRenderBounds;

  // These are per-frame only.
  bool mDrawDiagnostics;
  bool mUsingInvalidation;
  nsIntRegion mInvalidRegion;
  Maybe<widget::WidgetRenderingContext> mWidgetContext;
  
  IntSize mWindowSize;
  TimeStamp mCompositionStartTime;
  TimeStamp mLastCompositionEndTime;

  RefPtr<DrawTarget> mTarget;
  gfx::IntRect mTargetRect;
  FrameBuilder* mCurrentFrame;

  // The debug frame number is incremented every frame and is included in the
  // WorldConstants bound to vertex shaders. This allows us to correlate
  // a frame in RenderDoc to spew in the console.
  uint32_t mDebugFrameNumber;
  RefPtr<MLGBuffer> mDiagnosticVertices;
};

} // namespace layers
} // namespace mozilla

#endif