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

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef MOZILLA_GFX_DRAWTARGETTILED_H_
       7             : #define MOZILLA_GFX_DRAWTARGETTILED_H_
       8             : 
       9             : #include "2D.h"
      10             : #include "Filters.h"
      11             : #include "Logging.h"
      12             : 
      13             : #include <vector>
      14             : 
      15             : namespace mozilla {
      16             : namespace gfx {
      17             : 
      18           0 : struct TileInternal : public Tile {
      19             :   TileInternal()
      20             :     : mClippedOut(false)
      21             :   {}
      22             : 
      23           0 :   explicit TileInternal(const Tile& aOther)
      24           0 :     : Tile(aOther)
      25           0 :     , mClippedOut(false)
      26           0 :   {}
      27             : 
      28             :   bool mClippedOut;
      29             : };
      30             : 
      31             : 
      32           0 : class DrawTargetTiled : public DrawTarget
      33             : {
      34             : public:
      35             :   DrawTargetTiled();
      36             : 
      37             :   bool Init(const TileSet& mTiles);
      38             : 
      39           0 :   virtual bool IsTiledDrawTarget() const override { return true; }
      40             : 
      41           0 :   virtual DrawTargetType GetType() const override { return mTiles[0].mDrawTarget->GetType(); }
      42           0 :   virtual BackendType GetBackendType() const override { return mTiles[0].mDrawTarget->GetBackendType(); }
      43             :   virtual already_AddRefed<SourceSurface> Snapshot() override;
      44             :   virtual void DetachAllSnapshots() override;
      45           0 :   virtual IntSize GetSize() override {
      46           0 :     MOZ_ASSERT(mRect.width > 0 && mRect.height > 0);
      47           0 :     return IntSize(mRect.XMost(), mRect.YMost());
      48             :   }
      49             : 
      50             :   virtual void Flush() override;
      51             :   virtual void DrawSurface(SourceSurface *aSurface,
      52             :                            const Rect &aDest,
      53             :                            const Rect &aSource,
      54             :                            const DrawSurfaceOptions &aSurfOptions,
      55             :                            const DrawOptions &aOptions) override;
      56             :   virtual void DrawFilter(FilterNode *aNode,
      57             :                           const Rect &aSourceRect,
      58             :                           const Point &aDestPoint,
      59             :                           const DrawOptions &aOptions = DrawOptions()) override;
      60           0 :   virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
      61             :                                      const Point &aDest,
      62             :                                      const Color &aColor,
      63             :                                      const Point &aOffset,
      64             :                                      Float aSigma,
      65           0 :                                      CompositionOp aOperator) override { /* Not implemented */ MOZ_CRASH("GFX: DrawSurfaceWithShadow"); }
      66             : 
      67             :   virtual void ClearRect(const Rect &aRect) override;
      68             :   virtual void MaskSurface(const Pattern &aSource,
      69             :                            SourceSurface *aMask,
      70             :                            Point aOffset,
      71             :                            const DrawOptions &aOptions = DrawOptions()) override;
      72             : 
      73             :   virtual void CopySurface(SourceSurface *aSurface,
      74             :                            const IntRect &aSourceRect,
      75             :                            const IntPoint &aDestination) override;
      76             : 
      77             :   virtual void FillRect(const Rect &aRect,
      78             :                         const Pattern &aPattern,
      79             :                         const DrawOptions &aOptions = DrawOptions()) override;
      80             :   virtual void StrokeRect(const Rect &aRect,
      81             :                           const Pattern &aPattern,
      82             :                           const StrokeOptions &aStrokeOptions = StrokeOptions(),
      83             :                           const DrawOptions &aOptions = DrawOptions()) override;
      84             :   virtual void StrokeLine(const Point &aStart,
      85             :                           const Point &aEnd,
      86             :                           const Pattern &aPattern,
      87             :                           const StrokeOptions &aStrokeOptions = StrokeOptions(),
      88             :                           const DrawOptions &aOptions = DrawOptions()) override;
      89             :   virtual void Stroke(const Path *aPath,
      90             :                       const Pattern &aPattern,
      91             :                       const StrokeOptions &aStrokeOptions = StrokeOptions(),
      92             :                       const DrawOptions &aOptions = DrawOptions()) override;
      93             :   virtual void Fill(const Path *aPath,
      94             :                     const Pattern &aPattern,
      95             :                     const DrawOptions &aOptions = DrawOptions()) override;
      96             :   virtual void FillGlyphs(ScaledFont *aFont,
      97             :                           const GlyphBuffer &aBuffer,
      98             :                           const Pattern &aPattern,
      99             :                           const DrawOptions &aOptions = DrawOptions(),
     100             :                           const GlyphRenderingOptions *aRenderingOptions = nullptr) override;
     101             :   virtual void Mask(const Pattern &aSource,
     102             :                     const Pattern &aMask,
     103             :                     const DrawOptions &aOptions = DrawOptions()) override;
     104             :   virtual void PushClip(const Path *aPath) override;
     105             :   virtual void PushClipRect(const Rect &aRect) override;
     106             :   virtual void PopClip() override;
     107             :   virtual void PushLayer(bool aOpaque, Float aOpacity,
     108             :                          SourceSurface* aMask,
     109             :                          const Matrix& aMaskTransform,
     110             :                          const IntRect& aBounds = IntRect(),
     111             :                          bool aCopyBackground = false) override;
     112             :   virtual void PopLayer() override;
     113             : 
     114             : 
     115             :   virtual void SetTransform(const Matrix &aTransform) override;
     116             : 
     117             :   virtual void SetPermitSubpixelAA(bool aPermitSubpixelAA) override;
     118             : 
     119           0 :   virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
     120             :                                                                   const IntSize &aSize,
     121             :                                                                   int32_t aStride,
     122             :                                                                   SurfaceFormat aFormat) const override
     123             :   {
     124           0 :     return mTiles[0].mDrawTarget->CreateSourceSurfaceFromData(aData, aSize, aStride, aFormat);
     125             :   }
     126           0 :   virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const override
     127             :   {
     128           0 :     return mTiles[0].mDrawTarget->OptimizeSourceSurface(aSurface);
     129             :   }
     130             : 
     131             :   virtual already_AddRefed<SourceSurface>
     132           0 :     CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const override
     133             :   {
     134           0 :     return mTiles[0].mDrawTarget->CreateSourceSurfaceFromNativeSurface(aSurface);
     135             :   }
     136             : 
     137             :   virtual already_AddRefed<DrawTarget>
     138           0 :     CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const override
     139             :   {
     140           0 :     return mTiles[0].mDrawTarget->CreateSimilarDrawTarget(aSize, aFormat);
     141             :   }
     142             : 
     143           0 :   virtual already_AddRefed<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const override
     144             :   {
     145           0 :     return mTiles[0].mDrawTarget->CreatePathBuilder(aFillRule);
     146             :   }
     147             : 
     148             :   virtual already_AddRefed<GradientStops>
     149           0 :     CreateGradientStops(GradientStop *aStops,
     150             :                         uint32_t aNumStops,
     151             :                         ExtendMode aExtendMode = ExtendMode::CLAMP) const override
     152             :   {
     153           0 :     return mTiles[0].mDrawTarget->CreateGradientStops(aStops, aNumStops, aExtendMode);
     154             :   }
     155           0 :   virtual already_AddRefed<FilterNode> CreateFilter(FilterType aType) override
     156             :   {
     157           0 :     return mTiles[0].mDrawTarget->CreateFilter(aType);
     158             :   }
     159             : 
     160             : private:
     161             :   std::vector<TileInternal> mTiles;
     162             :   std::vector<std::vector<uint32_t> > mClippedOutTilesStack;
     163             :   IntRect mRect;
     164             : 
     165             :   struct PushedLayer
     166             :   {
     167           0 :     explicit PushedLayer(bool aOldPermitSubpixelAA)
     168           0 :       : mOldPermitSubpixelAA(aOldPermitSubpixelAA)
     169           0 :     {}
     170             :     bool mOldPermitSubpixelAA;
     171             :   };
     172             :   std::vector<PushedLayer> mPushedLayers;
     173             : };
     174             : 
     175           0 : class SnapshotTiled : public SourceSurface
     176             : {
     177             : public:
     178           0 :   SnapshotTiled(const std::vector<TileInternal>& aTiles, const IntRect& aRect)
     179           0 :     : mRect(aRect)
     180             :   {
     181           0 :     for (size_t i = 0; i < aTiles.size(); i++) {
     182           0 :       mSnapshots.push_back(aTiles[i].mDrawTarget->Snapshot());
     183           0 :       mOrigins.push_back(aTiles[i].mTileOrigin);
     184             :     }
     185           0 :   }
     186             : 
     187           0 :   virtual SurfaceType GetType() const { return SurfaceType::TILED; }
     188           0 :   virtual IntSize GetSize() const {
     189           0 :     MOZ_ASSERT(mRect.width > 0 && mRect.height > 0);
     190           0 :     return IntSize(mRect.XMost(), mRect.YMost());
     191             :   }
     192           0 :   virtual SurfaceFormat GetFormat() const { return mSnapshots[0]->GetFormat(); }
     193             : 
     194           0 :   virtual already_AddRefed<DataSourceSurface> GetDataSurface()
     195             :   {
     196           0 :     RefPtr<DataSourceSurface> surf = Factory::CreateDataSourceSurface(GetSize(), GetFormat());
     197             : 
     198             :     DataSourceSurface::MappedSurface mappedSurf;
     199           0 :     if (!surf->Map(DataSourceSurface::MapType::WRITE, &mappedSurf)) {
     200           0 :       gfxCriticalError() << "DrawTargetTiled::GetDataSurface failed to map surface";
     201           0 :       return nullptr;
     202             :     }
     203             : 
     204             :     {
     205             :       RefPtr<DrawTarget> dt =
     206           0 :         Factory::CreateDrawTargetForData(BackendType::CAIRO, mappedSurf.mData,
     207           0 :         GetSize(), mappedSurf.mStride, GetFormat());
     208             : 
     209           0 :       if (!dt) {
     210           0 :         gfxWarning() << "DrawTargetTiled::GetDataSurface failed in CreateDrawTargetForData";
     211           0 :         surf->Unmap();
     212           0 :         return nullptr;
     213             :       }
     214           0 :       for (size_t i = 0; i < mSnapshots.size(); i++) {
     215           0 :         RefPtr<DataSourceSurface> dataSurf = mSnapshots[i]->GetDataSurface();
     216           0 :         dt->CopySurface(dataSurf, IntRect(IntPoint(0, 0), mSnapshots[i]->GetSize()), mOrigins[i]);
     217             :       }
     218             :     }
     219           0 :     surf->Unmap();
     220             : 
     221           0 :     return surf.forget();
     222             :   }
     223             : 
     224             :   std::vector<RefPtr<SourceSurface>> mSnapshots;
     225             :   std::vector<IntPoint> mOrigins;
     226             :   IntRect mRect;
     227             : };
     228             : 
     229             : } // namespace gfx
     230             : } // namespace mozilla
     231             : 
     232             : #endif

Generated by: LCOV version 1.13