DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (cf48e59e88de)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
/* -*- 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"
#include "mozilla/layers/MLGPUScreenshotGrabber.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);
  virtual ~LayerManagerMLGPU();

  bool Initialize();
  void Destroy() override;

  // LayerManager methods
  bool BeginTransaction(const nsCString& aURL) 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;

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

  // HostLayerManager methods
  void ForcePresent() override;
  TextureFactoryIdentifier GetTextureFactoryIdentifier() override;
  LayersBackend GetBackendType() override;
  void AddInvalidRegion(const nsIntRegion& 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;

  void InvalidateAll() override {
    AddInvalidRegion(nsIntRegion(mRenderBounds));
  }

  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;

  // Screenshotting for the profiler.
  MLGPUScreenshotGrabber mProfilerScreenshotGrabber;
};

}  // namespace layers
}  // namespace mozilla

#endif