LCOV - code coverage report
Current view: top level - gfx/webrender_bindings - WebRenderTypes.h (source / functions) Hit Total Coverage
Test: output.info Lines: 3 249 1.2 %
Date: 2017-07-14 16:53:18 Functions: 1 58 1.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; 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 GFX_WEBRENDERTYPES_H
       7             : #define GFX_WEBRENDERTYPES_H
       8             : 
       9             : #include "mozilla/webrender/webrender_ffi.h"
      10             : #include "mozilla/Maybe.h"
      11             : #include "mozilla/gfx/Matrix.h"
      12             : #include "mozilla/gfx/Types.h"
      13             : #include "mozilla/gfx/Tools.h"
      14             : #include "mozilla/layers/LayersTypes.h"
      15             : #include "mozilla/Range.h"
      16             : #include "Units.h"
      17             : #include "RoundedRect.h"
      18             : #include "nsStyleConsts.h"
      19             : 
      20             : typedef mozilla::Maybe<WrImageMask> MaybeImageMask;
      21             : 
      22             : namespace mozilla {
      23             : namespace wr {
      24             : 
      25             : typedef WrGradientExtendMode GradientExtendMode;
      26             : typedef WrMixBlendMode MixBlendMode;
      27             : typedef WrImageRendering ImageRendering;
      28             : typedef WrImageFormat ImageFormat;
      29             : typedef WrWindowId WindowId;
      30             : typedef WrPipelineId PipelineId;
      31             : typedef WrImageKey ImageKey;
      32             : typedef WrFontKey FontKey;
      33             : typedef WrEpoch Epoch;
      34             : typedef WrExternalImageId ExternalImageId;
      35             : 
      36             : typedef Maybe<ExternalImageId> MaybeExternalImageId;
      37             : 
      38           0 : inline WindowId NewWindowId(uint64_t aId) {
      39             :   WindowId id;
      40           0 :   id.mHandle = aId;
      41           0 :   return id;
      42             : }
      43             : 
      44           0 : inline Epoch NewEpoch(uint32_t aEpoch) {
      45             :   Epoch e;
      46           0 :   e.mHandle = aEpoch;
      47           0 :   return e;
      48             : }
      49             : 
      50             : inline Maybe<WrImageFormat>
      51           0 : SurfaceFormatToWrImageFormat(gfx::SurfaceFormat aFormat) {
      52           0 :   switch (aFormat) {
      53             :     case gfx::SurfaceFormat::R8G8B8X8:
      54             :       // TODO: use RGBA + opaque flag
      55           0 :       return Some(WrImageFormat::BGRA8);
      56             :     case gfx::SurfaceFormat::B8G8R8X8:
      57             :       // TODO: WebRender will have a BGRA + opaque flag for this but does not
      58             :       // have it yet (cf. issue #732).
      59             :     case gfx::SurfaceFormat::B8G8R8A8:
      60           0 :       return Some(WrImageFormat::BGRA8);
      61             :     case gfx::SurfaceFormat::B8G8R8:
      62           0 :       return Some(WrImageFormat::RGB8);
      63             :     case gfx::SurfaceFormat::A8:
      64           0 :       return Some(WrImageFormat::A8);
      65             :     case gfx::SurfaceFormat::R8G8:
      66           0 :       return Some(WrImageFormat::RG8);
      67             :     case gfx::SurfaceFormat::UNKNOWN:
      68           0 :       return Some(WrImageFormat::Invalid);
      69             :     default:
      70           0 :       return Nothing();
      71             :   }
      72             : }
      73             : 
      74             : inline gfx::SurfaceFormat
      75           0 : WrImageFormatToSurfaceFormat(ImageFormat aFormat) {
      76           0 :   switch (aFormat) {
      77             :     case ImageFormat::BGRA8:
      78           0 :       return gfx::SurfaceFormat::B8G8R8A8;
      79             :     case ImageFormat::A8:
      80           0 :       return gfx::SurfaceFormat::A8;
      81             :     case ImageFormat::RGB8:
      82           0 :       return gfx::SurfaceFormat::B8G8R8;
      83             :     default:
      84           0 :       return gfx::SurfaceFormat::UNKNOWN;
      85             :   }
      86             : }
      87             : 
      88             : struct ImageDescriptor: public WrImageDescriptor {
      89           0 :   ImageDescriptor(const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat)
      90           0 :   {
      91           0 :     format = SurfaceFormatToWrImageFormat(aFormat).value();
      92           0 :     width = aSize.width;
      93           0 :     height = aSize.height;
      94           0 :     stride = 0;
      95           0 :     is_opaque = gfx::IsOpaqueFormat(aFormat);
      96           0 :   }
      97             : 
      98           0 :   ImageDescriptor(const gfx::IntSize& aSize, uint32_t aByteStride, gfx::SurfaceFormat aFormat)
      99           0 :   {
     100           0 :     format = SurfaceFormatToWrImageFormat(aFormat).value();
     101           0 :     width = aSize.width;
     102           0 :     height = aSize.height;
     103           0 :     stride = aByteStride;
     104           0 :     is_opaque = gfx::IsOpaqueFormat(aFormat);
     105           0 :   }
     106             : };
     107             : 
     108             : // Whenever possible, use wr::WindowId instead of manipulating uint64_t.
     109           0 : inline uint64_t AsUint64(const WindowId& aId) {
     110           0 :   return static_cast<uint64_t>(aId.mHandle);
     111             : }
     112             : 
     113             : // Whenever possible, use wr::ImageKey instead of manipulating uint64_t.
     114           0 : inline uint64_t AsUint64(const ImageKey& aId) {
     115           0 :   return (static_cast<uint64_t>(aId.mNamespace) << 32)
     116           0 :         + static_cast<uint64_t>(aId.mHandle);
     117             : }
     118             : 
     119           0 : inline ImageKey AsImageKey(const uint64_t& aId) {
     120             :   ImageKey imageKey;
     121           0 :   imageKey.mNamespace = aId >> 32;
     122           0 :   imageKey.mHandle = aId;
     123           0 :   return imageKey;
     124             : }
     125             : 
     126             : // Whenever possible, use wr::FontKey instead of manipulating uint64_t.
     127           0 : inline uint64_t AsUint64(const FontKey& aId) {
     128           0 :   return (static_cast<uint64_t>(aId.mNamespace) << 32)
     129           0 :         + static_cast<uint64_t>(aId.mHandle);
     130             : }
     131             : 
     132           0 : inline FontKey AsFontKey(const uint64_t& aId) {
     133             :   FontKey fontKey;
     134           0 :   fontKey.mNamespace = aId >> 32;
     135           0 :   fontKey.mHandle = aId;
     136           0 :   return fontKey;
     137             : }
     138             : 
     139             : // Whenever possible, use wr::PipelineId instead of manipulating uint64_t.
     140           0 : inline uint64_t AsUint64(const PipelineId& aId) {
     141           0 :   return (static_cast<uint64_t>(aId.mNamespace) << 32)
     142           0 :         + static_cast<uint64_t>(aId.mHandle);
     143             : }
     144             : 
     145           0 : inline PipelineId AsPipelineId(const uint64_t& aId) {
     146             :   PipelineId pipeline;
     147           0 :   pipeline.mNamespace = aId >> 32;
     148           0 :   pipeline.mHandle = aId;
     149           0 :   return pipeline;
     150             : }
     151             : 
     152           0 : inline ImageRendering ToImageRendering(gfx::SamplingFilter aFilter)
     153             : {
     154           0 :   return aFilter == gfx::SamplingFilter::POINT ? ImageRendering::Pixelated
     155           0 :                                                : ImageRendering::Auto;
     156             : }
     157             : 
     158           0 : static inline MixBlendMode ToWrMixBlendMode(gfx::CompositionOp compositionOp)
     159             : {
     160           0 :   switch (compositionOp)
     161             :   {
     162             :       case gfx::CompositionOp::OP_MULTIPLY:
     163           0 :         return MixBlendMode::Multiply;
     164             :       case gfx::CompositionOp::OP_SCREEN:
     165           0 :         return MixBlendMode::Screen;
     166             :       case gfx::CompositionOp::OP_OVERLAY:
     167           0 :         return MixBlendMode::Overlay;
     168             :       case gfx::CompositionOp::OP_DARKEN:
     169           0 :         return MixBlendMode::Darken;
     170             :       case gfx::CompositionOp::OP_LIGHTEN:
     171           0 :         return MixBlendMode::Lighten;
     172             :       case gfx::CompositionOp::OP_COLOR_DODGE:
     173           0 :         return MixBlendMode::ColorDodge;
     174             :       case gfx::CompositionOp::OP_COLOR_BURN:
     175           0 :         return MixBlendMode::ColorBurn;
     176             :       case gfx::CompositionOp::OP_HARD_LIGHT:
     177           0 :         return MixBlendMode::HardLight;
     178             :       case gfx::CompositionOp::OP_SOFT_LIGHT:
     179           0 :         return MixBlendMode::SoftLight;
     180             :       case gfx::CompositionOp::OP_DIFFERENCE:
     181           0 :         return MixBlendMode::Difference;
     182             :       case gfx::CompositionOp::OP_EXCLUSION:
     183           0 :         return MixBlendMode::Exclusion;
     184             :       case gfx::CompositionOp::OP_HUE:
     185           0 :         return MixBlendMode::Hue;
     186             :       case gfx::CompositionOp::OP_SATURATION:
     187           0 :         return MixBlendMode::Saturation;
     188             :       case gfx::CompositionOp::OP_COLOR:
     189           0 :         return MixBlendMode::Color;
     190             :       case gfx::CompositionOp::OP_LUMINOSITY:
     191           0 :         return MixBlendMode::Luminosity;
     192             :       default:
     193           0 :         return MixBlendMode::Normal;
     194             :   }
     195             : }
     196             : 
     197           0 : static inline WrColor ToWrColor(const gfx::Color& color)
     198             : {
     199             :   WrColor c;
     200           0 :   c.r = color.r;
     201           0 :   c.g = color.g;
     202           0 :   c.b = color.b;
     203           0 :   c.a = color.a;
     204           0 :   return c;
     205             : }
     206             : 
     207             : template<class T>
     208           0 : static inline WrPoint ToWrPoint(const gfx::PointTyped<T>& point)
     209             : {
     210             :   WrPoint p;
     211           0 :   p.x = point.x;
     212           0 :   p.y = point.y;
     213           0 :   return p;
     214             : }
     215             : 
     216             : template<class T>
     217             : static inline WrPoint ToWrPoint(const gfx::IntPointTyped<T>& point)
     218             : {
     219             :   return ToWrPoint(IntPointToPoint(point));
     220             : }
     221             : 
     222           0 : static inline WrPoint ToWrPoint(const gfx::Point& point)
     223             : {
     224             :   WrPoint p;
     225           0 :   p.x = point.x;
     226           0 :   p.y = point.y;
     227           0 :   return p;
     228             : }
     229             : 
     230             : template<class T>
     231           0 : static inline WrRect ToWrRect(const gfx::RectTyped<T>& rect)
     232             : {
     233             :   WrRect r;
     234           0 :   r.x = rect.x;
     235           0 :   r.y = rect.y;
     236           0 :   r.width = rect.width;
     237           0 :   r.height = rect.height;
     238           0 :   return r;
     239             : }
     240             : 
     241             : static inline WrRect ToWrRect(const gfxRect rect)
     242             : {
     243             :   WrRect r;
     244             :   r.x = rect.x;
     245             :   r.y = rect.y;
     246             :   r.width = rect.width;
     247             :   r.height = rect.height;
     248             :   return r;
     249             : }
     250             : 
     251             : template<class T>
     252           0 : static inline WrRect ToWrRect(const gfx::IntRectTyped<T>& rect)
     253             : {
     254           0 :   return ToWrRect(IntRectToRect(rect));
     255             : }
     256             : 
     257             : template<class T>
     258           0 : static inline WrSize ToWrSize(const gfx::SizeTyped<T>& size)
     259             : {
     260             :   WrSize ls;
     261           0 :   ls.width = size.width;
     262           0 :   ls.height = size.height;
     263           0 :   return ls;
     264             : }
     265             : 
     266             : static inline WrComplexClipRegion ToWrComplexClipRegion(const RoundedRect& rect)
     267             : {
     268             :   WrComplexClipRegion ret;
     269             :   ret.rect               = ToWrRect(rect.rect);
     270             :   ret.radii.top_left     = ToWrSize(rect.corners.radii[mozilla::eCornerTopLeft]);
     271             :   ret.radii.top_right    = ToWrSize(rect.corners.radii[mozilla::eCornerTopRight]);
     272             :   ret.radii.bottom_left  = ToWrSize(rect.corners.radii[mozilla::eCornerBottomLeft]);
     273             :   ret.radii.bottom_right = ToWrSize(rect.corners.radii[mozilla::eCornerBottomRight]);
     274             :   return ret;
     275             : }
     276             : 
     277             : template<class T>
     278             : static inline WrSize ToWrSize(const gfx::IntSizeTyped<T>& size)
     279             : {
     280             :   return ToWrSize(IntSizeToSize(size));
     281             : }
     282             : 
     283             : template<class S, class T>
     284           0 : static inline WrMatrix ToWrMatrix(const gfx::Matrix4x4Typed<S, T>& m)
     285             : {
     286             :   WrMatrix transform;
     287             :   static_assert(sizeof(m.components) == sizeof(transform.values),
     288             :       "Matrix components size mismatch!");
     289           0 :   memcpy(transform.values, m.components, sizeof(transform.values));
     290           0 :   return transform;
     291             : }
     292             : 
     293           0 : static inline WrBorderStyle ToWrBorderStyle(const uint8_t& style)
     294             : {
     295           0 :   switch (style) {
     296             :   case NS_STYLE_BORDER_STYLE_NONE:
     297           0 :     return WrBorderStyle::None;
     298             :   case NS_STYLE_BORDER_STYLE_SOLID:
     299           0 :     return WrBorderStyle::Solid;
     300             :   case NS_STYLE_BORDER_STYLE_DOUBLE:
     301           0 :     return WrBorderStyle::Double;
     302             :   case NS_STYLE_BORDER_STYLE_DOTTED:
     303           0 :     return WrBorderStyle::Dotted;
     304             :   case NS_STYLE_BORDER_STYLE_DASHED:
     305           0 :     return WrBorderStyle::Dashed;
     306             :   case NS_STYLE_BORDER_STYLE_HIDDEN:
     307           0 :     return WrBorderStyle::Hidden;
     308             :   case NS_STYLE_BORDER_STYLE_GROOVE:
     309           0 :     return WrBorderStyle::Groove;
     310             :   case NS_STYLE_BORDER_STYLE_RIDGE:
     311           0 :     return WrBorderStyle::Ridge;
     312             :   case NS_STYLE_BORDER_STYLE_INSET:
     313           0 :     return WrBorderStyle::Inset;
     314             :   case NS_STYLE_BORDER_STYLE_OUTSET:
     315           0 :     return WrBorderStyle::Outset;
     316             :   default:
     317           0 :     MOZ_ASSERT(false);
     318             :   }
     319             :   return WrBorderStyle::None;
     320             : }
     321             : 
     322           0 : static inline WrBorderSide ToWrBorderSide(const gfx::Color& color, const uint8_t& style)
     323             : {
     324             :   WrBorderSide bs;
     325           0 :   bs.color = ToWrColor(color);
     326           0 :   bs.style = ToWrBorderStyle(style);
     327           0 :   return bs;
     328             : }
     329             : 
     330             : static inline WrBorderRadius ToWrUniformBorderRadius(const LayerSize& aSize)
     331             : {
     332             :   WrBorderRadius br;
     333             :   br.top_left = ToWrSize(aSize);
     334             :   br.top_right = ToWrSize(aSize);
     335             :   br.bottom_left = ToWrSize(aSize);
     336             :   br.bottom_right = ToWrSize(aSize);
     337             :   return br;
     338             : }
     339             : 
     340           0 : static inline WrBorderRadius ToWrBorderRadius(const LayerSize& topLeft, const LayerSize& topRight,
     341             :                                               const LayerSize& bottomLeft, const LayerSize& bottomRight)
     342             : {
     343             :   WrBorderRadius br;
     344           0 :   br.top_left = ToWrSize(topLeft);
     345           0 :   br.top_right = ToWrSize(topRight);
     346           0 :   br.bottom_left = ToWrSize(bottomLeft);
     347           0 :   br.bottom_right = ToWrSize(bottomRight);
     348           0 :   return br;
     349             : }
     350             : 
     351           0 : static inline WrBorderWidths ToWrBorderWidths(float top, float right, float bottom, float left)
     352             : {
     353             :   WrBorderWidths bw;
     354           0 :   bw.top = top;
     355           0 :   bw.right = right;
     356           0 :   bw.bottom = bottom;
     357           0 :   bw.left = left;
     358           0 :   return bw;
     359             : }
     360             : 
     361           0 : static inline WrNinePatchDescriptor ToWrNinePatchDescriptor(uint32_t width, uint32_t height,
     362             :                                                             const WrSideOffsets2Du32& slice)
     363             : {
     364             :   WrNinePatchDescriptor patch;
     365           0 :   patch.width = width;
     366           0 :   patch.height = height;
     367           0 :   patch.slice = slice;
     368           0 :   return patch;
     369             : }
     370             : 
     371           0 : static inline WrSideOffsets2Du32 ToWrSideOffsets2Du32(uint32_t top, uint32_t right, uint32_t bottom, uint32_t left)
     372             : {
     373             :   WrSideOffsets2Du32 offset;
     374           0 :   offset.top = top;
     375           0 :   offset.right = right;
     376           0 :   offset.bottom = bottom;
     377           0 :   offset.left = left;
     378           0 :   return offset;
     379             : }
     380             : 
     381           0 : static inline WrSideOffsets2Df32 ToWrSideOffsets2Df32(float top, float right, float bottom, float left)
     382             : {
     383             :   WrSideOffsets2Df32 offset;
     384           0 :   offset.top = top;
     385           0 :   offset.right = right;
     386           0 :   offset.bottom = bottom;
     387           0 :   offset.left = left;
     388           0 :   return offset;
     389             : }
     390             : 
     391           0 : static inline WrRepeatMode ToWrRepeatMode(uint8_t repeatMode)
     392             : {
     393           0 :   switch (repeatMode) {
     394             :   case NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH:
     395           0 :     return WrRepeatMode::Stretch;
     396             :   case NS_STYLE_BORDER_IMAGE_REPEAT_REPEAT:
     397           0 :     return WrRepeatMode::Repeat;
     398             :   case NS_STYLE_BORDER_IMAGE_REPEAT_ROUND:
     399           0 :     return WrRepeatMode::Round;
     400             :   case NS_STYLE_BORDER_IMAGE_REPEAT_SPACE:
     401           0 :     return WrRepeatMode::Space;
     402             :   default:
     403           0 :     MOZ_ASSERT(false);
     404             :   }
     405             : 
     406             :   return WrRepeatMode::Stretch;
     407             : }
     408             : 
     409             : template<class S, class T>
     410           0 : static inline WrTransformProperty ToWrTransformProperty(uint64_t id,
     411             :                                                         const gfx::Matrix4x4Typed<S, T>& transform)
     412             : {
     413             :   WrTransformProperty prop;
     414           0 :   prop.id = id;
     415           0 :   prop.transform = ToWrMatrix(transform);
     416           0 :   return prop;
     417             : }
     418             : 
     419           0 : static inline WrOpacityProperty ToWrOpacityProperty(uint64_t id, const float opacity)
     420             : {
     421             :   WrOpacityProperty prop;
     422           0 :   prop.id = id;
     423           0 :   prop.opacity = opacity;
     424           0 :   return prop;
     425             : }
     426             : 
     427             : static inline WrComplexClipRegion ToWrComplexClipRegion(const WrRect& rect,
     428             :                                                         const LayerSize& size)
     429             : {
     430             :   WrComplexClipRegion complex_clip;
     431             :   complex_clip.rect = rect;
     432             :   complex_clip.radii = wr::ToWrUniformBorderRadius(size);
     433             :   return complex_clip;
     434             : }
     435             : 
     436             : template<class T>
     437             : static inline WrComplexClipRegion ToWrComplexClipRegion(const gfx::RectTyped<T>& rect,
     438             :                                                         const LayerSize& size)
     439             : {
     440             :   return ToWrComplexClipRegion(wr::ToWrRect(rect), size);
     441             : }
     442             : 
     443             : // Whenever possible, use wr::ExternalImageId instead of manipulating uint64_t.
     444           0 : inline uint64_t AsUint64(const ExternalImageId& aId) {
     445           0 :   return static_cast<uint64_t>(aId.mHandle);
     446             : }
     447             : 
     448           9 : static inline ExternalImageId ToExternalImageId(uint64_t aID)
     449             : {
     450             :   ExternalImageId Id;
     451           9 :   Id.mHandle = aID;
     452           9 :   return Id;
     453             : }
     454             : 
     455           0 : static inline WrExternalImage RawDataToWrExternalImage(const uint8_t* aBuff,
     456             :                                                        size_t size)
     457             : {
     458             :   return WrExternalImage {
     459             :     WrExternalImageType::RawData,
     460             :     0, 0.0f, 0.0f, 0.0f, 0.0f,
     461             :     aBuff, size
     462           0 :   };
     463             : }
     464             : 
     465           0 : static inline WrExternalImage NativeTextureToWrExternalImage(uint32_t aHandle,
     466             :                                                              float u0, float v0,
     467             :                                                              float u1, float v1)
     468             : {
     469             :   return WrExternalImage {
     470             :     WrExternalImageType::NativeTexture,
     471             :     aHandle, u0, v0, u1, v1,
     472             :     nullptr, 0
     473           0 :   };
     474             : }
     475             : 
     476             : struct VecU8 {
     477             :   WrVecU8 inner;
     478           0 :   VecU8() {
     479           0 :     SetEmpty();
     480           0 :   }
     481             :   VecU8(VecU8&) = delete;
     482             :   VecU8(VecU8&& src) {
     483             :     inner = src.inner;
     484             :     src.SetEmpty();
     485             :   }
     486             : 
     487             :   VecU8&
     488             :   operator=(VecU8&& src) {
     489             :     inner = src.inner;
     490             :     src.SetEmpty();
     491             :     return *this;
     492             :   }
     493             : 
     494             :   WrVecU8
     495             :   Extract() {
     496             :     WrVecU8 ret = inner;
     497             :     SetEmpty();
     498             :     return ret;
     499             :   }
     500             : 
     501             :   void
     502           0 :   SetEmpty() {
     503           0 :     inner.data = (uint8_t*)1;
     504           0 :     inner.capacity = 0;
     505           0 :     inner.length = 0;
     506           0 :   }
     507             : 
     508           0 :   ~VecU8() {
     509           0 :     if (inner.data) {
     510           0 :       wr_vec_u8_free(inner);
     511             :     }
     512           0 :   }
     513             : };
     514             : 
     515             : struct ByteBuffer
     516             : {
     517           0 :   ByteBuffer(size_t aLength, uint8_t* aData)
     518           0 :     : mLength(aLength)
     519             :     , mData(aData)
     520           0 :     , mOwned(false)
     521           0 :   {}
     522             : 
     523             :   // XXX: this is a bit of hack that assumes
     524             :   // the allocators are the same
     525           0 :   explicit ByteBuffer(VecU8&& vec)
     526           0 :   {
     527           0 :     if (vec.inner.capacity) {
     528           0 :       mLength = vec.inner.length;
     529           0 :       mData = vec.inner.data;
     530           0 :       vec.inner.data = nullptr;
     531           0 :       vec.inner.capacity = 0;
     532           0 :       mOwned = true;
     533             :     } else {
     534           0 :       mOwned = false;
     535           0 :       mData = nullptr;
     536           0 :       mLength = 0;
     537             :     }
     538           0 :   }
     539             : 
     540           0 :   ByteBuffer()
     541           0 :     : mLength(0)
     542             :     , mData(nullptr)
     543           0 :     , mOwned(false)
     544           0 :   {}
     545             : 
     546             :   bool
     547           0 :   Allocate(size_t aLength)
     548             :   {
     549           0 :     MOZ_ASSERT(mData == nullptr);
     550           0 :     mData = (uint8_t*)malloc(aLength);
     551           0 :     if (!mData) {
     552           0 :       return false;
     553             :     }
     554           0 :     mLength = aLength;
     555           0 :     mOwned = true;
     556           0 :     return true;
     557             :   }
     558             : 
     559           0 :   ~ByteBuffer()
     560           0 :   {
     561           0 :     if (mData && mOwned) {
     562           0 :       free(mData);
     563             :     }
     564           0 :   }
     565             : 
     566           0 :   const Range<uint8_t> AsSlice() const { return Range<uint8_t>(mData, mLength); }
     567             : 
     568             :   Range<uint8_t> AsSlice() { return Range<uint8_t>(mData, mLength); }
     569             : 
     570             :   bool operator==(const ByteBuffer& other) const {
     571             :     return mLength == other.mLength &&
     572             :           !(memcmp(mData, other.mData, mLength));
     573             :   }
     574             : 
     575             :   size_t mLength;
     576             :   uint8_t* mData;
     577             :   bool mOwned;
     578             : };
     579             : 
     580           0 : inline WrByteSlice RangeToByteSlice(mozilla::Range<uint8_t> aRange) {
     581           0 :   return WrByteSlice { aRange.begin().get(), aRange.length() };
     582             : }
     583             : 
     584           0 : inline mozilla::Range<const uint8_t> ByteSliceToRange(WrByteSlice aWrSlice) {
     585           0 :   return mozilla::Range<const uint8_t>(aWrSlice.buffer, aWrSlice.len);
     586             : }
     587             : 
     588           0 : inline mozilla::Range<uint8_t> MutByteSliceToRange(MutByteSlice aWrSlice) {
     589           0 :   return mozilla::Range<uint8_t>(aWrSlice.buffer, aWrSlice.len);
     590             : }
     591             : 
     592           0 : struct BuiltDisplayList {
     593             :   VecU8 dl;
     594             :   WrBuiltDisplayListDescriptor dl_desc;
     595             : };
     596             : 
     597           0 : static inline WrFilterOpType ToWrFilterOpType(const layers::CSSFilterType type) {
     598           0 :   switch (type) {
     599             :     case layers::CSSFilterType::BLUR:
     600           0 :       return WrFilterOpType::Blur;
     601             :     case layers::CSSFilterType::BRIGHTNESS:
     602           0 :       return WrFilterOpType::Brightness;
     603             :     case layers::CSSFilterType::CONTRAST:
     604           0 :       return WrFilterOpType::Contrast;
     605             :     case layers::CSSFilterType::GRAYSCALE:
     606           0 :       return WrFilterOpType::Grayscale;
     607             :     case layers::CSSFilterType::HUE_ROTATE:
     608           0 :       return WrFilterOpType::HueRotate;
     609             :     case layers::CSSFilterType::INVERT:
     610           0 :       return WrFilterOpType::Invert;
     611             :     case layers::CSSFilterType::OPACITY:
     612           0 :       return WrFilterOpType::Opacity;
     613             :     case layers::CSSFilterType::SATURATE:
     614           0 :       return WrFilterOpType::Saturate;
     615             :     case layers::CSSFilterType::SEPIA:
     616           0 :       return WrFilterOpType::Sepia;
     617             :   }
     618           0 :   MOZ_ASSERT_UNREACHABLE("Tried to convert unknown filter type.");
     619             :   return WrFilterOpType::Grayscale;
     620             : }
     621             : 
     622           0 : static inline WrFilterOp ToWrFilterOp(const layers::CSSFilter& filter) {
     623             :   return {
     624           0 :     ToWrFilterOpType(filter.type),
     625           0 :     filter.argument,
     626           0 :   };
     627             : }
     628             : 
     629             : // Corresponds to an "internal" webrender clip id. That is, a
     630             : // ClipId::Clip(x,pipeline_id) maps to a WrClipId{x}. We use a struct wrapper
     631             : // instead of a typedef so that this is a distinct type from FrameMetrics::ViewID
     632             : // and the compiler will catch accidental conversions between the two.
     633             : struct WrClipId {
     634             :   uint64_t id;
     635             : };
     636             : 
     637             : } // namespace wr
     638             : } // namespace mozilla
     639             : 
     640             : #endif /* GFX_WEBRENDERTYPES_H */

Generated by: LCOV version 1.13