LCOV - code coverage report
Current view: top level - gfx/webrender_bindings - WebRenderAPI.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 8 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set sw=2 sts=2 ts=8 et tw=99 : */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef MOZILLA_LAYERS_WEBRENDERAPI_H
       8             : #define MOZILLA_LAYERS_WEBRENDERAPI_H
       9             : 
      10             : #include <vector>
      11             : #include <unordered_map>
      12             : 
      13             : #include "mozilla/AlreadyAddRefed.h"
      14             : #include "mozilla/Range.h"
      15             : #include "mozilla/webrender/webrender_ffi.h"
      16             : #include "mozilla/webrender/WebRenderTypes.h"
      17             : #include "FrameMetrics.h"
      18             : #include "GLTypes.h"
      19             : #include "Units.h"
      20             : 
      21             : namespace mozilla {
      22             : 
      23             : namespace widget {
      24             : class CompositorWidget;
      25             : }
      26             : 
      27             : namespace layers {
      28             : class CompositorBridgeParentBase;
      29             : class WebRenderBridgeParent;
      30             : }
      31             : 
      32             : namespace wr {
      33             : 
      34             : class DisplayListBuilder;
      35             : class RendererOGL;
      36             : class RendererEvent;
      37             : 
      38             : class WebRenderAPI
      39             : {
      40           0 :   NS_INLINE_DECL_REFCOUNTING(WebRenderAPI);
      41             : 
      42             : public:
      43             :   /// This can be called on the compositor thread only.
      44             :   static already_AddRefed<WebRenderAPI> Create(bool aEnableProfiler,
      45             :                                                layers::CompositorBridgeParentBase* aBridge,
      46             :                                                RefPtr<widget::CompositorWidget>&& aWidget,
      47             :                                                LayoutDeviceIntSize aSize);
      48             : 
      49           0 :   wr::WindowId GetId() const { return mId; }
      50             : 
      51             :   void UpdateScrollPosition(const WrPipelineId& aPipelineId,
      52             :                             const layers::FrameMetrics::ViewID& aScrollId,
      53             :                             const WrPoint& aScrollPosition);
      54             : 
      55             :   void GenerateFrame();
      56             :   void GenerateFrame(const nsTArray<WrOpacityProperty>& aOpacityArray,
      57             :                      const nsTArray<WrTransformProperty>& aTransformArray);
      58             : 
      59             :   void SetWindowParameters(LayoutDeviceIntSize size);
      60             :   void SetRootDisplayList(gfx::Color aBgColor,
      61             :                           Epoch aEpoch,
      62             :                           LayerSize aViewportSize,
      63             :                           WrPipelineId pipeline_id,
      64             :                           const WrSize& content_size,
      65             :                           WrBuiltDisplayListDescriptor dl_descriptor,
      66             :                           uint8_t *dl_data,
      67             :                           size_t dl_size);
      68             : 
      69             :   void ClearRootDisplayList(Epoch aEpoch,
      70             :                             WrPipelineId pipeline_id);
      71             : 
      72             :   void SetRootPipeline(wr::PipelineId aPipeline);
      73             : 
      74             :   void AddImage(wr::ImageKey aKey,
      75             :                 const ImageDescriptor& aDescriptor,
      76             :                 Range<uint8_t> aBytes);
      77             : 
      78             :   void AddBlobImage(wr::ImageKey aKey,
      79             :                     const ImageDescriptor& aDescriptor,
      80             :                     Range<uint8_t> aBytes);
      81             : 
      82             :   void AddExternalImageBuffer(ImageKey key,
      83             :                               const ImageDescriptor& aDescriptor,
      84             :                               ExternalImageId aHandle);
      85             : 
      86             :   void AddExternalImage(ImageKey key,
      87             :                         const ImageDescriptor& aDescriptor,
      88             :                         ExternalImageId aExtID,
      89             :                         WrExternalImageBufferType aBufferType,
      90             :                         uint8_t aChannelIndex);
      91             : 
      92             :   void UpdateImageBuffer(wr::ImageKey aKey,
      93             :                          const ImageDescriptor& aDescriptor,
      94             :                          Range<uint8_t> aBytes);
      95             : 
      96             :   void DeleteImage(wr::ImageKey aKey);
      97             : 
      98             :   void AddRawFont(wr::FontKey aKey, Range<uint8_t> aBytes, uint32_t aIndex);
      99             : 
     100             :   void DeleteFont(wr::FontKey aKey);
     101             : 
     102             :   void SetProfilerEnabled(bool aEnabled);
     103             : 
     104             :   void RunOnRenderThread(UniquePtr<RendererEvent> aEvent);
     105             :   void Readback(gfx::IntSize aSize, uint8_t *aBuffer, uint32_t aBufferSize);
     106             : 
     107             :   void Pause();
     108             :   bool Resume();
     109             : 
     110             :   WrIdNamespace GetNamespace();
     111           0 :   GLint GetMaxTextureSize() const { return mMaxTextureSize; }
     112           0 :   bool GetUseANGLE() const { return mUseANGLE; }
     113             : 
     114             : protected:
     115           0 :   WebRenderAPI(WrAPI* aRawApi, wr::WindowId aId, GLint aMaxTextureSize, bool aUseANGLE)
     116           0 :     : mWrApi(aRawApi)
     117             :     , mId(aId)
     118             :     , mMaxTextureSize(aMaxTextureSize)
     119           0 :     , mUseANGLE(aUseANGLE)
     120           0 :   {}
     121             : 
     122             :   ~WebRenderAPI();
     123             :   // Should be used only for shutdown handling
     124             :   void WaitFlushed();
     125             : 
     126             :   WrAPI* mWrApi;
     127             :   wr::WindowId mId;
     128             :   GLint mMaxTextureSize;
     129             :   bool mUseANGLE;
     130             : 
     131             :   friend class DisplayListBuilder;
     132             :   friend class layers::WebRenderBridgeParent;
     133             : };
     134             : 
     135             : /// This is a simple C++ wrapper around WrState defined in the rust bindings.
     136             : /// We may want to turn this into a direct wrapper on top of WebRenderFrameBuilder
     137             : /// instead, so the interface may change a bit.
     138             : class DisplayListBuilder {
     139             : public:
     140             :   explicit DisplayListBuilder(wr::PipelineId aId,
     141             :                               const WrSize& aContentSize);
     142             :   DisplayListBuilder(DisplayListBuilder&&) = default;
     143             : 
     144             :   ~DisplayListBuilder();
     145             : 
     146             :   void Begin(const LayerIntSize& aSize);
     147             : 
     148             :   void End();
     149             :   void Finalize(WrSize& aOutContentSize,
     150             :                 wr::BuiltDisplayList& aOutDisplayList);
     151             : 
     152             :   void PushStackingContext(const WrRect& aBounds, // TODO: We should work with strongly typed rects
     153             :                            const uint64_t& aAnimationId,
     154             :                            const float* aOpacity,
     155             :                            const gfx::Matrix4x4* aTransform,
     156             :                            WrTransformStyle aTransformStyle,
     157             :                            const WrMixBlendMode& aMixBlendMode,
     158             :                            const nsTArray<WrFilterOp>& aFilters);
     159             :   void PopStackingContext();
     160             : 
     161             :   void PushClip(const WrRect& aClipRect,
     162             :                 const WrImageMask* aMask);
     163             :   void PopClip();
     164             : 
     165             :   void PushBuiltDisplayList(wr::BuiltDisplayList &dl);
     166             : 
     167             :   void PushScrollLayer(const layers::FrameMetrics::ViewID& aScrollId,
     168             :                        const WrRect& aContentRect, // TODO: We should work with strongly typed rects
     169             :                        const WrRect& aClipRect);
     170             :   void PopScrollLayer();
     171             : 
     172             :   void PushClipAndScrollInfo(const layers::FrameMetrics::ViewID& aScrollId,
     173             :                              const WrClipId* aClipId);
     174             :   void PopClipAndScrollInfo();
     175             : 
     176             :   void PushRect(const WrRect& aBounds,
     177             :                 const WrRect& aClip,
     178             :                 const WrColor& aColor);
     179             : 
     180             :   void PushLinearGradient(const WrRect& aBounds,
     181             :                           const WrRect& aClip,
     182             :                           const WrPoint& aStartPoint,
     183             :                           const WrPoint& aEndPoint,
     184             :                           const nsTArray<WrGradientStop>& aStops,
     185             :                           wr::GradientExtendMode aExtendMode,
     186             :                           const WrSize aTileSize,
     187             :                           const WrSize aTileSpacing);
     188             : 
     189             :   void PushRadialGradient(const WrRect& aBounds,
     190             :                           const WrRect& aClip,
     191             :                           const WrPoint& aCenter,
     192             :                           const WrSize& aRadius,
     193             :                           const nsTArray<WrGradientStop>& aStops,
     194             :                           wr::GradientExtendMode aExtendMode,
     195             :                           const WrSize aTileSize,
     196             :                           const WrSize aTileSpacing);
     197             : 
     198             :   void PushImage(const WrRect& aBounds,
     199             :                  const WrRect& aClip,
     200             :                  wr::ImageRendering aFilter,
     201             :                  wr::ImageKey aImage);
     202             : 
     203             :   void PushImage(const WrRect& aBounds,
     204             :                  const WrRect& aClip,
     205             :                  const WrSize& aStretchSize,
     206             :                  const WrSize& aTileSpacing,
     207             :                  wr::ImageRendering aFilter,
     208             :                  wr::ImageKey aImage);
     209             : 
     210             :   void PushYCbCrPlanarImage(const WrRect& aBounds,
     211             :                             const WrRect& aClip,
     212             :                             wr::ImageKey aImageChannel0,
     213             :                             wr::ImageKey aImageChannel1,
     214             :                             wr::ImageKey aImageChannel2,
     215             :                             WrYuvColorSpace aColorSpace,
     216             :                             wr::ImageRendering aFilter);
     217             : 
     218             :   void PushNV12Image(const WrRect& aBounds,
     219             :                      const WrRect& aClip,
     220             :                      wr::ImageKey aImageChannel0,
     221             :                      wr::ImageKey aImageChannel1,
     222             :                      WrYuvColorSpace aColorSpace,
     223             :                      wr::ImageRendering aFilter);
     224             : 
     225             :   void PushYCbCrInterleavedImage(const WrRect& aBounds,
     226             :                                  const WrRect& aClip,
     227             :                                  wr::ImageKey aImageChannel0,
     228             :                                  WrYuvColorSpace aColorSpace,
     229             :                                  wr::ImageRendering aFilter);
     230             : 
     231             :   void PushIFrame(const WrRect& aBounds,
     232             :                   wr::PipelineId aPipeline);
     233             : 
     234             :   // XXX WrBorderSides are passed with Range.
     235             :   // It is just to bypass compiler bug. See Bug 1357734.
     236             :   void PushBorder(const WrRect& aBounds,
     237             :                   const WrRect& aClip,
     238             :                   const WrBorderWidths& aWidths,
     239             :                   const Range<const WrBorderSide>& aSides,
     240             :                   const WrBorderRadius& aRadius);
     241             : 
     242             :   void PushBorderImage(const WrRect& aBounds,
     243             :                        const WrRect& aClip,
     244             :                        const WrBorderWidths& aWidths,
     245             :                        wr::ImageKey aImage,
     246             :                        const WrNinePatchDescriptor& aPatch,
     247             :                        const WrSideOffsets2Df32& aOutset,
     248             :                        const WrRepeatMode& aRepeatHorizontal,
     249             :                        const WrRepeatMode& aRepeatVertical);
     250             : 
     251             :   void PushBorderGradient(const WrRect& aBounds,
     252             :                           const WrRect& aClip,
     253             :                           const WrBorderWidths& aWidths,
     254             :                           const WrPoint& aStartPoint,
     255             :                           const WrPoint& aEndPoint,
     256             :                           const nsTArray<WrGradientStop>& aStops,
     257             :                           wr::GradientExtendMode aExtendMode,
     258             :                           const WrSideOffsets2Df32& aOutset);
     259             : 
     260             :   void PushBorderRadialGradient(const WrRect& aBounds,
     261             :                                 const WrRect& aClip,
     262             :                                 const WrBorderWidths& aWidths,
     263             :                                 const WrPoint& aCenter,
     264             :                                 const WrSize& aRadius,
     265             :                                 const nsTArray<WrGradientStop>& aStops,
     266             :                                 wr::GradientExtendMode aExtendMode,
     267             :                                 const WrSideOffsets2Df32& aOutset);
     268             : 
     269             :   void PushText(const WrRect& aBounds,
     270             :                 const WrRect& aClip,
     271             :                 const gfx::Color& aColor,
     272             :                 wr::FontKey aFontKey,
     273             :                 Range<const WrGlyphInstance> aGlyphBuffer,
     274             :                 float aGlyphSize);
     275             : 
     276             :   void PushBoxShadow(const WrRect& aRect,
     277             :                      const WrRect& aClip,
     278             :                      const WrRect& aBoxBounds,
     279             :                      const WrPoint& aOffset,
     280             :                      const WrColor& aColor,
     281             :                      const float& aBlurRadius,
     282             :                      const float& aSpreadRadius,
     283             :                      const float& aBorderRadius,
     284             :                      const WrBoxShadowClipMode& aClipMode);
     285             : 
     286             :   // Returns the clip id that was most recently pushed with PushClip and that
     287             :   // has not yet been popped with PopClip. Return Nothing() if the clip stack
     288             :   // is empty.
     289             :   Maybe<WrClipId> TopmostClipId();
     290             :   // Returns the scroll id that was pushed just before the given scroll id. This
     291             :   // function returns Nothing() if the given scrollid has not been encountered,
     292             :   // or if it is the rootmost scroll id (and therefore has no ancestor).
     293             :   Maybe<layers::FrameMetrics::ViewID> ParentScrollIdFor(layers::FrameMetrics::ViewID aScrollId);
     294             : 
     295             :   // Try to avoid using this when possible.
     296             :   WrState* Raw() { return mWrState; }
     297             : protected:
     298             :   WrState* mWrState;
     299             : 
     300             :   // Track the stack of clip ids and scroll layer ids that have been pushed
     301             :   // (by PushClip and PushScrollLayer, respectively) and are still active.
     302             :   // This is helpful for knowing e.g. what the ancestor scroll id of a particular
     303             :   // scroll id is, and doing other "queries" of current state.
     304             :   std::vector<WrClipId> mClipIdStack;
     305             :   std::vector<layers::FrameMetrics::ViewID> mScrollIdStack;
     306             : 
     307             :   // Track the parent scroll id of each scroll id that we encountered.
     308             :   std::unordered_map<layers::FrameMetrics::ViewID, layers::FrameMetrics::ViewID> mScrollParents;
     309             : 
     310             :   friend class WebRenderAPI;
     311             : };
     312             : 
     313             : Maybe<WrImageFormat>
     314             : SurfaceFormatToWrImageFormat(gfx::SurfaceFormat aFormat);
     315             : 
     316             : } // namespace wr
     317             : } // namespace mozilla
     318             : 
     319             : #endif

Generated by: LCOV version 1.13