SourceSurfaceCairo.h (2240B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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_GFX_OP_SOURCESURFACE_CAIRO_H 8 #define _MOZILLA_GFX_OP_SOURCESURFACE_CAIRO_H 9 10 #include "2D.h" 11 12 namespace mozilla { 13 namespace gfx { 14 15 class DrawTargetCairo; 16 17 class SourceSurfaceCairo : public SourceSurface { 18 public: 19 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceCairo, override) 20 21 // Create a SourceSurfaceCairo. The surface will not be copied, but simply 22 // referenced. 23 // If aDrawTarget is non-nullptr, it is assumed that this is a snapshot source 24 // surface, and we'll call DrawTargetCairo::RemoveSnapshot(this) on it when 25 // we're destroyed. 26 SourceSurfaceCairo(cairo_surface_t* aSurface, const IntSize& aSize, 27 const SurfaceFormat& aFormat, 28 DrawTargetCairo* aDrawTarget = nullptr); 29 virtual ~SourceSurfaceCairo(); 30 31 SurfaceType GetType() const override { return SurfaceType::CAIRO; } 32 IntSize GetSize() const override; 33 SurfaceFormat GetFormat() const override; 34 already_AddRefed<DataSourceSurface> GetDataSurface() override; 35 36 cairo_surface_t* GetSurface() const; 37 38 private: // methods 39 friend class DrawTargetCairo; 40 void DrawTargetWillChange(); 41 42 private: // data 43 IntSize mSize; 44 SurfaceFormat mFormat; 45 cairo_surface_t* mSurface; 46 DrawTargetCairo* mDrawTarget; 47 }; 48 49 class DataSourceSurfaceCairo : public DataSourceSurface { 50 public: 51 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceCairo, override) 52 53 explicit DataSourceSurfaceCairo(cairo_surface_t* imageSurf); 54 virtual ~DataSourceSurfaceCairo(); 55 unsigned char* GetData() override; 56 int32_t Stride() override; 57 58 SurfaceType GetType() const override { return SurfaceType::CAIRO_IMAGE; } 59 IntSize GetSize() const override; 60 SurfaceFormat GetFormat() const override; 61 62 cairo_surface_t* GetSurface() const; 63 64 private: 65 cairo_surface_t* mImageSurface; 66 }; 67 68 } // namespace gfx 69 } // namespace mozilla 70 71 #endif // _MOZILLA_GFX_OP_SOURCESURFACE_CAIRO_H