michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _MOZILLA_GFX_SOURCESURFACESKIA_H michael@0: #define _MOZILLA_GFX_SOURCESURFACESKIA_H michael@0: michael@0: #ifdef USE_SKIA_GPU michael@0: #include "skia/GrContext.h" michael@0: #include "skia/GrGLInterface.h" michael@0: #endif michael@0: michael@0: #include "skia/SkCanvas.h" michael@0: michael@0: #include "2D.h" michael@0: #include "Rect.h" michael@0: #include "PathSkia.h" michael@0: #include michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: class SourceSurfaceSkia; michael@0: michael@0: class DrawTargetSkia : public DrawTarget michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetSkia) michael@0: DrawTargetSkia(); michael@0: virtual ~DrawTargetSkia(); michael@0: michael@0: virtual BackendType GetType() const { return BackendType::SKIA; } michael@0: virtual TemporaryRef Snapshot(); michael@0: virtual IntSize GetSize() { return mSize; } michael@0: virtual void Flush(); michael@0: virtual void DrawSurface(SourceSurface *aSurface, michael@0: const Rect &aDest, michael@0: const Rect &aSource, michael@0: const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(), michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void DrawFilter(FilterNode *aNode, michael@0: const Rect &aSourceRect, michael@0: const Point &aDestPoint, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, michael@0: const Point &aDest, michael@0: const Color &aColor, michael@0: const Point &aOffset, michael@0: Float aSigma, michael@0: CompositionOp aOperator); michael@0: virtual void ClearRect(const Rect &aRect); michael@0: virtual void CopySurface(SourceSurface *aSurface, michael@0: const IntRect &aSourceRect, michael@0: const IntPoint &aDestination); michael@0: virtual void FillRect(const Rect &aRect, michael@0: const Pattern &aPattern, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void StrokeRect(const Rect &aRect, michael@0: const Pattern &aPattern, michael@0: const StrokeOptions &aStrokeOptions = StrokeOptions(), michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void StrokeLine(const Point &aStart, michael@0: const Point &aEnd, michael@0: const Pattern &aPattern, michael@0: const StrokeOptions &aStrokeOptions = StrokeOptions(), michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void Stroke(const Path *aPath, michael@0: const Pattern &aPattern, michael@0: const StrokeOptions &aStrokeOptions = StrokeOptions(), michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void Fill(const Path *aPath, michael@0: const Pattern &aPattern, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void FillGlyphs(ScaledFont *aFont, michael@0: const GlyphBuffer &aBuffer, michael@0: const Pattern &aPattern, michael@0: const DrawOptions &aOptions = DrawOptions(), michael@0: const GlyphRenderingOptions *aRenderingOptions = nullptr); michael@0: virtual void Mask(const Pattern &aSource, michael@0: const Pattern &aMask, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void MaskSurface(const Pattern &aSource, michael@0: SourceSurface *aMask, michael@0: Point aOffset, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: virtual void PushClip(const Path *aPath); michael@0: virtual void PushClipRect(const Rect& aRect); michael@0: virtual void PopClip(); michael@0: virtual TemporaryRef CreateSourceSurfaceFromData(unsigned char *aData, michael@0: const IntSize &aSize, michael@0: int32_t aStride, michael@0: SurfaceFormat aFormat) const; michael@0: virtual TemporaryRef OptimizeSourceSurface(SourceSurface *aSurface) const; michael@0: virtual TemporaryRef michael@0: CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const; michael@0: virtual TemporaryRef michael@0: CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const; michael@0: virtual TemporaryRef CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const; michael@0: virtual TemporaryRef CreateGradientStops(GradientStop *aStops, uint32_t aNumStops, ExtendMode aExtendMode = ExtendMode::CLAMP) const; michael@0: virtual TemporaryRef CreateFilter(FilterType aType); michael@0: virtual void SetTransform(const Matrix &aTransform); michael@0: virtual void *GetNativeSurface(NativeSurfaceType aType); michael@0: michael@0: bool Init(const IntSize &aSize, SurfaceFormat aFormat); michael@0: void Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat); michael@0: michael@0: #ifdef USE_SKIA_GPU michael@0: bool InitWithGrContext(GrContext* aGrContext, michael@0: const IntSize &aSize, michael@0: SurfaceFormat aFormat) MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: operator std::string() const { michael@0: std::stringstream stream; michael@0: stream << "DrawTargetSkia(" << this << ")"; michael@0: return stream.str(); michael@0: } michael@0: michael@0: private: michael@0: friend class SourceSurfaceSkia; michael@0: void SnapshotDestroyed(); michael@0: michael@0: void MarkChanged(); michael@0: michael@0: SkRect SkRectCoveringWholeSurface() const; michael@0: michael@0: #ifdef USE_SKIA_GPU michael@0: SkRefPtr mGrContext; michael@0: uint32_t mTexture; michael@0: #endif michael@0: michael@0: IntSize mSize; michael@0: SkRefPtr mCanvas; michael@0: SourceSurfaceSkia* mSnapshot; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif // _MOZILLA_GFX_SOURCESURFACESKIA_H