2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2014-04-16 20:17:22 +04:00
|
|
|
#ifndef _MOZILLA_GFX_SOURCESURFACESKIA_H
|
|
|
|
#define _MOZILLA_GFX_SOURCESURFACESKIA_H
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2015-07-29 23:31:40 +03:00
|
|
|
#include "skia/include/core/SkCanvas.h"
|
2016-10-25 05:40:59 +03:00
|
|
|
#include "skia/include/core/SkSurface.h"
|
2013-03-14 03:29:47 +04:00
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
#include "2D.h"
|
2014-08-06 20:01:44 +04:00
|
|
|
#include "HelpersSkia.h"
|
2011-11-02 23:55:03 +04:00
|
|
|
#include "Rect.h"
|
|
|
|
#include "PathSkia.h"
|
|
|
|
#include <sstream>
|
2011-11-02 23:55:03 +04:00
|
|
|
#include <vector>
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2016-05-17 21:41:38 +03:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
|
|
|
# include <ApplicationServices/ApplicationServices.h>
|
|
|
|
#endif
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
class SourceSurfaceSkia;
|
2017-02-12 17:24:44 +03:00
|
|
|
class BorrowedCGContext;
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
class DrawTargetSkia : public DrawTarget {
|
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetSkia, override)
|
2011-11-02 23:55:03 +04:00
|
|
|
DrawTargetSkia();
|
|
|
|
virtual ~DrawTargetSkia();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual DrawTargetType GetType() const override;
|
|
|
|
virtual BackendType GetBackendType() const override {
|
|
|
|
return BackendType::SKIA;
|
|
|
|
}
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> Snapshot() override;
|
2018-01-23 20:10:11 +03:00
|
|
|
virtual IntSize GetSize() const override { return mSize; };
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual bool LockBits(uint8_t** aData, IntSize* aSize, int32_t* aStride,
|
|
|
|
SurfaceFormat* aFormat,
|
|
|
|
IntPoint* aOrigin = nullptr) override;
|
|
|
|
virtual void ReleaseBits(uint8_t* aData) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Flush() override;
|
2011-11-02 23:55:03 +04:00
|
|
|
virtual void DrawSurface(
|
2019-05-01 11:47:10 +03:00
|
|
|
SourceSurface* aSurface, const Rect& aDest, const Rect& aSource,
|
|
|
|
const DrawSurfaceOptions& aSurfOptions = DrawSurfaceOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual void DrawFilter(FilterNode* aNode, const Rect& aSourceRect,
|
|
|
|
const Point& aDestPoint,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual void DrawSurfaceWithShadow(SourceSurface* aSurface,
|
|
|
|
const Point& aDest, const Color& aColor,
|
|
|
|
const Point& aOffset, Float aSigma,
|
2015-03-21 19:28:04 +03:00
|
|
|
CompositionOp aOperator) override;
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void ClearRect(const Rect& aRect) override;
|
|
|
|
virtual void CopySurface(SourceSurface* aSurface, const IntRect& aSourceRect,
|
|
|
|
const IntPoint& aDestination) override;
|
|
|
|
virtual void FillRect(const Rect& aRect, const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual void StrokeRect(const Rect& aRect, const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions = StrokeOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual void StrokeLine(const Point& aStart, const Point& aEnd,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions = StrokeOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual void Stroke(const Path* aPath, const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions = StrokeOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual void Fill(const Path* aPath, const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
|
|
|
|
virtual void FillGlyphs(ScaledFont* aFont, const GlyphBuffer& aBuffer,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2017-02-12 17:24:44 +03:00
|
|
|
virtual void StrokeGlyphs(
|
2019-05-01 11:47:10 +03:00
|
|
|
ScaledFont* aFont, const GlyphBuffer& aBuffer, const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions = StrokeOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual void Mask(const Pattern& aSource, const Pattern& aMask,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2013-06-28 00:20:30 +04:00
|
|
|
virtual void MaskSurface(
|
2019-05-01 11:47:10 +03:00
|
|
|
const Pattern& aSource, SourceSurface* aMask, Point aOffset,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
virtual bool Draw3DTransformedSurface(SourceSurface* aSurface,
|
|
|
|
const Matrix4x4& aMatrix) override;
|
|
|
|
virtual void PushClip(const Path* aPath) override;
|
|
|
|
virtual void PushClipRect(const Rect& aRect) override;
|
|
|
|
virtual void PushDeviceSpaceClipRects(const IntRect* aRects,
|
2016-09-22 00:03:20 +03:00
|
|
|
uint32_t aCount) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void PopClip() override;
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void PushLayer(bool aOpaque, Float aOpacity, SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform,
|
|
|
|
const IntRect& aBounds = IntRect(),
|
2016-01-13 07:30:33 +03:00
|
|
|
bool aCopyBackground = false) override;
|
2018-02-17 20:07:30 +03:00
|
|
|
virtual void PushLayerWithBlend(
|
2019-05-01 11:47:10 +03:00
|
|
|
bool aOpaque, Float aOpacity, SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform, const IntRect& aBounds = IntRect(),
|
2018-02-17 20:07:30 +03:00
|
|
|
bool aCopyBackground = false,
|
|
|
|
CompositionOp aCompositionOp = CompositionOp::OP_OVER) override;
|
2016-01-13 07:30:33 +03:00
|
|
|
virtual void PopLayer() override;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(
|
2019-05-01 11:47:10 +03:00
|
|
|
unsigned char* aData, const IntSize& aSize, int32_t aStride,
|
2015-03-21 19:28:04 +03:00
|
|
|
SurfaceFormat aFormat) const override;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(
|
2019-05-01 11:47:10 +03:00
|
|
|
SourceSurface* aSurface) const override;
|
2016-08-05 20:29:12 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> OptimizeSourceSurfaceForUnknownAlpha(
|
2019-05-01 11:47:10 +03:00
|
|
|
SourceSurface* aSurface) const override;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromNativeSurface(
|
2019-05-01 11:47:10 +03:00
|
|
|
const NativeSurface& aSurface) const override;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<DrawTarget> CreateSimilarDrawTarget(
|
2019-05-01 11:47:10 +03:00
|
|
|
const IntSize& aSize, SurfaceFormat aFormat) const override;
|
|
|
|
virtual bool CanCreateSimilarDrawTarget(const IntSize& aSize,
|
2018-11-13 13:39:02 +03:00
|
|
|
SurfaceFormat aFormat) const override;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<PathBuilder> CreatePathBuilder(
|
|
|
|
FillRule aFillRule = FillRule::FILL_WINDING) const override;
|
|
|
|
virtual already_AddRefed<GradientStops> CreateGradientStops(
|
2019-05-01 11:47:10 +03:00
|
|
|
GradientStop* aStops, uint32_t aNumStops,
|
2015-06-17 17:00:52 +03:00
|
|
|
ExtendMode aExtendMode = ExtendMode::CLAMP) const override;
|
|
|
|
virtual already_AddRefed<FilterNode> CreateFilter(FilterType aType) override;
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void SetTransform(const Matrix& aTransform) override;
|
|
|
|
virtual void* GetNativeSurface(NativeSurfaceType aType) override;
|
2016-07-01 11:58:13 +03:00
|
|
|
virtual void DetachAllSnapshots() override { MarkChanged(); }
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool Init(const IntSize& aSize, SurfaceFormat aFormat);
|
|
|
|
bool Init(unsigned char* aData, const IntSize& aSize, int32_t aStride,
|
2016-10-25 05:40:59 +03:00
|
|
|
SurfaceFormat aFormat, bool aUninitialized = false);
|
2019-05-01 11:47:10 +03:00
|
|
|
bool Init(SkCanvas* aCanvas);
|
2013-06-17 06:07:18 +04:00
|
|
|
|
2015-11-19 21:35:31 +03:00
|
|
|
// Skia assumes that texture sizes fit in 16-bit signed integers.
|
|
|
|
static size_t GetMaxSurfaceSize() { return 32767; }
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
operator std::string() const {
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << "DrawTargetSkia(" << this << ")";
|
|
|
|
return stream.str();
|
|
|
|
}
|
2013-05-29 20:49:40 +04:00
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
private:
|
2011-11-02 23:55:03 +04:00
|
|
|
friend class SourceSurfaceSkia;
|
|
|
|
|
|
|
|
void MarkChanged();
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2015-05-04 20:23:54 +03:00
|
|
|
bool ShouldLCDRenderText(FontType aFontType, AntialiasMode aAntialiasMode);
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void DrawGlyphs(ScaledFont* aFont, const GlyphBuffer& aBuffer,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const StrokeOptions* aStrokeOptions = nullptr,
|
|
|
|
const DrawOptions& aOptions = DrawOptions());
|
2017-02-12 17:24:44 +03:00
|
|
|
|
2016-01-13 07:30:33 +03:00
|
|
|
struct PushedLayer {
|
2019-05-01 11:47:10 +03:00
|
|
|
PushedLayer(bool aOldPermitSubpixelAA, SourceSurface* aMask)
|
2016-01-13 07:30:33 +03:00
|
|
|
: mOldPermitSubpixelAA(aOldPermitSubpixelAA), mMask(aMask) {}
|
|
|
|
bool mOldPermitSubpixelAA;
|
|
|
|
RefPtr<SourceSurface> mMask;
|
|
|
|
};
|
|
|
|
std::vector<PushedLayer> mPushedLayers;
|
|
|
|
|
2013-06-17 21:45:04 +04:00
|
|
|
IntSize mSize;
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkSurface> mSurface;
|
2019-05-01 11:47:10 +03:00
|
|
|
SkCanvas* mCanvas;
|
2017-12-06 06:59:19 +03:00
|
|
|
RefPtr<SourceSurfaceSkia> mSnapshot;
|
|
|
|
Mutex mSnapshotLock;
|
2016-05-17 21:41:38 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2017-02-12 17:24:44 +03:00
|
|
|
friend class BorrowedCGContext;
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
CGContextRef BorrowCGContext(const DrawOptions& aOptions);
|
2017-02-12 17:24:44 +03:00
|
|
|
void ReturnCGContext(CGContextRef);
|
2019-05-01 11:47:10 +03:00
|
|
|
bool FillGlyphsWithCG(ScaledFont* aFont, const GlyphBuffer& aBuffer,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions = DrawOptions());
|
2017-02-12 17:24:44 +03:00
|
|
|
|
2016-05-17 21:41:38 +03:00
|
|
|
CGContextRef mCG;
|
|
|
|
CGColorSpaceRef mColorSpace;
|
2019-05-01 11:47:10 +03:00
|
|
|
uint8_t* mCanvasData;
|
2016-05-17 21:41:38 +03:00
|
|
|
IntSize mCGSize;
|
2017-05-10 23:21:13 +03:00
|
|
|
bool mNeedLayer;
|
2016-05-17 21:41:38 +03:00
|
|
|
#endif
|
2011-11-02 23:55:03 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2014-04-16 20:17:22 +04:00
|
|
|
|
|
|
|
#endif // _MOZILLA_GFX_SOURCESURFACESKIA_H
|