2011-11-02 23:55:03 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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
|
|
|
|
|
|
|
#include "DrawTargetSkia.h"
|
|
|
|
#include "SourceSurfaceSkia.h"
|
2012-01-09 22:54:44 +04:00
|
|
|
#include "ScaledFontBase.h"
|
2013-06-05 21:48:59 +04:00
|
|
|
#include "ScaledFontCairo.h"
|
2013-11-27 15:25:28 +04:00
|
|
|
#include "FilterNodeSoftware.h"
|
2015-09-02 21:12:32 +03:00
|
|
|
#include "HelpersSkia.h"
|
2013-03-14 03:29:47 +04:00
|
|
|
|
2016-09-07 21:42:15 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
|
|
|
|
2015-12-18 21:53:25 +03:00
|
|
|
#include "skia/include/core/SkSurface.h"
|
2015-07-29 23:31:40 +03:00
|
|
|
#include "skia/include/core/SkTypeface.h"
|
|
|
|
#include "skia/include/effects/SkGradientShader.h"
|
|
|
|
#include "skia/include/core/SkColorFilter.h"
|
2017-05-15 13:14:38 +03:00
|
|
|
#include "skia/include/core/SkRegion.h"
|
2015-09-04 22:29:11 +03:00
|
|
|
#include "skia/include/effects/SkBlurImageFilter.h"
|
2015-07-29 23:31:40 +03:00
|
|
|
#include "skia/include/effects/SkLayerRasterizer.h"
|
2017-05-10 05:31:07 +03:00
|
|
|
#include "skia/src/core/SkDevice.h"
|
2016-03-26 05:14:50 +03:00
|
|
|
#include "Blur.h"
|
2011-11-02 23:55:03 +04:00
|
|
|
#include "Logging.h"
|
|
|
|
#include "Tools.h"
|
2013-11-03 20:28:30 +04:00
|
|
|
#include "DataSurfaceHelpers.h"
|
2017-02-28 23:47:46 +03:00
|
|
|
#include "PathHelpers.h"
|
2017-02-12 17:28:12 +03:00
|
|
|
#include "Swizzle.h"
|
2011-11-02 23:55:03 +04:00
|
|
|
#include <algorithm>
|
|
|
|
|
2016-01-21 17:51:40 +03:00
|
|
|
#ifdef USE_SKIA_GPU
|
|
|
|
#include "GLDefs.h"
|
|
|
|
#include "skia/include/gpu/GrContext.h"
|
|
|
|
#include "skia/include/gpu/gl/GrGLInterface.h"
|
2017-05-10 05:31:07 +03:00
|
|
|
#include "skia/src/gpu/GrRenderTargetContext.h"
|
2016-10-25 05:40:59 +03:00
|
|
|
#include "skia/src/image/SkImage_Gpu.h"
|
2016-01-21 17:51:40 +03:00
|
|
|
#endif
|
|
|
|
|
2016-05-17 21:41:38 +03:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2016-08-03 17:53:12 +03:00
|
|
|
#include "BorrowedContext.h"
|
2016-05-17 21:41:38 +03:00
|
|
|
#include <ApplicationServices/ApplicationServices.h>
|
|
|
|
#include "mozilla/Vector.h"
|
|
|
|
#include "ScaledFontMac.h"
|
|
|
|
#include "CGTextDrawing.h"
|
|
|
|
#endif
|
|
|
|
|
2016-09-08 19:34:10 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "ScaledFontDWrite.h"
|
|
|
|
#endif
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
class GradientStopsSkia : public GradientStops
|
|
|
|
{
|
|
|
|
public:
|
2014-02-24 17:23:37 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GradientStopsSkia)
|
2012-01-19 08:48:33 +04:00
|
|
|
GradientStopsSkia(const std::vector<GradientStop>& aStops, uint32_t aNumStops, ExtendMode aExtendMode)
|
2011-11-02 23:55:03 +04:00
|
|
|
: mCount(aNumStops)
|
2012-01-19 08:48:33 +04:00
|
|
|
, mExtendMode(aExtendMode)
|
2011-11-02 23:55:03 +04:00
|
|
|
{
|
|
|
|
if (mCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skia gradients always require a stop at 0.0 and 1.0, insert these if
|
|
|
|
// we don't have them.
|
|
|
|
uint32_t shift = 0;
|
|
|
|
if (aStops[0].offset != 0) {
|
|
|
|
mCount++;
|
|
|
|
shift = 1;
|
|
|
|
}
|
|
|
|
if (aStops[aNumStops-1].offset != 1) {
|
|
|
|
mCount++;
|
|
|
|
}
|
|
|
|
mColors.resize(mCount);
|
|
|
|
mPositions.resize(mCount);
|
|
|
|
if (aStops[0].offset != 0) {
|
|
|
|
mColors[0] = ColorToSkColor(aStops[0].color, 1.0);
|
|
|
|
mPositions[0] = 0;
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < aNumStops; i++) {
|
|
|
|
mColors[i + shift] = ColorToSkColor(aStops[i].color, 1.0);
|
|
|
|
mPositions[i + shift] = SkFloatToScalar(aStops[i].offset);
|
|
|
|
}
|
|
|
|
if (aStops[aNumStops-1].offset != 1) {
|
|
|
|
mColors[mCount-1] = ColorToSkColor(aStops[aNumStops-1].color, 1.0);
|
|
|
|
mPositions[mCount-1] = SK_Scalar1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 23:06:16 +04:00
|
|
|
BackendType GetBackendType() const { return BackendType::SKIA; }
|
2011-11-02 23:55:03 +04:00
|
|
|
|
|
|
|
std::vector<SkColor> mColors;
|
|
|
|
std::vector<SkScalar> mPositions;
|
|
|
|
int mCount;
|
2012-01-19 08:48:33 +04:00
|
|
|
ExtendMode mExtendMode;
|
2011-11-02 23:55:03 +04:00
|
|
|
};
|
|
|
|
|
2014-01-13 04:29:48 +04:00
|
|
|
/**
|
2016-10-25 05:40:59 +03:00
|
|
|
* When constructing a temporary SkImage via GetSkImageForSurface, we may also
|
2014-01-13 04:29:48 +04:00
|
|
|
* have to construct a temporary DataSourceSurface, which must live as long as
|
2016-10-25 05:40:59 +03:00
|
|
|
* the SkImage. We attach this temporary surface to the image's pixelref, so
|
2016-01-12 21:05:13 +03:00
|
|
|
* that it can be released once the pixelref is freed.
|
2014-01-13 04:29:48 +04:00
|
|
|
*/
|
2016-01-12 21:05:13 +03:00
|
|
|
static void
|
2016-10-25 05:40:59 +03:00
|
|
|
ReleaseTemporarySurface(const void* aPixels, void* aContext)
|
2014-01-13 04:29:48 +04:00
|
|
|
{
|
2016-01-12 21:05:13 +03:00
|
|
|
DataSourceSurface* surf = static_cast<DataSourceSurface*>(aContext);
|
|
|
|
if (surf) {
|
|
|
|
surf->Release();
|
|
|
|
}
|
|
|
|
}
|
2014-01-13 04:29:48 +04:00
|
|
|
|
2016-08-05 20:29:12 +03:00
|
|
|
static void
|
|
|
|
WriteRGBXFormat(uint8_t* aData, const IntSize &aSize,
|
|
|
|
const int32_t aStride, SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
if (aFormat != SurfaceFormat::B8G8R8X8 || aSize.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-12 17:28:12 +03:00
|
|
|
SwizzleData(aData, aStride, SurfaceFormat::X8R8G8B8_UINT32,
|
|
|
|
aData, aStride, SurfaceFormat::A8R8G8B8_UINT32,
|
|
|
|
aSize);
|
2016-08-05 20:29:12 +03:00
|
|
|
}
|
|
|
|
|
2016-07-26 02:36:35 +03:00
|
|
|
#ifdef DEBUG
|
2016-08-18 16:55:45 +03:00
|
|
|
static IntRect
|
|
|
|
CalculateSurfaceBounds(const IntSize &aSize, const Rect* aBounds, const Matrix* aMatrix)
|
|
|
|
{
|
|
|
|
IntRect surfaceBounds(IntPoint(0, 0), aSize);
|
|
|
|
if (!aBounds) {
|
|
|
|
return surfaceBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aMatrix);
|
|
|
|
Matrix inverse(*aMatrix);
|
|
|
|
if (!inverse.Invert()) {
|
|
|
|
return surfaceBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntRect bounds;
|
|
|
|
Rect sampledBounds = inverse.TransformBounds(*aBounds);
|
|
|
|
if (!sampledBounds.ToIntRect(&bounds)) {
|
|
|
|
return surfaceBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
return surfaceBounds.Intersect(bounds);
|
|
|
|
}
|
|
|
|
|
2017-02-12 17:28:12 +03:00
|
|
|
static const int kARGBAlphaOffset = SurfaceFormat::A8R8G8B8_UINT32 == SurfaceFormat::B8G8R8A8 ? 3 : 0;
|
|
|
|
|
2016-07-26 02:36:35 +03:00
|
|
|
static bool
|
|
|
|
VerifyRGBXFormat(uint8_t* aData, const IntSize &aSize, const int32_t aStride, SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
if (aFormat != SurfaceFormat::B8G8R8X8 || aSize.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// We should've initialized the data to be opaque already
|
|
|
|
// On debug builds, verify that this is actually true.
|
|
|
|
int height = aSize.height;
|
2016-08-05 20:26:33 +03:00
|
|
|
int width = aSize.width * 4;
|
2016-07-26 02:36:35 +03:00
|
|
|
|
|
|
|
for (int row = 0; row < height; ++row) {
|
|
|
|
for (int column = 0; column < width; column += 4) {
|
2016-09-07 21:42:15 +03:00
|
|
|
if (aData[column + kARGBAlphaOffset] != 0xFF) {
|
|
|
|
gfxCriticalError() << "RGBX pixel at (" << column << "," << row << ") in "
|
|
|
|
<< width << "x" << height << " surface is not opaque: "
|
|
|
|
<< int(aData[column]) << ","
|
|
|
|
<< int(aData[column+1]) << ","
|
|
|
|
<< int(aData[column+2]) << ","
|
|
|
|
<< int(aData[column+3]);
|
|
|
|
}
|
2016-07-26 02:36:35 +03:00
|
|
|
}
|
|
|
|
aData += aStride;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since checking every pixel is expensive, this only checks the four corners and center
|
|
|
|
// of a surface that their alpha value is 0xFF.
|
|
|
|
static bool
|
2016-08-18 16:55:45 +03:00
|
|
|
VerifyRGBXCorners(uint8_t* aData, const IntSize &aSize, const int32_t aStride, SurfaceFormat aFormat, const Rect* aBounds = nullptr, const Matrix* aMatrix = nullptr)
|
2016-07-26 02:36:35 +03:00
|
|
|
{
|
|
|
|
if (aFormat != SurfaceFormat::B8G8R8X8 || aSize.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-18 16:55:45 +03:00
|
|
|
IntRect bounds = CalculateSurfaceBounds(aSize, aBounds, aMatrix);
|
|
|
|
if (bounds.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-14 15:29:28 +03:00
|
|
|
const int height = bounds.Height();
|
|
|
|
const int width = bounds.Width();
|
2016-07-26 02:36:35 +03:00
|
|
|
const int pixelSize = 4;
|
2016-08-18 16:55:45 +03:00
|
|
|
MOZ_ASSERT(aSize.width * pixelSize <= aStride);
|
2016-07-26 02:36:35 +03:00
|
|
|
|
2016-08-18 16:55:45 +03:00
|
|
|
const int translation = bounds.y * aStride + bounds.x * pixelSize;
|
|
|
|
const int topLeft = translation;
|
|
|
|
const int topRight = topLeft + (width - 1) * pixelSize;
|
|
|
|
const int bottomLeft = translation + (height - 1) * aStride;
|
|
|
|
const int bottomRight = bottomLeft + (width - 1) * pixelSize;
|
2016-07-26 02:36:35 +03:00
|
|
|
|
|
|
|
// Lastly the center pixel
|
2016-08-18 16:55:45 +03:00
|
|
|
const int middleRowHeight = height / 2;
|
|
|
|
const int middleRowWidth = (width / 2) * pixelSize;
|
|
|
|
const int middle = translation + aStride * middleRowHeight + middleRowWidth;
|
2016-09-07 21:42:15 +03:00
|
|
|
|
|
|
|
const int offsets[] = { topLeft, topRight, bottomRight, bottomLeft, middle };
|
2016-11-15 11:55:49 +03:00
|
|
|
for (int offset : offsets) {
|
2016-09-29 02:20:13 +03:00
|
|
|
if (aData[offset + kARGBAlphaOffset] != 0xFF) {
|
2016-09-07 21:42:15 +03:00
|
|
|
int row = offset / aStride;
|
|
|
|
int column = (offset % aStride) / pixelSize;
|
|
|
|
gfxCriticalError() << "RGBX corner pixel at (" << column << "," << row << ") in "
|
2016-08-18 16:55:45 +03:00
|
|
|
<< aSize.width << "x" << aSize.height << " surface, bounded by "
|
|
|
|
<< "(" << bounds.x << "," << bounds.y << "," << width << ","
|
|
|
|
<< height << ") is not opaque: "
|
2016-09-29 02:20:13 +03:00
|
|
|
<< int(aData[offset]) << ","
|
|
|
|
<< int(aData[offset+1]) << ","
|
|
|
|
<< int(aData[offset+2]) << ","
|
|
|
|
<< int(aData[offset+3]);
|
2016-09-07 21:42:15 +03:00
|
|
|
}
|
|
|
|
}
|
2016-07-26 02:36:35 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
static sk_sp<SkImage>
|
2016-08-18 16:55:45 +03:00
|
|
|
GetSkImageForSurface(SourceSurface* aSurface, const Rect* aBounds = nullptr, const Matrix* aMatrix = nullptr)
|
2014-01-13 04:29:48 +04:00
|
|
|
{
|
2016-04-14 23:20:12 +03:00
|
|
|
if (!aSurface) {
|
2016-10-25 05:40:59 +03:00
|
|
|
gfxDebug() << "Creating null Skia image from null SourceSurface";
|
|
|
|
return nullptr;
|
2016-04-14 23:20:12 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 04:29:48 +04:00
|
|
|
if (aSurface->GetType() == SurfaceType::SKIA) {
|
2016-10-25 05:40:59 +03:00
|
|
|
return static_cast<SourceSurfaceSkia*>(aSurface)->GetImage();
|
2014-01-13 04:29:48 +04:00
|
|
|
}
|
|
|
|
|
2016-01-12 21:05:13 +03:00
|
|
|
DataSourceSurface* surf = aSurface->GetDataSurface().take();
|
2014-01-13 04:29:48 +04:00
|
|
|
if (!surf) {
|
2016-10-25 05:40:59 +03:00
|
|
|
gfxWarning() << "Failed getting DataSourceSurface for Skia image";
|
|
|
|
return nullptr;
|
2013-11-27 15:25:27 +04:00
|
|
|
}
|
2014-01-13 04:29:48 +04:00
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
SkPixmap pixmap(MakeSkiaImageInfo(surf->GetSize(), surf->GetFormat()),
|
|
|
|
surf->GetData(), surf->Stride());
|
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromRaster(pixmap, ReleaseTemporarySurface, surf);
|
|
|
|
if (!image) {
|
|
|
|
ReleaseTemporarySurface(nullptr, surf);
|
|
|
|
gfxDebug() << "Failed making Skia raster image for temporary surface";
|
2016-01-12 21:05:13 +03:00
|
|
|
}
|
2014-07-28 04:47:43 +04:00
|
|
|
|
2016-07-26 02:36:35 +03:00
|
|
|
// Skia doesn't support RGBX surfaces so ensure that the alpha value is opaque white.
|
|
|
|
MOZ_ASSERT(VerifyRGBXCorners(surf->GetData(), surf->GetSize(),
|
2016-08-18 16:55:45 +03:00
|
|
|
surf->Stride(), surf->GetFormat(),
|
|
|
|
aBounds, aMatrix));
|
2016-10-25 05:40:59 +03:00
|
|
|
return image;
|
2013-11-27 15:25:27 +04:00
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
DrawTargetSkia::DrawTargetSkia()
|
2016-01-21 17:51:40 +03:00
|
|
|
: mSnapshot(nullptr)
|
2016-05-17 21:41:38 +03:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
|
|
|
, mCG(nullptr)
|
2016-05-19 03:09:14 +03:00
|
|
|
, mColorSpace(nullptr)
|
2016-05-17 21:41:38 +03:00
|
|
|
, mCanvasData(nullptr)
|
|
|
|
, mCGSize(0, 0)
|
2017-05-10 23:21:13 +03:00
|
|
|
, mNeedLayer(false)
|
2016-05-17 21:41:38 +03:00
|
|
|
#endif
|
2011-11-02 23:55:03 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawTargetSkia::~DrawTargetSkia()
|
|
|
|
{
|
2016-05-17 21:41:38 +03:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
|
|
|
if (mCG) {
|
|
|
|
CGContextRelease(mCG);
|
|
|
|
mCG = nullptr;
|
|
|
|
}
|
2016-05-19 03:09:14 +03:00
|
|
|
|
|
|
|
if (mColorSpace) {
|
|
|
|
CGColorSpaceRelease(mColorSpace);
|
|
|
|
mColorSpace = nullptr;
|
|
|
|
}
|
2016-05-17 21:41:38 +03:00
|
|
|
#endif
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2011-11-02 23:55:03 +04:00
|
|
|
DrawTargetSkia::Snapshot()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurfaceSkia> snapshot = mSnapshot;
|
2016-10-26 20:41:07 +03:00
|
|
|
if (mSurface && !snapshot) {
|
2013-08-02 05:12:16 +04:00
|
|
|
snapshot = new SourceSurfaceSkia();
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkImage> image;
|
|
|
|
// If the surface is raster, making a snapshot may trigger a pixel copy.
|
|
|
|
// Instead, try to directly make a raster image referencing the surface pixels.
|
|
|
|
SkPixmap pixmap;
|
|
|
|
if (mSurface->peekPixels(&pixmap)) {
|
|
|
|
image = SkImage::MakeFromRaster(pixmap, nullptr, nullptr);
|
|
|
|
} else {
|
2017-05-10 05:31:07 +03:00
|
|
|
image = mSurface->makeImageSnapshot();
|
2016-10-25 05:40:59 +03:00
|
|
|
}
|
|
|
|
if (!snapshot->InitFromImage(image, mFormat, this)) {
|
2016-10-25 02:45:46 +03:00
|
|
|
return nullptr;
|
2016-10-25 05:40:59 +03:00
|
|
|
}
|
|
|
|
mSnapshot = snapshot;
|
2013-08-02 05:12:16 +04:00
|
|
|
}
|
2013-05-29 20:49:40 +04:00
|
|
|
|
2014-06-13 20:09:23 +04:00
|
|
|
return snapshot.forget();
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2015-05-01 21:08:04 +03:00
|
|
|
bool
|
|
|
|
DrawTargetSkia::LockBits(uint8_t** aData, IntSize* aSize,
|
2016-01-13 21:11:07 +03:00
|
|
|
int32_t* aStride, SurfaceFormat* aFormat,
|
|
|
|
IntPoint* aOrigin)
|
2015-05-01 21:08:04 +03:00
|
|
|
{
|
2015-12-18 21:53:25 +03:00
|
|
|
SkImageInfo info;
|
|
|
|
size_t rowBytes;
|
2017-05-10 05:31:07 +03:00
|
|
|
SkIPoint origin;
|
|
|
|
void* pixels = mCanvas->accessTopLayerPixels(&info, &rowBytes, &origin);
|
|
|
|
if (!pixels ||
|
|
|
|
// Ensure the layer is at the origin if required.
|
|
|
|
(!aOrigin && !origin.isZero())) {
|
2015-05-01 21:08:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MarkChanged();
|
|
|
|
|
2015-12-18 21:53:25 +03:00
|
|
|
*aData = reinterpret_cast<uint8_t*>(pixels);
|
|
|
|
*aSize = IntSize(info.width(), info.height());
|
|
|
|
*aStride = int32_t(rowBytes);
|
2016-08-04 03:24:39 +03:00
|
|
|
*aFormat = SkiaColorTypeToGfxFormat(info.colorType(), info.alphaType());
|
2016-01-13 21:11:07 +03:00
|
|
|
if (aOrigin) {
|
|
|
|
*aOrigin = IntPoint(origin.x(), origin.y());
|
|
|
|
}
|
2015-05-01 21:08:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::ReleaseBits(uint8_t* aData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
static void
|
|
|
|
ReleaseImage(const void* aPixels, void* aContext)
|
|
|
|
{
|
|
|
|
SkImage* image = static_cast<SkImage*>(aContext);
|
|
|
|
SkSafeUnref(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkImage>
|
|
|
|
ExtractSubset(sk_sp<SkImage> aImage, const IntRect& aRect)
|
|
|
|
{
|
|
|
|
SkIRect subsetRect = IntRectToSkIRect(aRect);
|
|
|
|
if (aImage->bounds() == subsetRect) {
|
|
|
|
return aImage;
|
|
|
|
}
|
|
|
|
// makeSubset is slow, so prefer to use SkPixmap::extractSubset where possible.
|
|
|
|
SkPixmap pixmap, subsetPixmap;
|
|
|
|
if (aImage->peekPixels(&pixmap) &&
|
|
|
|
pixmap.extractSubset(&subsetPixmap, subsetRect)) {
|
|
|
|
// Release the original image reference so only the subset image keeps it alive.
|
|
|
|
return SkImage::MakeFromRaster(subsetPixmap, ReleaseImage, aImage.release());
|
|
|
|
}
|
|
|
|
return aImage->makeSubset(subsetRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
SkImageIsMask(const sk_sp<SkImage>& aImage)
|
|
|
|
{
|
|
|
|
SkPixmap pixmap;
|
|
|
|
if (aImage->peekPixels(&pixmap)) {
|
|
|
|
return pixmap.colorType() == kAlpha_8_SkColorType;
|
|
|
|
#ifdef USE_SKIA_GPU
|
2017-02-09 15:39:27 +03:00
|
|
|
}
|
|
|
|
if (GrTexture* tex = aImage->getTexture()) {
|
2016-10-25 05:40:59 +03:00
|
|
|
return GrPixelConfigIsAlphaOnly(tex->config());
|
|
|
|
#endif
|
|
|
|
}
|
2017-02-09 15:39:27 +03:00
|
|
|
return false;
|
2016-10-25 05:40:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2016-11-15 01:16:18 +03:00
|
|
|
ExtractAlphaBitmap(const sk_sp<SkImage>& aImage, SkBitmap* aResultBitmap)
|
2016-10-25 05:40:59 +03:00
|
|
|
{
|
|
|
|
SkImageInfo info = SkImageInfo::MakeA8(aImage->width(), aImage->height());
|
|
|
|
SkBitmap bitmap;
|
|
|
|
if (!bitmap.tryAllocPixels(info, SkAlign4(info.minRowBytes())) ||
|
|
|
|
!aImage->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(), 0, 0)) {
|
|
|
|
gfxWarning() << "Failed reading alpha pixels for Skia bitmap";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResultBitmap = bitmap;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkImage>
|
|
|
|
ExtractAlphaForSurface(SourceSurface* aSurface)
|
|
|
|
{
|
|
|
|
sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
|
|
|
|
if (!image) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (SkImageIsMask(image)) {
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap bitmap;
|
|
|
|
if (!ExtractAlphaBitmap(image, &bitmap)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark the bitmap immutable so that it will be shared rather than copied.
|
|
|
|
bitmap.setImmutable();
|
|
|
|
return SkImage::MakeFromBitmap(bitmap);
|
|
|
|
}
|
|
|
|
|
2014-01-13 04:29:48 +04:00
|
|
|
static void
|
2016-08-18 16:55:45 +03:00
|
|
|
SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, Float aAlpha = 1.0, Point aOffset = Point(0, 0), const Rect* aBounds = nullptr)
|
2012-01-19 08:48:33 +04:00
|
|
|
{
|
|
|
|
switch (aPattern.GetType()) {
|
2014-01-10 23:06:17 +04:00
|
|
|
case PatternType::COLOR: {
|
2012-01-19 08:48:33 +04:00
|
|
|
Color color = static_cast<const ColorPattern&>(aPattern).mColor;
|
|
|
|
aPaint.setColor(ColorToSkColor(color, aAlpha));
|
|
|
|
break;
|
|
|
|
}
|
2014-01-10 23:06:17 +04:00
|
|
|
case PatternType::LINEAR_GRADIENT: {
|
2012-01-19 08:48:33 +04:00
|
|
|
const LinearGradientPattern& pat = static_cast<const LinearGradientPattern&>(aPattern);
|
|
|
|
GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
|
2016-07-19 07:59:00 +03:00
|
|
|
if (!stops || stops->mCount < 2 ||
|
2016-06-30 03:01:48 +03:00
|
|
|
!pat.mBegin.IsFinite() || !pat.mEnd.IsFinite()) {
|
|
|
|
aPaint.setColor(SK_ColorTRANSPARENT);
|
|
|
|
} else {
|
2016-07-19 07:59:00 +03:00
|
|
|
SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode, Axis::BOTH);
|
2012-01-19 08:48:33 +04:00
|
|
|
SkPoint points[2];
|
|
|
|
points[0] = SkPoint::Make(SkFloatToScalar(pat.mBegin.x), SkFloatToScalar(pat.mBegin.y));
|
|
|
|
points[1] = SkPoint::Make(SkFloatToScalar(pat.mEnd.x), SkFloatToScalar(pat.mEnd.y));
|
|
|
|
|
2016-01-12 21:26:31 +03:00
|
|
|
SkMatrix mat;
|
|
|
|
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
|
2016-08-25 21:27:24 +03:00
|
|
|
mat.postTranslate(SkFloatToScalar(aOffset.x), SkFloatToScalar(aOffset.y));
|
2016-04-29 05:55:27 +03:00
|
|
|
sk_sp<SkShader> shader = SkGradientShader::MakeLinear(points,
|
|
|
|
&stops->mColors.front(),
|
|
|
|
&stops->mPositions.front(),
|
|
|
|
stops->mCount,
|
|
|
|
mode, 0, &mat);
|
2017-05-10 05:31:07 +03:00
|
|
|
if (shader) {
|
|
|
|
aPaint.setShader(shader);
|
|
|
|
} else {
|
|
|
|
aPaint.setColor(SK_ColorTRANSPARENT);
|
|
|
|
}
|
2012-01-19 08:48:33 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-01-10 23:06:17 +04:00
|
|
|
case PatternType::RADIAL_GRADIENT: {
|
2012-01-19 08:48:33 +04:00
|
|
|
const RadialGradientPattern& pat = static_cast<const RadialGradientPattern&>(aPattern);
|
|
|
|
GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
|
2016-07-19 07:59:00 +03:00
|
|
|
if (!stops || stops->mCount < 2 ||
|
2016-06-30 03:01:48 +03:00
|
|
|
!pat.mCenter1.IsFinite() || !IsFinite(pat.mRadius1) ||
|
|
|
|
!pat.mCenter2.IsFinite() || !IsFinite(pat.mRadius2)) {
|
|
|
|
aPaint.setColor(SK_ColorTRANSPARENT);
|
|
|
|
} else {
|
2016-07-19 07:59:00 +03:00
|
|
|
SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode, Axis::BOTH);
|
2012-01-19 08:48:33 +04:00
|
|
|
SkPoint points[2];
|
|
|
|
points[0] = SkPoint::Make(SkFloatToScalar(pat.mCenter1.x), SkFloatToScalar(pat.mCenter1.y));
|
|
|
|
points[1] = SkPoint::Make(SkFloatToScalar(pat.mCenter2.x), SkFloatToScalar(pat.mCenter2.y));
|
|
|
|
|
2016-01-12 21:26:31 +03:00
|
|
|
SkMatrix mat;
|
|
|
|
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
|
2016-08-25 21:27:24 +03:00
|
|
|
mat.postTranslate(SkFloatToScalar(aOffset.x), SkFloatToScalar(aOffset.y));
|
2016-04-29 05:55:27 +03:00
|
|
|
sk_sp<SkShader> shader = SkGradientShader::MakeTwoPointConical(points[0],
|
|
|
|
SkFloatToScalar(pat.mRadius1),
|
|
|
|
points[1],
|
|
|
|
SkFloatToScalar(pat.mRadius2),
|
|
|
|
&stops->mColors.front(),
|
|
|
|
&stops->mPositions.front(),
|
|
|
|
stops->mCount,
|
|
|
|
mode, 0, &mat);
|
2017-05-10 05:31:07 +03:00
|
|
|
if (shader) {
|
|
|
|
aPaint.setShader(shader);
|
|
|
|
} else {
|
|
|
|
aPaint.setColor(SK_ColorTRANSPARENT);
|
|
|
|
}
|
2012-01-19 08:48:33 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-01-10 23:06:17 +04:00
|
|
|
case PatternType::SURFACE: {
|
2012-01-19 08:48:33 +04:00
|
|
|
const SurfacePattern& pat = static_cast<const SurfacePattern&>(aPattern);
|
2016-08-18 16:55:45 +03:00
|
|
|
sk_sp<SkImage> image = GetSkImageForSurface(pat.mSurface, aBounds, &pat.mMatrix);
|
2017-01-06 23:23:17 +03:00
|
|
|
if (!image) {
|
|
|
|
aPaint.setColor(SK_ColorTRANSPARENT);
|
|
|
|
break;
|
|
|
|
}
|
2012-01-19 08:48:33 +04:00
|
|
|
|
|
|
|
SkMatrix mat;
|
|
|
|
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
|
2016-08-25 21:27:24 +03:00
|
|
|
mat.postTranslate(SkFloatToScalar(aOffset.x), SkFloatToScalar(aOffset.y));
|
2014-09-12 09:18:22 +04:00
|
|
|
|
|
|
|
if (!pat.mSamplingRect.IsEmpty()) {
|
2016-10-25 05:40:59 +03:00
|
|
|
image = ExtractSubset(image, pat.mSamplingRect);
|
|
|
|
mat.preTranslate(pat.mSamplingRect.x, pat.mSamplingRect.y);
|
2014-09-12 09:18:22 +04:00
|
|
|
}
|
|
|
|
|
2015-11-23 19:17:35 +03:00
|
|
|
SkShader::TileMode xTileMode = ExtendModeToTileMode(pat.mExtendMode, Axis::X_AXIS);
|
|
|
|
SkShader::TileMode yTileMode = ExtendModeToTileMode(pat.mExtendMode, Axis::Y_AXIS);
|
|
|
|
|
2017-01-06 23:23:17 +03:00
|
|
|
aPaint.setShader(image->makeShader(xTileMode, yTileMode, &mat));
|
2016-10-25 05:40:59 +03:00
|
|
|
|
2016-05-25 19:01:18 +03:00
|
|
|
if (pat.mSamplingFilter == SamplingFilter::POINT) {
|
2015-12-18 21:53:25 +03:00
|
|
|
aPaint.setFilterQuality(kNone_SkFilterQuality);
|
2012-01-19 08:48:33 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 12:59:20 +04:00
|
|
|
static inline Rect
|
|
|
|
GetClipBounds(SkCanvas *aCanvas)
|
|
|
|
{
|
2016-08-18 18:25:38 +03:00
|
|
|
// Use a manually transformed getClipDeviceBounds instead of
|
|
|
|
// getClipBounds because getClipBounds inflates the the bounds
|
|
|
|
// by a pixel in each direction to compensate for antialiasing.
|
|
|
|
SkIRect deviceBounds;
|
2017-05-10 05:31:07 +03:00
|
|
|
if (!aCanvas->getDeviceClipBounds(&deviceBounds)) {
|
2016-04-13 23:34:07 +03:00
|
|
|
return Rect();
|
|
|
|
}
|
2016-08-18 18:25:38 +03:00
|
|
|
SkMatrix inverseCTM;
|
|
|
|
if (!aCanvas->getTotalMatrix().invert(&inverseCTM)) {
|
|
|
|
return Rect();
|
|
|
|
}
|
|
|
|
SkRect localBounds;
|
|
|
|
inverseCTM.mapRect(&localBounds, SkRect::Make(deviceBounds));
|
|
|
|
return SkRectToRect(localBounds);
|
2014-04-01 12:59:20 +04:00
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
struct AutoPaintSetup {
|
2016-08-18 16:55:45 +03:00
|
|
|
AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions, const Pattern& aPattern, const Rect* aMaskBounds = nullptr, Point aOffset = Point(0, 0), const Rect* aSourceBounds = nullptr)
|
2011-11-02 23:55:03 +04:00
|
|
|
: mNeedsRestore(false), mAlpha(1.0)
|
|
|
|
{
|
2016-08-26 07:42:12 +03:00
|
|
|
Init(aCanvas, aOptions, aMaskBounds, false);
|
2016-08-18 16:55:45 +03:00
|
|
|
SetPaintPattern(mPaint, aPattern, mAlpha, aOffset, aSourceBounds);
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2016-08-26 07:42:12 +03:00
|
|
|
AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions, const Rect* aMaskBounds = nullptr, bool aForceGroup = false)
|
2011-11-02 23:55:03 +04:00
|
|
|
: mNeedsRestore(false), mAlpha(1.0)
|
|
|
|
{
|
2016-08-26 07:42:12 +03:00
|
|
|
Init(aCanvas, aOptions, aMaskBounds, aForceGroup);
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~AutoPaintSetup()
|
|
|
|
{
|
|
|
|
if (mNeedsRestore) {
|
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 07:42:12 +03:00
|
|
|
void Init(SkCanvas *aCanvas, const DrawOptions& aOptions, const Rect* aMaskBounds, bool aForceGroup)
|
2011-11-02 23:55:03 +04:00
|
|
|
{
|
2016-10-25 05:40:59 +03:00
|
|
|
mPaint.setBlendMode(GfxOpToSkiaOp(aOptions.mCompositionOp));
|
2011-11-02 23:55:03 +04:00
|
|
|
mCanvas = aCanvas;
|
|
|
|
|
|
|
|
//TODO: Can we set greyscale somehow?
|
2014-01-10 23:06:17 +04:00
|
|
|
if (aOptions.mAntialiasMode != AntialiasMode::NONE) {
|
2011-11-02 23:55:03 +04:00
|
|
|
mPaint.setAntiAlias(true);
|
|
|
|
} else {
|
|
|
|
mPaint.setAntiAlias(false);
|
|
|
|
}
|
|
|
|
|
2016-08-26 07:42:12 +03:00
|
|
|
bool needsGroup = aForceGroup ||
|
|
|
|
(!IsOperatorBoundByMask(aOptions.mCompositionOp) &&
|
|
|
|
(!aMaskBounds || !aMaskBounds->Contains(GetClipBounds(aCanvas))));
|
2014-04-01 12:59:20 +04:00
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
// TODO: We could skip the temporary for operator_source and just
|
|
|
|
// clear the clip rect. The other operators would be harder
|
|
|
|
// but could be worth it to skip pushing a group.
|
2014-04-01 12:59:20 +04:00
|
|
|
if (needsGroup) {
|
2016-10-25 05:40:59 +03:00
|
|
|
mPaint.setBlendMode(SkBlendMode::kSrcOver);
|
2011-11-02 23:55:03 +04:00
|
|
|
SkPaint temp;
|
2016-10-25 05:40:59 +03:00
|
|
|
temp.setBlendMode(GfxOpToSkiaOp(aOptions.mCompositionOp));
|
2014-06-18 18:16:30 +04:00
|
|
|
temp.setAlpha(ColorFloatToByte(aOptions.mAlpha));
|
2011-11-02 23:55:03 +04:00
|
|
|
//TODO: Get a rect here
|
2016-12-16 19:02:04 +03:00
|
|
|
mCanvas->saveLayerPreserveLCDTextRequests(nullptr, &temp);
|
2011-11-02 23:55:03 +04:00
|
|
|
mNeedsRestore = true;
|
|
|
|
} else {
|
2014-06-18 18:16:30 +04:00
|
|
|
mPaint.setAlpha(ColorFloatToByte(aOptions.mAlpha));
|
2011-11-02 23:55:03 +04:00
|
|
|
mAlpha = aOptions.mAlpha;
|
|
|
|
}
|
2015-12-18 21:53:25 +03:00
|
|
|
mPaint.setFilterQuality(kLow_SkFilterQuality);
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Maybe add an operator overload to access this easier?
|
|
|
|
SkPaint mPaint;
|
|
|
|
bool mNeedsRestore;
|
|
|
|
SkCanvas* mCanvas;
|
|
|
|
Float mAlpha;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::Flush()
|
|
|
|
{
|
2012-12-01 03:57:38 +04:00
|
|
|
mCanvas->flush();
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::DrawSurface(SourceSurface *aSurface,
|
|
|
|
const Rect &aDest,
|
|
|
|
const Rect &aSource,
|
|
|
|
const DrawSurfaceOptions &aSurfOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2016-09-02 04:17:03 +03:00
|
|
|
if (aSource.IsEmpty()) {
|
|
|
|
return;
|
2013-12-03 17:52:06 +04:00
|
|
|
}
|
|
|
|
|
2016-09-16 18:03:48 +03:00
|
|
|
MarkChanged();
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
|
|
|
|
if (!image) {
|
2011-11-02 23:55:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRect destRect = RectToSkRect(aDest);
|
|
|
|
SkRect sourceRect = RectToSkRect(aSource);
|
2016-10-25 05:40:59 +03:00
|
|
|
bool forceGroup = SkImageIsMask(image) &&
|
2016-08-26 07:42:12 +03:00
|
|
|
aOptions.mCompositionOp != CompositionOp::OP_OVER;
|
2014-10-08 08:16:14 +04:00
|
|
|
|
2017-05-10 05:31:07 +03:00
|
|
|
AutoPaintSetup paint(mCanvas, aOptions, &aDest, forceGroup);
|
2016-05-25 19:01:18 +03:00
|
|
|
if (aSurfOptions.mSamplingFilter == SamplingFilter::POINT) {
|
2015-12-18 21:53:25 +03:00
|
|
|
paint.mPaint.setFilterQuality(kNone_SkFilterQuality);
|
2011-11-18 08:00:38 +04:00
|
|
|
}
|
2012-11-16 04:57:40 +04:00
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
mCanvas->drawImageRect(image, sourceRect, destRect, &paint.mPaint);
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2014-06-27 13:17:49 +04:00
|
|
|
DrawTargetType
|
|
|
|
DrawTargetSkia::GetType() const
|
|
|
|
{
|
|
|
|
#ifdef USE_SKIA_GPU
|
|
|
|
if (mGrContext) {
|
|
|
|
return DrawTargetType::HARDWARE_RASTER;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return DrawTargetType::SOFTWARE_RASTER;
|
|
|
|
}
|
|
|
|
|
2013-11-27 15:25:28 +04:00
|
|
|
void
|
|
|
|
DrawTargetSkia::DrawFilter(FilterNode *aNode,
|
|
|
|
const Rect &aSourceRect,
|
|
|
|
const Point &aDestPoint,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
FilterNodeSoftware* filter = static_cast<FilterNodeSoftware*>(aNode);
|
|
|
|
filter->Draw(this, aSourceRect, aDestPoint, aOptions);
|
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
void
|
|
|
|
DrawTargetSkia::DrawSurfaceWithShadow(SourceSurface *aSurface,
|
|
|
|
const Point &aDest,
|
|
|
|
const Color &aColor,
|
|
|
|
const Point &aOffset,
|
|
|
|
Float aSigma,
|
|
|
|
CompositionOp aOperator)
|
|
|
|
{
|
2016-09-02 04:17:03 +03:00
|
|
|
if (aSurface->GetSize().IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-16 18:03:48 +03:00
|
|
|
MarkChanged();
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
|
|
|
|
if (!image) {
|
2014-03-07 01:33:39 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-28 04:51:09 +04:00
|
|
|
mCanvas->save();
|
2011-11-02 23:55:03 +04:00
|
|
|
mCanvas->resetMatrix();
|
|
|
|
|
|
|
|
SkPaint paint;
|
2016-10-25 05:40:59 +03:00
|
|
|
paint.setBlendMode(GfxOpToSkiaOp(aOperator));
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2015-09-04 22:29:11 +03:00
|
|
|
// bug 1201272
|
|
|
|
// We can't use the SkDropShadowImageFilter here because it applies the xfer
|
|
|
|
// mode first to render the bitmap to a temporary layer, and then implicitly
|
|
|
|
// uses src-over to composite the resulting shadow.
|
|
|
|
// The canvas spec, however, states that the composite op must be used to
|
|
|
|
// composite the resulting shadow, so we must instead use a SkBlurImageFilter
|
|
|
|
// to blur the image ourselves.
|
|
|
|
|
|
|
|
SkPaint shadowPaint;
|
2016-10-25 05:40:59 +03:00
|
|
|
shadowPaint.setBlendMode(GfxOpToSkiaOp(aOperator));
|
2015-09-04 22:29:11 +03:00
|
|
|
|
2016-07-26 17:48:34 +03:00
|
|
|
auto shadowDest = IntPoint::Round(aDest + aOffset);
|
2016-03-26 05:14:50 +03:00
|
|
|
|
|
|
|
SkBitmap blurMask;
|
|
|
|
if (!UsingSkiaGPU() &&
|
2016-10-25 05:40:59 +03:00
|
|
|
ExtractAlphaBitmap(image, &blurMask)) {
|
2016-03-26 05:14:50 +03:00
|
|
|
// Prefer using our own box blur instead of Skia's when we're
|
|
|
|
// not using the GPU. It currently performs much better than
|
|
|
|
// SkBlurImageFilter or SkBlurMaskFilter on the CPU.
|
|
|
|
AlphaBoxBlur blur(Rect(0, 0, blurMask.width(), blurMask.height()),
|
|
|
|
int32_t(blurMask.rowBytes()),
|
|
|
|
aSigma, aSigma);
|
2016-10-25 02:45:46 +03:00
|
|
|
blurMask.lockPixels();
|
2016-03-26 05:14:50 +03:00
|
|
|
blur.Blur(reinterpret_cast<uint8_t*>(blurMask.getPixels()));
|
2016-10-25 02:45:46 +03:00
|
|
|
blurMask.unlockPixels();
|
|
|
|
blurMask.notifyPixelsChanged();
|
2016-03-26 05:14:50 +03:00
|
|
|
|
|
|
|
shadowPaint.setColor(ColorToSkColor(aColor, 1.0f));
|
|
|
|
|
|
|
|
mCanvas->drawBitmap(blurMask, shadowDest.x, shadowDest.y, &shadowPaint);
|
|
|
|
} else {
|
2016-04-29 05:55:27 +03:00
|
|
|
sk_sp<SkImageFilter> blurFilter(SkBlurImageFilter::Make(aSigma, aSigma, nullptr));
|
|
|
|
sk_sp<SkColorFilter> colorFilter(
|
2016-10-25 05:40:59 +03:00
|
|
|
SkColorFilter::MakeModeFilter(ColorToSkColor(aColor, 1.0f), SkBlendMode::kSrcIn));
|
2016-03-26 05:14:50 +03:00
|
|
|
|
2016-04-29 05:55:27 +03:00
|
|
|
shadowPaint.setImageFilter(blurFilter);
|
|
|
|
shadowPaint.setColorFilter(colorFilter);
|
2016-03-26 05:14:50 +03:00
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
mCanvas->drawImage(image, shadowDest.x, shadowDest.y, &shadowPaint);
|
2016-03-26 05:14:50 +03:00
|
|
|
}
|
2015-09-04 22:29:11 +03:00
|
|
|
|
2016-11-21 21:17:09 +03:00
|
|
|
if (aSurface->GetFormat() != SurfaceFormat::A8) {
|
|
|
|
// Composite the original image after the shadow
|
|
|
|
auto dest = IntPoint::Round(aDest);
|
|
|
|
mCanvas->drawImage(image, dest.x, dest.y, &paint);
|
|
|
|
}
|
2015-09-04 22:29:11 +03:00
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::FillRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2016-08-23 20:36:45 +03:00
|
|
|
// The sprite blitting path in Skia can be faster than the shader blitter for
|
|
|
|
// operators other than source (or source-over with opaque surface). So, when
|
|
|
|
// possible/beneficial, route to DrawSurface which will use the sprite blitter.
|
|
|
|
if (aPattern.GetType() == PatternType::SURFACE &&
|
|
|
|
aOptions.mCompositionOp != CompositionOp::OP_SOURCE) {
|
|
|
|
const SurfacePattern& pat = static_cast<const SurfacePattern&>(aPattern);
|
|
|
|
// Verify there is a valid surface and a pattern matrix without skew.
|
|
|
|
if (pat.mSurface &&
|
|
|
|
(aOptions.mCompositionOp != CompositionOp::OP_OVER ||
|
|
|
|
GfxFormatToSkiaAlphaType(pat.mSurface->GetFormat()) != kOpaque_SkAlphaType) &&
|
|
|
|
!pat.mMatrix.HasNonAxisAlignedTransform()) {
|
|
|
|
// Bound the sampling to smaller of the bounds or the sampling rect.
|
|
|
|
IntRect srcRect(IntPoint(0, 0), pat.mSurface->GetSize());
|
|
|
|
if (!pat.mSamplingRect.IsEmpty()) {
|
|
|
|
srcRect = srcRect.Intersect(pat.mSamplingRect);
|
|
|
|
}
|
|
|
|
// Transform the destination rectangle by the inverse of the pattern
|
|
|
|
// matrix so that it is in pattern space like the source rectangle.
|
|
|
|
Rect patRect = aRect - pat.mMatrix.GetTranslation();
|
|
|
|
patRect.Scale(1.0f / pat.mMatrix._11, 1.0f / pat.mMatrix._22);
|
|
|
|
// Verify the pattern rectangle will not tile or clamp.
|
|
|
|
if (!patRect.IsEmpty() && srcRect.Contains(RoundedOut(patRect))) {
|
|
|
|
// The pattern is a surface with an axis-aligned source rectangle
|
|
|
|
// fitting entirely in its bounds, so just treat it as a DrawSurface.
|
|
|
|
DrawSurface(pat.mSurface, aRect, patRect,
|
|
|
|
DrawSurfaceOptions(pat.mSamplingFilter),
|
|
|
|
aOptions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
MarkChanged();
|
2011-11-02 23:55:03 +04:00
|
|
|
SkRect rect = RectToSkRect(aRect);
|
2017-05-10 05:31:07 +03:00
|
|
|
AutoPaintSetup paint(mCanvas, aOptions, aPattern, &aRect, Point(0, 0), &aRect);
|
2011-11-02 23:55:03 +04:00
|
|
|
|
|
|
|
mCanvas->drawRect(rect, paint.mPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::Stroke(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2011-11-02 23:55:03 +04:00
|
|
|
MarkChanged();
|
2012-04-26 02:04:35 +04:00
|
|
|
MOZ_ASSERT(aPath, "Null path");
|
2014-01-10 23:06:16 +04:00
|
|
|
if (aPath->GetBackendType() != BackendType::SKIA) {
|
2011-11-02 23:55:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathSkia *skiaPath = static_cast<const PathSkia*>(aPath);
|
|
|
|
|
|
|
|
|
2017-05-10 05:31:07 +03:00
|
|
|
AutoPaintSetup paint(mCanvas, aOptions, aPattern);
|
2011-11-18 08:00:38 +04:00
|
|
|
if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2015-12-30 21:39:13 +03:00
|
|
|
if (!skiaPath->GetPath().isFinite()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
mCanvas->drawPath(skiaPath->GetPath(), paint.mPaint);
|
|
|
|
}
|
|
|
|
|
2017-05-23 06:53:04 +03:00
|
|
|
static Double
|
2017-02-28 23:47:46 +03:00
|
|
|
DashPeriodLength(const StrokeOptions& aStrokeOptions)
|
|
|
|
{
|
2017-05-23 06:53:04 +03:00
|
|
|
Double length = 0;
|
2017-02-28 23:47:46 +03:00
|
|
|
for (size_t i = 0; i < aStrokeOptions.mDashLength; i++) {
|
|
|
|
length += aStrokeOptions.mDashPattern[i];
|
|
|
|
}
|
|
|
|
if (aStrokeOptions.mDashLength & 1) {
|
|
|
|
// "If an odd number of values is provided, then the list of values is
|
|
|
|
// repeated to yield an even number of values."
|
|
|
|
// Double the length.
|
|
|
|
length += length;
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2017-05-23 06:53:04 +03:00
|
|
|
static inline Double
|
|
|
|
RoundDownToMultiple(Double aValue, Double aFactor)
|
2017-02-28 23:47:46 +03:00
|
|
|
{
|
2017-05-23 06:53:04 +03:00
|
|
|
return floor(aValue / aFactor) * aFactor;
|
2017-02-28 23:47:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static Rect
|
|
|
|
UserSpaceStrokeClip(const IntRect &aDeviceClip,
|
|
|
|
const Matrix &aTransform,
|
|
|
|
const StrokeOptions &aStrokeOptions)
|
|
|
|
{
|
|
|
|
Matrix inverse = aTransform;
|
|
|
|
if (!inverse.Invert()) {
|
|
|
|
return Rect();
|
|
|
|
}
|
|
|
|
Rect deviceClip(aDeviceClip);
|
|
|
|
deviceClip.Inflate(MaxStrokeExtents(aStrokeOptions, aTransform));
|
|
|
|
return inverse.TransformBounds(deviceClip);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Rect
|
|
|
|
ShrinkClippedStrokedRect(const Rect &aStrokedRect, const IntRect &aDeviceClip,
|
|
|
|
const Matrix &aTransform,
|
|
|
|
const StrokeOptions &aStrokeOptions)
|
|
|
|
{
|
|
|
|
Rect userSpaceStrokeClip =
|
|
|
|
UserSpaceStrokeClip(aDeviceClip, aTransform, aStrokeOptions);
|
2017-05-23 06:53:04 +03:00
|
|
|
RectDouble strokedRectDouble(
|
2017-08-14 15:29:28 +03:00
|
|
|
aStrokedRect.x, aStrokedRect.y, aStrokedRect.Width(), aStrokedRect.Height());
|
2017-05-23 06:53:04 +03:00
|
|
|
RectDouble intersection =
|
|
|
|
strokedRectDouble.Intersect(RectDouble(userSpaceStrokeClip.x,
|
|
|
|
userSpaceStrokeClip.y,
|
2017-08-14 15:29:28 +03:00
|
|
|
userSpaceStrokeClip.Width(),
|
|
|
|
userSpaceStrokeClip.Height()));
|
2017-05-23 06:53:04 +03:00
|
|
|
Double dashPeriodLength = DashPeriodLength(aStrokeOptions);
|
2017-02-28 23:47:46 +03:00
|
|
|
if (intersection.IsEmpty() || dashPeriodLength == 0.0f) {
|
2017-05-23 06:53:04 +03:00
|
|
|
return Rect(
|
2017-08-14 15:29:28 +03:00
|
|
|
intersection.x, intersection.y, intersection.Width(), intersection.Height());
|
2017-02-28 23:47:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reduce the rectangle side lengths in multiples of the dash period length
|
|
|
|
// so that the visible dashes stay in the same place.
|
2017-05-23 06:53:04 +03:00
|
|
|
MarginDouble insetBy = strokedRectDouble - intersection;
|
2017-02-28 23:47:46 +03:00
|
|
|
insetBy.top = RoundDownToMultiple(insetBy.top, dashPeriodLength);
|
|
|
|
insetBy.right = RoundDownToMultiple(insetBy.right, dashPeriodLength);
|
|
|
|
insetBy.bottom = RoundDownToMultiple(insetBy.bottom, dashPeriodLength);
|
|
|
|
insetBy.left = RoundDownToMultiple(insetBy.left, dashPeriodLength);
|
|
|
|
|
2017-05-23 06:53:04 +03:00
|
|
|
strokedRectDouble.Deflate(insetBy);
|
|
|
|
return Rect(strokedRectDouble.x,
|
|
|
|
strokedRectDouble.y,
|
2017-08-14 15:29:28 +03:00
|
|
|
strokedRectDouble.Width(),
|
|
|
|
strokedRectDouble.Height());
|
2017-02-28 23:47:46 +03:00
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
void
|
|
|
|
DrawTargetSkia::StrokeRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2017-02-28 23:47:46 +03:00
|
|
|
// Stroking large rectangles with dashes is expensive with Skia (fixed
|
|
|
|
// overhead based on the number of dashes, regardless of whether the dashes
|
|
|
|
// are visible), so we try to reduce the size of the stroked rectangle as
|
|
|
|
// much as possible before passing it on to Skia.
|
|
|
|
Rect rect = aRect;
|
|
|
|
if (aStrokeOptions.mDashLength > 0 && !rect.IsEmpty()) {
|
|
|
|
IntRect deviceClip(IntPoint(0, 0), mSize);
|
|
|
|
SkIRect clipBounds;
|
2017-05-10 05:31:07 +03:00
|
|
|
if (mCanvas->getDeviceClipBounds(&clipBounds)) {
|
2017-02-28 23:47:46 +03:00
|
|
|
deviceClip = SkIRectToIntRect(clipBounds);
|
|
|
|
}
|
|
|
|
rect = ShrinkClippedStrokedRect(rect, deviceClip, mTransform, aStrokeOptions);
|
|
|
|
if (rect.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
MarkChanged();
|
2017-05-10 05:31:07 +03:00
|
|
|
AutoPaintSetup paint(mCanvas, aOptions, aPattern);
|
2011-11-18 08:00:38 +04:00
|
|
|
if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2017-02-28 23:47:46 +03:00
|
|
|
mCanvas->drawRect(RectToSkRect(rect), paint.mPaint);
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2014-10-08 08:16:14 +04:00
|
|
|
void
|
2011-11-02 23:55:03 +04:00
|
|
|
DrawTargetSkia::StrokeLine(const Point &aStart,
|
|
|
|
const Point &aEnd,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2011-11-02 23:55:03 +04:00
|
|
|
MarkChanged();
|
2017-05-10 05:31:07 +03:00
|
|
|
AutoPaintSetup paint(mCanvas, aOptions, aPattern);
|
2011-11-18 08:00:38 +04:00
|
|
|
if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2014-10-08 08:16:14 +04:00
|
|
|
mCanvas->drawLine(SkFloatToScalar(aStart.x), SkFloatToScalar(aStart.y),
|
|
|
|
SkFloatToScalar(aEnd.x), SkFloatToScalar(aEnd.y),
|
2011-11-02 23:55:03 +04:00
|
|
|
paint.mPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::Fill(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2011-11-02 23:55:03 +04:00
|
|
|
MarkChanged();
|
2017-01-16 21:21:36 +03:00
|
|
|
if (!aPath || aPath->GetBackendType() != BackendType::SKIA) {
|
2011-11-02 23:55:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathSkia *skiaPath = static_cast<const PathSkia*>(aPath);
|
|
|
|
|
2017-05-10 05:31:07 +03:00
|
|
|
AutoPaintSetup paint(mCanvas, aOptions, aPattern);
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2015-12-30 21:39:13 +03:00
|
|
|
if (!skiaPath->GetPath().isFinite()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
mCanvas->drawPath(skiaPath->GetPath(), paint.mPaint);
|
|
|
|
}
|
|
|
|
|
2015-05-04 20:23:54 +03:00
|
|
|
bool
|
|
|
|
DrawTargetSkia::ShouldLCDRenderText(FontType aFontType, AntialiasMode aAntialiasMode)
|
|
|
|
{
|
2016-12-16 19:02:04 +03:00
|
|
|
// Only allow subpixel AA if explicitly permitted.
|
|
|
|
if (!GetPermitSubpixelAA()) {
|
2015-05-04 20:23:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAntialiasMode == AntialiasMode::DEFAULT) {
|
|
|
|
switch (aFontType) {
|
|
|
|
case FontType::MAC:
|
2016-02-18 19:37:43 +03:00
|
|
|
case FontType::GDI:
|
|
|
|
case FontType::DWRITE:
|
2016-07-20 22:07:11 +03:00
|
|
|
case FontType::FONTCONFIG:
|
2015-05-04 20:23:54 +03:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
// TODO: Figure out what to do for the other platforms.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (aAntialiasMode == AntialiasMode::SUBPIXEL);
|
|
|
|
}
|
|
|
|
|
2016-05-17 21:41:38 +03:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2016-10-19 06:22:44 +03:00
|
|
|
static inline CGAffineTransform
|
|
|
|
GfxMatrixToCGAffineTransform(const Matrix &m)
|
|
|
|
{
|
|
|
|
CGAffineTransform t;
|
|
|
|
t.a = m._11;
|
|
|
|
t.b = m._12;
|
|
|
|
t.c = m._21;
|
|
|
|
t.d = m._22;
|
|
|
|
t.tx = m._31;
|
|
|
|
t.ty = m._32;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2016-05-17 21:41:38 +03:00
|
|
|
/***
|
|
|
|
* We have to do a lot of work to draw glyphs with CG because
|
|
|
|
* CG assumes that the origin of rects are in the bottom left
|
|
|
|
* while every other DrawTarget assumes the top left is the origin.
|
|
|
|
* This means we have to transform the CGContext to have rects
|
|
|
|
* actually be applied in top left fashion. We do this by:
|
|
|
|
*
|
|
|
|
* 1) Translating the context up by the height of the canvas
|
|
|
|
* 2) Flipping the context by the Y axis so it's upside down.
|
|
|
|
*
|
|
|
|
* These two transforms put the origin in the top left.
|
|
|
|
* Transforms are better understood thinking about them from right to left order (mathematically).
|
|
|
|
*
|
|
|
|
* Consider a point we want to draw at (0, 10) in normal cartesian planes with
|
|
|
|
* a box of (100, 100). in CG terms, this would be at (0, 10).
|
|
|
|
* Positive Y values point up.
|
|
|
|
* In our DrawTarget terms, positive Y values point down, so (0, 10) would be
|
|
|
|
* at (0, 90) in cartesian plane terms. That means our point at (0, 10) in DrawTarget
|
|
|
|
* terms should end up at (0, 90). How does this work with the current transforms?
|
|
|
|
*
|
|
|
|
* Going right to left with the transforms, a CGPoint of (0, 10) has cartesian coordinates
|
|
|
|
* of (0, 10). The first flip of the Y axis puts the point now at (0, -10);
|
|
|
|
* Next, we translate the context up by the size of the canvas (Positive Y values go up in CG
|
|
|
|
* coordinates but down in our draw target coordinates). Since our canvas size is (100, 100),
|
|
|
|
* the resulting coordinate becomes (0, 90), which is what we expect from our DrawTarget code.
|
|
|
|
* These two transforms put the CG context equal to what every other DrawTarget expects.
|
|
|
|
*
|
|
|
|
* Next, we need two more transforms for actual text. IF we left the transforms as is,
|
|
|
|
* the text would be drawn upside down, so we need another flip of the Y axis
|
|
|
|
* to draw the text right side up. However, with only the flip, the text would be drawn
|
|
|
|
* in the wrong place. Thus we also have to invert the Y position of the glyphs to get them
|
|
|
|
* in the right place.
|
|
|
|
*
|
|
|
|
* Thus we have the following transforms:
|
|
|
|
* 1) Translation of the context up
|
|
|
|
* 2) Flipping the context around the Y axis
|
|
|
|
* 3) Flipping the context around the Y axis
|
|
|
|
* 4) Inverting the Y position of each glyph
|
|
|
|
*
|
|
|
|
* We cannot cancel out (2) and (3) as we have to apply the clips and transforms
|
|
|
|
* of DrawTargetSkia between (2) and (3).
|
|
|
|
*
|
|
|
|
* Consider the example letter P, drawn at (0, 20) in CG coordinates in a (100, 100) rect.
|
|
|
|
* Again, going right to left of the transforms. We'd get:
|
|
|
|
*
|
|
|
|
* 1) The letter P drawn at (0, -20) due to the inversion of the Y axis
|
|
|
|
* 2) The letter P upside down (b) at (0, 20) due to the second flip
|
|
|
|
* 3) The letter P right side up at (0, -20) due to the first flip
|
|
|
|
* 4) The letter P right side up at (0, 80) due to the translation
|
|
|
|
*
|
|
|
|
* tl;dr - CGRects assume origin is bottom left, DrawTarget rects assume top left.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
SetupCGContext(DrawTargetSkia* aDT,
|
|
|
|
CGContextRef aCGContext,
|
2017-05-10 05:31:07 +03:00
|
|
|
SkCanvas* aCanvas,
|
2016-12-16 19:02:04 +03:00
|
|
|
const IntPoint& aOrigin,
|
2017-06-10 04:40:13 +03:00
|
|
|
const IntSize& aSize,
|
|
|
|
bool aClipped)
|
2016-05-17 21:41:38 +03:00
|
|
|
{
|
|
|
|
// DrawTarget expects the origin to be at the top left, but CG
|
|
|
|
// expects it to be at the bottom left. Transform to set the origin to
|
|
|
|
// the top left. Have to set this before we do anything else.
|
|
|
|
// This is transform (1) up top
|
2016-12-16 19:02:04 +03:00
|
|
|
CGContextTranslateCTM(aCGContext, -aOrigin.x, aOrigin.y + aSize.height);
|
2016-05-17 21:41:38 +03:00
|
|
|
|
|
|
|
// Transform (2) from the comments.
|
|
|
|
CGContextScaleCTM(aCGContext, 1, -1);
|
|
|
|
|
|
|
|
// Want to apply clips BEFORE the transform since the transform
|
|
|
|
// will apply to the clips we apply.
|
2017-06-10 04:40:13 +03:00
|
|
|
if (aClipped) {
|
|
|
|
SkRegion clipRegion;
|
|
|
|
aCanvas->temporary_internal_getRgnClip(&clipRegion);
|
|
|
|
Vector<CGRect, 8> rects;
|
|
|
|
for (SkRegion::Iterator it(clipRegion); !it.done(); it.next()) {
|
|
|
|
const SkIRect& rect = it.rect();
|
|
|
|
if (!rects.append(CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rects.length()) {
|
|
|
|
CGContextClipToRects(aCGContext, rects.begin(), rects.length());
|
|
|
|
}
|
2017-05-10 05:31:07 +03:00
|
|
|
}
|
|
|
|
|
2016-05-17 21:41:38 +03:00
|
|
|
CGContextConcatCTM(aCGContext, GfxMatrixToCGAffineTransform(aDT->GetTransform()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
SetupCGGlyphs(CGContextRef aCGContext,
|
|
|
|
const GlyphBuffer& aBuffer,
|
|
|
|
Vector<CGGlyph,32>& aGlyphs,
|
|
|
|
Vector<CGPoint,32>& aPositions)
|
|
|
|
{
|
|
|
|
// Flip again so we draw text in right side up. Transform (3) from the top
|
|
|
|
CGContextScaleCTM(aCGContext, 1, -1);
|
|
|
|
|
|
|
|
if (!aGlyphs.resizeUninitialized(aBuffer.mNumGlyphs) ||
|
|
|
|
!aPositions.resizeUninitialized(aBuffer.mNumGlyphs)) {
|
|
|
|
gfxDevCrash(LogReason::GlyphAllocFailedCG) << "glyphs/positions allocation failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
|
|
|
|
aGlyphs[i] = aBuffer.mGlyphs[i].mIndex;
|
|
|
|
|
|
|
|
// Flip the y coordinates so that text ends up in the right spot after the (3) flip
|
|
|
|
// Inversion from (4) in the comments.
|
|
|
|
aPositions[i] = CGPointMake(aBuffer.mGlyphs[i].mPosition.x,
|
|
|
|
-aBuffer.mGlyphs[i].mPosition.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// End long comment about transforms. SetupCGContext and SetupCGGlyphs should stay
|
|
|
|
// next to each other.
|
|
|
|
|
|
|
|
// The context returned from this method will have the origin
|
2017-05-10 05:31:07 +03:00
|
|
|
// in the top left and will have applied all the neccessary clips
|
2016-05-17 21:41:38 +03:00
|
|
|
// and transforms to the CGContext. See the comment above
|
|
|
|
// SetupCGContext.
|
|
|
|
CGContextRef
|
|
|
|
DrawTargetSkia::BorrowCGContext(const DrawOptions &aOptions)
|
|
|
|
{
|
2017-05-10 23:21:13 +03:00
|
|
|
// Since we can't replay Skia clips, we have to use a layer if we have a complex clip.
|
|
|
|
// After saving a layer, the SkCanvas queries for needing a layer change so save if we
|
|
|
|
// pushed a layer.
|
|
|
|
mNeedLayer = !mCanvas->isClipEmpty() && !mCanvas->isClipRect();
|
|
|
|
if (mNeedLayer) {
|
2017-05-10 05:31:07 +03:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setBlendMode(SkBlendMode::kSrc);
|
|
|
|
SkCanvas::SaveLayerRec rec(nullptr, &paint, SkCanvas::kInitWithPrevious_SaveLayerFlag);
|
|
|
|
mCanvas->saveLayer(rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* data = nullptr;
|
2016-05-17 21:41:38 +03:00
|
|
|
int32_t stride;
|
|
|
|
SurfaceFormat format;
|
|
|
|
IntSize size;
|
2016-12-16 19:02:04 +03:00
|
|
|
IntPoint origin;
|
2017-05-10 05:31:07 +03:00
|
|
|
if (!LockBits(&data, &size, &stride, &format, &origin)) {
|
2016-05-17 21:41:38 +03:00
|
|
|
NS_WARNING("Could not lock skia bits to wrap CG around");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-10 23:21:13 +03:00
|
|
|
if (!mNeedLayer && (data == mCanvasData) && mCG && (mCGSize == size)) {
|
2016-05-17 21:41:38 +03:00
|
|
|
// If our canvas data still points to the same data,
|
|
|
|
// we can reuse the CG Context
|
|
|
|
CGContextSetAlpha(mCG, aOptions.mAlpha);
|
2017-06-10 04:40:13 +03:00
|
|
|
CGContextSetShouldAntialias(mCG, aOptions.mAntialiasMode != AntialiasMode::NONE);
|
|
|
|
CGContextSaveGState(mCG);
|
|
|
|
SetupCGContext(this, mCG, mCanvas, origin, size, true);
|
2016-05-17 21:41:38 +03:00
|
|
|
return mCG;
|
|
|
|
}
|
|
|
|
|
2016-05-19 03:09:14 +03:00
|
|
|
if (!mColorSpace) {
|
2016-08-03 17:53:12 +03:00
|
|
|
mColorSpace = (format == SurfaceFormat::A8) ?
|
|
|
|
CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB();
|
2016-05-19 03:09:14 +03:00
|
|
|
}
|
|
|
|
|
2016-05-17 21:41:38 +03:00
|
|
|
if (mCG) {
|
|
|
|
// Release the old CG context since it's no longer valid.
|
|
|
|
CGContextRelease(mCG);
|
|
|
|
}
|
|
|
|
|
2017-05-10 05:31:07 +03:00
|
|
|
mCanvasData = data;
|
2016-05-17 21:41:38 +03:00
|
|
|
mCGSize = size;
|
|
|
|
|
2016-08-03 17:53:12 +03:00
|
|
|
uint32_t bitmapInfo = (format == SurfaceFormat::A8) ?
|
|
|
|
kCGImageAlphaOnly :
|
|
|
|
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
|
|
|
|
|
2016-05-17 21:41:38 +03:00
|
|
|
mCG = CGBitmapContextCreateWithData(mCanvasData,
|
|
|
|
mCGSize.width,
|
|
|
|
mCGSize.height,
|
|
|
|
8, /* bits per component */
|
|
|
|
stride,
|
|
|
|
mColorSpace,
|
2016-08-03 17:53:12 +03:00
|
|
|
bitmapInfo,
|
2016-05-17 21:41:38 +03:00
|
|
|
NULL, /* Callback when released */
|
|
|
|
NULL);
|
|
|
|
if (!mCG) {
|
2017-05-10 23:21:13 +03:00
|
|
|
if (mNeedLayer) {
|
2017-05-10 05:31:07 +03:00
|
|
|
mCanvas->restore();
|
|
|
|
}
|
2016-05-17 21:41:38 +03:00
|
|
|
ReleaseBits(mCanvasData);
|
|
|
|
NS_WARNING("Could not create bitmap around skia data\n");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGContextSetAlpha(mCG, aOptions.mAlpha);
|
|
|
|
CGContextSetShouldAntialias(mCG, aOptions.mAntialiasMode != AntialiasMode::NONE);
|
|
|
|
CGContextSetShouldSmoothFonts(mCG, true);
|
|
|
|
CGContextSetTextDrawingMode(mCG, kCGTextFill);
|
|
|
|
CGContextSaveGState(mCG);
|
2017-06-10 04:40:13 +03:00
|
|
|
SetupCGContext(this, mCG, mCanvas, origin, size, !mNeedLayer);
|
2016-05-17 21:41:38 +03:00
|
|
|
return mCG;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::ReturnCGContext(CGContextRef aCGContext)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCGContext == mCG);
|
|
|
|
ReleaseBits(mCanvasData);
|
|
|
|
CGContextRestoreGState(aCGContext);
|
2017-05-10 05:31:07 +03:00
|
|
|
|
2017-05-10 23:21:13 +03:00
|
|
|
if (mNeedLayer) {
|
2017-05-10 05:31:07 +03:00
|
|
|
// A layer was used for clipping and is about to be popped by the restore.
|
|
|
|
// Make sure the CG context referencing it is released first so the popped
|
|
|
|
// layer doesn't accidentally get used.
|
|
|
|
if (mCG) {
|
|
|
|
CGContextRelease(mCG);
|
|
|
|
mCG = nullptr;
|
|
|
|
}
|
|
|
|
mCanvas->restore();
|
|
|
|
}
|
2016-05-17 21:41:38 +03:00
|
|
|
}
|
|
|
|
|
2016-08-03 17:53:12 +03:00
|
|
|
CGContextRef
|
|
|
|
BorrowedCGContext::BorrowCGContextFromDrawTarget(DrawTarget *aDT)
|
|
|
|
{
|
2016-10-19 06:22:44 +03:00
|
|
|
DrawTargetSkia* skiaDT = static_cast<DrawTargetSkia*>(aDT);
|
|
|
|
return skiaDT->BorrowCGContext(DrawOptions());
|
2016-08-03 17:53:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BorrowedCGContext::ReturnCGContextToDrawTarget(DrawTarget *aDT, CGContextRef cg)
|
|
|
|
{
|
2016-10-19 06:22:44 +03:00
|
|
|
DrawTargetSkia* skiaDT = static_cast<DrawTargetSkia*>(aDT);
|
|
|
|
skiaDT->ReturnCGContext(cg);
|
|
|
|
return;
|
2016-08-03 17:53:12 +03:00
|
|
|
}
|
|
|
|
|
2016-05-17 21:41:38 +03:00
|
|
|
static void
|
|
|
|
SetFontColor(CGContextRef aCGContext, CGColorSpaceRef aColorSpace, const Pattern& aPattern)
|
|
|
|
{
|
|
|
|
const Color& color = static_cast<const ColorPattern&>(aPattern).mColor;
|
|
|
|
CGColorRef textColor = ColorToCGColor(aColorSpace, color);
|
|
|
|
CGContextSetFillColorWithColor(aCGContext, textColor);
|
|
|
|
CGColorRelease(textColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* We need this to support subpixel AA text on OS X in two cases:
|
|
|
|
* text in DrawTargets that are not opaque and text over vibrant backgrounds.
|
|
|
|
* Skia normally doesn't support subpixel AA text on transparent backgrounds.
|
|
|
|
* To get around this, we have to wrap the Skia bytes with a CGContext and ask
|
|
|
|
* CG to draw the text.
|
|
|
|
* In vibrancy cases, we have to use a private API,
|
|
|
|
* CGContextSetFontSmoothingBackgroundColor, which sets the expected
|
|
|
|
* background color the text will draw onto so that CG can render the text
|
|
|
|
* properly. After that, we have to go back and fixup the pixels
|
|
|
|
* such that their alpha values are correct.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
DrawTargetSkia::FillGlyphsWithCG(ScaledFont *aFont,
|
|
|
|
const GlyphBuffer &aBuffer,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions,
|
|
|
|
const GlyphRenderingOptions *aRenderingOptions)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aFont->GetType() == FontType::MAC);
|
|
|
|
MOZ_ASSERT(aPattern.GetType() == PatternType::COLOR);
|
|
|
|
|
|
|
|
CGContextRef cgContext = BorrowCGContext(aOptions);
|
|
|
|
if (!cgContext) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<CGGlyph,32> glyphs;
|
|
|
|
Vector<CGPoint,32> positions;
|
|
|
|
if (!SetupCGGlyphs(cgContext, aBuffer, glyphs, positions)) {
|
2016-05-19 03:09:14 +03:00
|
|
|
ReturnCGContext(cgContext);
|
2016-05-17 21:41:38 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-17 22:59:46 +03:00
|
|
|
SetFontSmoothingBackgroundColor(cgContext, mColorSpace, aRenderingOptions);
|
2016-05-17 21:41:38 +03:00
|
|
|
SetFontColor(cgContext, mColorSpace, aPattern);
|
|
|
|
|
|
|
|
ScaledFontMac* macFont = static_cast<ScaledFontMac*>(aFont);
|
|
|
|
if (ScaledFontMac::CTFontDrawGlyphsPtr != nullptr) {
|
|
|
|
ScaledFontMac::CTFontDrawGlyphsPtr(macFont->mCTFont, glyphs.begin(),
|
|
|
|
positions.begin(),
|
|
|
|
aBuffer.mNumGlyphs, cgContext);
|
|
|
|
} else {
|
|
|
|
CGContextSetFont(cgContext, macFont->mFont);
|
|
|
|
CGContextSetFontSize(cgContext, macFont->mSize);
|
|
|
|
CGContextShowGlyphsAtPositions(cgContext, glyphs.begin(), positions.begin(),
|
|
|
|
aBuffer.mNumGlyphs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the area of the text we just drew
|
2016-11-15 12:00:08 +03:00
|
|
|
auto *bboxes = new CGRect[aBuffer.mNumGlyphs];
|
2016-05-17 21:41:38 +03:00
|
|
|
CTFontGetBoundingRectsForGlyphs(macFont->mCTFont, kCTFontDefaultOrientation,
|
|
|
|
glyphs.begin(), bboxes, aBuffer.mNumGlyphs);
|
|
|
|
CGRect extents = ComputeGlyphsExtents(bboxes, positions.begin(), aBuffer.mNumGlyphs, 1.0f);
|
|
|
|
delete[] bboxes;
|
|
|
|
|
|
|
|
CGAffineTransform cgTransform = CGContextGetCTM(cgContext);
|
|
|
|
extents = CGRectApplyAffineTransform(extents, cgTransform);
|
|
|
|
|
|
|
|
// Have to round it out to ensure we fully cover all pixels
|
|
|
|
Rect rect(extents.origin.x, extents.origin.y, extents.size.width, extents.size.height);
|
|
|
|
rect.RoundOut();
|
|
|
|
extents = CGRectMake(rect.x, rect.y, rect.width, rect.height);
|
|
|
|
|
|
|
|
EnsureValidPremultipliedData(cgContext, extents);
|
|
|
|
|
|
|
|
ReturnCGContext(cgContext);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
HasFontSmoothingBackgroundColor(const GlyphRenderingOptions* aRenderingOptions)
|
|
|
|
{
|
|
|
|
// This should generally only be true if we have a popup context menu
|
|
|
|
if (aRenderingOptions && aRenderingOptions->GetType() == FontType::MAC) {
|
|
|
|
Color fontSmoothingBackgroundColor =
|
|
|
|
static_cast<const GlyphRenderingOptionsCG*>(aRenderingOptions)->FontSmoothingBackgroundColor();
|
|
|
|
return fontSmoothingBackgroundColor.a > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ShouldUseCGToFillGlyphs(const GlyphRenderingOptions* aOptions, const Pattern& aPattern)
|
|
|
|
{
|
|
|
|
return HasFontSmoothingBackgroundColor(aOptions) &&
|
|
|
|
aPattern.GetType() == PatternType::COLOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-09-03 01:00:29 +03:00
|
|
|
static bool
|
|
|
|
CanDrawFont(ScaledFont* aFont)
|
2011-11-02 23:55:03 +04:00
|
|
|
{
|
2016-07-20 22:07:11 +03:00
|
|
|
switch (aFont->GetType()) {
|
|
|
|
case FontType::SKIA:
|
|
|
|
case FontType::CAIRO:
|
|
|
|
case FontType::FONTCONFIG:
|
|
|
|
case FontType::MAC:
|
|
|
|
case FontType::GDI:
|
|
|
|
case FontType::DWRITE:
|
2016-09-03 01:00:29 +03:00
|
|
|
return true;
|
2016-07-20 22:07:11 +03:00
|
|
|
default:
|
2016-09-03 01:00:29 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-12 17:24:44 +03:00
|
|
|
DrawTargetSkia::DrawGlyphs(ScaledFont* aFont,
|
|
|
|
const GlyphBuffer& aBuffer,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const StrokeOptions* aStrokeOptions,
|
|
|
|
const DrawOptions& aOptions,
|
|
|
|
const GlyphRenderingOptions* aRenderingOptions)
|
2016-09-03 01:00:29 +03:00
|
|
|
{
|
|
|
|
if (!CanDrawFont(aFont)) {
|
2011-11-02 23:55:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
MarkChanged();
|
|
|
|
|
2016-05-17 21:41:38 +03:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2017-02-12 17:24:44 +03:00
|
|
|
if (!aStrokeOptions &&
|
|
|
|
ShouldUseCGToFillGlyphs(aRenderingOptions, aPattern)) {
|
2016-05-17 21:41:38 +03:00
|
|
|
if (FillGlyphsWithCG(aFont, aBuffer, aPattern, aOptions, aRenderingOptions)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-01-09 22:54:44 +04:00
|
|
|
ScaledFontBase* skiaFont = static_cast<ScaledFontBase*>(aFont);
|
2016-05-20 19:16:29 +03:00
|
|
|
SkTypeface* typeface = skiaFont->GetSkTypeface();
|
|
|
|
if (!typeface) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2017-05-10 05:31:07 +03:00
|
|
|
AutoPaintSetup paint(mCanvas, aOptions, aPattern);
|
2017-02-12 17:24:44 +03:00
|
|
|
if (aStrokeOptions &&
|
|
|
|
!StrokeOptionsToPaint(paint.mPaint, *aStrokeOptions)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-03 01:00:29 +03:00
|
|
|
AntialiasMode aaMode = aFont->GetDefaultAAMode();
|
|
|
|
if (aOptions.mAntialiasMode != AntialiasMode::DEFAULT) {
|
|
|
|
aaMode = aOptions.mAntialiasMode;
|
|
|
|
}
|
|
|
|
bool aaEnabled = aaMode != AntialiasMode::NONE;
|
|
|
|
|
|
|
|
paint.mPaint.setAntiAlias(aaEnabled);
|
2016-10-25 05:40:59 +03:00
|
|
|
paint.mPaint.setTypeface(sk_ref_sp(typeface));
|
2011-11-02 23:55:03 +04:00
|
|
|
paint.mPaint.setTextSize(SkFloatToScalar(skiaFont->mSize));
|
|
|
|
paint.mPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
2013-06-05 21:48:59 +04:00
|
|
|
|
2016-09-03 01:00:29 +03:00
|
|
|
bool shouldLCDRenderText = ShouldLCDRenderText(aFont->GetType(), aaMode);
|
2015-05-04 20:23:54 +03:00
|
|
|
paint.mPaint.setLCDRenderText(shouldLCDRenderText);
|
|
|
|
|
2016-07-20 22:07:11 +03:00
|
|
|
bool useSubpixelText = true;
|
2015-09-02 21:12:32 +03:00
|
|
|
|
2016-07-20 22:07:11 +03:00
|
|
|
switch (aFont->GetType()) {
|
|
|
|
case FontType::SKIA:
|
|
|
|
case FontType::CAIRO:
|
|
|
|
case FontType::FONTCONFIG:
|
2016-05-09 19:34:00 +03:00
|
|
|
// SkFontHost_cairo does not support subpixel text positioning,
|
|
|
|
// so only enable it for other font hosts.
|
2016-07-20 22:07:11 +03:00
|
|
|
useSubpixelText = false;
|
|
|
|
break;
|
|
|
|
case FontType::MAC:
|
2016-09-03 01:00:29 +03:00
|
|
|
if (aaMode == AntialiasMode::GRAY) {
|
2016-05-09 19:34:00 +03:00
|
|
|
// Normally, Skia enables LCD FontSmoothing which creates thicker fonts
|
|
|
|
// and also enables subpixel AA. CoreGraphics without font smoothing
|
|
|
|
// explicitly creates thinner fonts and grayscale AA.
|
|
|
|
// CoreGraphics doesn't support a configuration that produces thicker
|
|
|
|
// fonts with grayscale AA as LCD Font Smoothing enables or disables both.
|
|
|
|
// However, Skia supports it by enabling font smoothing (producing subpixel AA)
|
|
|
|
// and converts it to grayscale AA. Since Skia doesn't support subpixel AA on
|
|
|
|
// transparent backgrounds, we still want font smoothing for the thicker fonts,
|
|
|
|
// even if it is grayscale AA.
|
|
|
|
//
|
|
|
|
// With explicit Grayscale AA (from -moz-osx-font-smoothing:grayscale),
|
|
|
|
// we want to have grayscale AA with no smoothing at all. This means
|
|
|
|
// disabling the LCD font smoothing behaviour.
|
|
|
|
// To accomplish this we have to explicitly disable hinting,
|
|
|
|
// and disable LCDRenderText.
|
2016-02-25 04:35:38 +03:00
|
|
|
paint.mPaint.setHinting(SkPaint::kNo_Hinting);
|
|
|
|
}
|
2016-07-20 22:07:11 +03:00
|
|
|
break;
|
|
|
|
case FontType::GDI:
|
2016-09-03 01:00:29 +03:00
|
|
|
{
|
2016-09-16 22:11:35 +03:00
|
|
|
if (!shouldLCDRenderText && aaEnabled) {
|
2016-09-03 01:00:29 +03:00
|
|
|
// If we have non LCD GDI text, render the fonts as cleartype and convert them
|
|
|
|
// to grayscale. This seems to be what Chrome and IE are doing on Windows 7.
|
|
|
|
// This also applies if cleartype is disabled system wide.
|
2016-07-20 22:07:11 +03:00
|
|
|
paint.mPaint.setFlags(paint.mPaint.getFlags() | SkPaint::kGenA8FromLCD_Flag);
|
|
|
|
}
|
|
|
|
break;
|
2016-09-03 01:00:29 +03:00
|
|
|
}
|
2016-09-08 19:55:42 +03:00
|
|
|
#ifdef XP_WIN
|
2016-09-08 19:34:10 +03:00
|
|
|
case FontType::DWRITE:
|
|
|
|
{
|
|
|
|
ScaledFontDWrite* dwriteFont = static_cast<ScaledFontDWrite*>(aFont);
|
|
|
|
paint.mPaint.setEmbeddedBitmapText(dwriteFont->UseEmbeddedBitmaps());
|
2016-09-16 22:25:42 +03:00
|
|
|
|
|
|
|
if (dwriteFont->ForceGDIMode()) {
|
|
|
|
paint.mPaint.setEmbeddedBitmapText(true);
|
|
|
|
useSubpixelText = false;
|
|
|
|
}
|
2016-09-08 19:34:10 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-09-08 19:55:42 +03:00
|
|
|
#endif
|
2016-07-20 22:07:11 +03:00
|
|
|
default:
|
|
|
|
break;
|
2013-06-05 21:48:59 +04:00
|
|
|
}
|
|
|
|
|
2016-07-20 22:07:11 +03:00
|
|
|
paint.mPaint.setSubpixelText(useSubpixelText);
|
2016-06-06 20:00:33 +03:00
|
|
|
|
2017-07-28 10:43:28 +03:00
|
|
|
const uint32_t heapSize = 64;
|
|
|
|
uint16_t indicesOnStack[heapSize];
|
|
|
|
SkPoint offsetsOnStack[heapSize];
|
|
|
|
std::vector<uint16_t> indicesOnHeap;
|
|
|
|
std::vector<SkPoint> offsetsOnHeap;
|
|
|
|
uint16_t* indices = indicesOnStack;
|
|
|
|
SkPoint* offsets = offsetsOnStack;
|
|
|
|
if (aBuffer.mNumGlyphs > heapSize) {
|
|
|
|
// Heap allocation/ deallocation is slow, use it only if we need a
|
|
|
|
// bigger(>heapSize) buffer.
|
|
|
|
indicesOnHeap.resize(aBuffer.mNumGlyphs);
|
|
|
|
offsetsOnHeap.resize(aBuffer.mNumGlyphs);
|
|
|
|
indices = (uint16_t*)&indicesOnHeap.front();
|
|
|
|
offsets = (SkPoint*)&offsetsOnHeap.front();
|
|
|
|
}
|
2011-11-02 23:55:03 +04:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
|
|
|
|
indices[i] = aBuffer.mGlyphs[i].mIndex;
|
|
|
|
offsets[i].fX = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.x);
|
|
|
|
offsets[i].fY = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.y);
|
|
|
|
}
|
|
|
|
|
2017-07-28 10:43:28 +03:00
|
|
|
mCanvas->drawPosText(indices, aBuffer.mNumGlyphs*2, offsets, paint.mPaint);
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2017-02-12 17:24:44 +03:00
|
|
|
void
|
|
|
|
DrawTargetSkia::FillGlyphs(ScaledFont* aFont,
|
|
|
|
const GlyphBuffer& aBuffer,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions,
|
|
|
|
const GlyphRenderingOptions* aRenderingOptions)
|
|
|
|
{
|
|
|
|
DrawGlyphs(aFont, aBuffer, aPattern, nullptr, aOptions, aRenderingOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::StrokeGlyphs(ScaledFont* aFont,
|
|
|
|
const GlyphBuffer& aBuffer,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions,
|
|
|
|
const DrawOptions& aOptions,
|
|
|
|
const GlyphRenderingOptions* aRenderingOptions)
|
|
|
|
{
|
|
|
|
DrawGlyphs(aFont, aBuffer, aPattern, &aStrokeOptions, aOptions, aRenderingOptions);
|
|
|
|
}
|
|
|
|
|
2012-01-19 08:48:33 +04:00
|
|
|
void
|
|
|
|
DrawTargetSkia::Mask(const Pattern &aSource,
|
|
|
|
const Pattern &aMask,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
MarkChanged();
|
2017-05-10 05:31:07 +03:00
|
|
|
AutoPaintSetup paint(mCanvas, aOptions, aSource);
|
2012-01-19 08:48:33 +04:00
|
|
|
|
|
|
|
SkPaint maskPaint;
|
2016-01-12 21:05:13 +03:00
|
|
|
SetPaintPattern(maskPaint, aMask);
|
2014-10-08 08:16:14 +04:00
|
|
|
|
2014-06-20 22:47:27 +04:00
|
|
|
SkLayerRasterizer::Builder builder;
|
|
|
|
builder.addLayer(maskPaint);
|
2016-04-29 05:55:27 +03:00
|
|
|
sk_sp<SkLayerRasterizer> raster(builder.detach());
|
|
|
|
paint.mPaint.setRasterizer(raster);
|
2012-01-19 08:48:33 +04:00
|
|
|
|
2016-01-12 21:26:31 +03:00
|
|
|
mCanvas->drawPaint(paint.mPaint);
|
2012-01-19 08:48:33 +04:00
|
|
|
}
|
|
|
|
|
2013-11-25 18:20:56 +04:00
|
|
|
void
|
|
|
|
DrawTargetSkia::MaskSurface(const Pattern &aSource,
|
|
|
|
SourceSurface *aMask,
|
|
|
|
Point aOffset,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
MarkChanged();
|
2017-05-10 05:31:07 +03:00
|
|
|
AutoPaintSetup paint(mCanvas, aOptions, aSource, nullptr, -aOffset);
|
2013-11-25 18:20:56 +04:00
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkImage> alphaMask = ExtractAlphaForSurface(aMask);
|
|
|
|
if (!alphaMask) {
|
2016-01-12 21:26:31 +03:00
|
|
|
gfxDebug() << *this << ": MaskSurface() failed to extract alpha for mask";
|
|
|
|
return;
|
|
|
|
}
|
2015-11-19 18:25:15 +03:00
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
mCanvas->drawImage(alphaMask, aOffset.x, aOffset.y, &paint.mPaint);
|
2013-11-25 18:20:56 +04:00
|
|
|
}
|
|
|
|
|
2016-03-23 08:03:10 +03:00
|
|
|
bool
|
|
|
|
DrawTarget::Draw3DTransformedSurface(SourceSurface* aSurface, const Matrix4x4& aMatrix)
|
|
|
|
{
|
|
|
|
// Composite the 3D transform with the DT's transform.
|
|
|
|
Matrix4x4 fullMat = aMatrix * Matrix4x4::From2D(mTransform);
|
|
|
|
if (fullMat.IsSingular()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Transform the surface bounds and clip to this DT.
|
|
|
|
IntRect xformBounds =
|
|
|
|
RoundedOut(
|
|
|
|
fullMat.TransformAndClipBounds(Rect(Point(0, 0), Size(aSurface->GetSize())),
|
|
|
|
Rect(Point(0, 0), Size(GetSize()))));
|
|
|
|
if (xformBounds.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Offset the matrix by the transformed origin.
|
|
|
|
fullMat.PostTranslate(-xformBounds.x, -xformBounds.y, 0);
|
|
|
|
|
|
|
|
// Read in the source data.
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkImage> srcImage = GetSkImageForSurface(aSurface);
|
|
|
|
if (!srcImage) {
|
2016-09-02 04:17:03 +03:00
|
|
|
return true;
|
|
|
|
}
|
2016-03-23 08:03:10 +03:00
|
|
|
|
|
|
|
// Set up an intermediate destination surface only the size of the transformed bounds.
|
|
|
|
// Try to pass through the source's format unmodified in both the BGRA and ARGB cases.
|
|
|
|
RefPtr<DataSourceSurface> dstSurf =
|
|
|
|
Factory::CreateDataSourceSurface(xformBounds.Size(),
|
2016-10-25 05:40:59 +03:00
|
|
|
!srcImage->isOpaque() ?
|
2016-03-23 08:03:10 +03:00
|
|
|
aSurface->GetFormat() : SurfaceFormat::A8R8G8B8_UINT32,
|
|
|
|
true);
|
|
|
|
if (!dstSurf) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-10 05:31:07 +03:00
|
|
|
std::unique_ptr<SkCanvas> dstCanvas(
|
|
|
|
SkCanvas::MakeRasterDirect(
|
2017-08-14 15:29:28 +03:00
|
|
|
SkImageInfo::Make(xformBounds.Width(), xformBounds.Height(),
|
2016-10-25 05:40:59 +03:00
|
|
|
GfxFormatToSkiaColorType(dstSurf->GetFormat()),
|
2016-03-23 08:03:10 +03:00
|
|
|
kPremul_SkAlphaType),
|
|
|
|
dstSurf->GetData(), dstSurf->Stride()));
|
|
|
|
if (!dstCanvas) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do the transform.
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setFilterQuality(kLow_SkFilterQuality);
|
2016-10-25 05:40:59 +03:00
|
|
|
paint.setBlendMode(SkBlendMode::kSrc);
|
2016-03-23 08:03:10 +03:00
|
|
|
|
|
|
|
SkMatrix xform;
|
|
|
|
GfxMatrixToSkiaMatrix(fullMat, xform);
|
|
|
|
dstCanvas->setMatrix(xform);
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
dstCanvas->drawImage(srcImage, 0, 0, &paint);
|
2016-03-23 08:03:10 +03:00
|
|
|
dstCanvas->flush();
|
|
|
|
|
|
|
|
// Temporarily reset the DT's transform, since it has already been composed above.
|
|
|
|
Matrix origTransform = mTransform;
|
|
|
|
SetTransform(Matrix());
|
|
|
|
|
|
|
|
// Draw the transformed surface within the transformed bounds.
|
|
|
|
DrawSurface(dstSurf, Rect(xformBounds), Rect(Point(0, 0), Size(xformBounds.Size())));
|
|
|
|
|
|
|
|
SetTransform(origTransform);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DrawTargetSkia::Draw3DTransformedSurface(SourceSurface* aSurface, const Matrix4x4& aMatrix)
|
|
|
|
{
|
|
|
|
if (aMatrix.IsSingular()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-16 18:03:48 +03:00
|
|
|
MarkChanged();
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
|
|
|
|
if (!image) {
|
2016-09-02 04:17:03 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-23 08:03:10 +03:00
|
|
|
mCanvas->save();
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setFilterQuality(kLow_SkFilterQuality);
|
|
|
|
|
|
|
|
SkMatrix xform;
|
|
|
|
GfxMatrixToSkiaMatrix(aMatrix, xform);
|
|
|
|
mCanvas->concat(xform);
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
mCanvas->drawImage(image, 0, 0, &paint);
|
2016-03-23 08:03:10 +03:00
|
|
|
|
|
|
|
mCanvas->restore();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2011-11-02 23:55:03 +04:00
|
|
|
DrawTargetSkia::CreateSourceSurfaceFromData(unsigned char *aData,
|
2013-11-01 17:13:36 +04:00
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
|
|
|
SurfaceFormat aFormat) const
|
2011-11-02 23:55:03 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurfaceSkia> newSurf = new SourceSurfaceSkia();
|
2011-11-02 23:55:03 +04:00
|
|
|
|
|
|
|
if (!newSurf->InitFromData(aData, aSize, aStride, aFormat)) {
|
|
|
|
gfxDebug() << *this << ": Failure to create source surface from data. Size: " << aSize;
|
2012-08-14 22:06:12 +04:00
|
|
|
return nullptr;
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
2014-10-08 08:16:14 +04:00
|
|
|
|
2014-06-13 20:09:23 +04:00
|
|
|
return newSurf.forget();
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
2011-11-02 23:55:03 +04:00
|
|
|
DrawTargetSkia::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTargetSkia> target = new DrawTargetSkia();
|
2016-01-21 17:51:40 +03:00
|
|
|
#ifdef USE_SKIA_GPU
|
|
|
|
if (UsingSkiaGPU()) {
|
|
|
|
// Try to create a GPU draw target first if we're currently using the GPU.
|
2016-02-03 21:49:36 +03:00
|
|
|
// Mark the DT as cached so that shadow DTs, extracted subrects, and similar can be reused.
|
|
|
|
if (target->InitWithGrContext(mGrContext.get(), aSize, aFormat, true)) {
|
2016-01-21 17:51:40 +03:00
|
|
|
return target.forget();
|
|
|
|
}
|
|
|
|
// Otherwise, just fall back to a software draw target.
|
|
|
|
}
|
|
|
|
#endif
|
2016-10-31 18:05:30 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2017-05-10 05:31:07 +03:00
|
|
|
if (!IsBackedByPixels(mCanvas)) {
|
2016-12-22 04:35:22 +03:00
|
|
|
// If our canvas is backed by vector storage such as PDF then we want to
|
|
|
|
// create a new DrawTarget with similar storage to avoid losing fidelity
|
|
|
|
// (fidelity will be lost if the returned DT is Snapshot()'ed and drawn
|
|
|
|
// back onto us since a raster will be drawn instead of vector commands).
|
2016-10-31 18:05:30 +03:00
|
|
|
NS_WARNING("Not backed by pixels - we need to handle PDF backed SkCanvas");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
if (!target->Init(aSize, aFormat)) {
|
2012-08-14 22:06:12 +04:00
|
|
|
return nullptr;
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
2014-06-13 20:09:23 +04:00
|
|
|
return target.forget();
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2014-05-23 09:09:34 +04:00
|
|
|
bool
|
|
|
|
DrawTargetSkia::UsingSkiaGPU() const
|
|
|
|
{
|
|
|
|
#ifdef USE_SKIA_GPU
|
2016-01-21 17:51:40 +03:00
|
|
|
return !!mGrContext;
|
2014-05-23 09:09:34 +04:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-05 20:29:12 +03:00
|
|
|
#ifdef USE_SKIA_GPU
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2016-08-05 20:29:12 +03:00
|
|
|
DrawTargetSkia::OptimizeGPUSourceSurface(SourceSurface *aSurface) const
|
2011-11-02 23:55:03 +04:00
|
|
|
{
|
2016-10-25 05:40:59 +03:00
|
|
|
// Check if the underlying SkImage already has an associated GrTexture.
|
|
|
|
sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
|
|
|
|
if (!image || image->isTextureBacked()) {
|
2016-08-05 20:29:12 +03:00
|
|
|
RefPtr<SourceSurface> surface(aSurface);
|
|
|
|
return surface.forget();
|
|
|
|
}
|
2013-11-01 17:13:36 +04:00
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
// Upload the SkImage to a GrTexture otherwise.
|
2017-05-10 05:31:07 +03:00
|
|
|
sk_sp<SkImage> texture = image->makeTextureImage(mGrContext.get(), nullptr);
|
2016-08-05 20:29:12 +03:00
|
|
|
if (texture) {
|
2016-10-25 05:40:59 +03:00
|
|
|
// Create a new SourceSurfaceSkia whose SkImage contains the GrTexture.
|
2016-08-05 20:29:12 +03:00
|
|
|
RefPtr<SourceSurfaceSkia> surface = new SourceSurfaceSkia();
|
2016-10-25 05:40:59 +03:00
|
|
|
if (surface->InitFromImage(texture, aSurface->GetFormat())) {
|
2016-01-21 17:52:08 +03:00
|
|
|
return surface.forget();
|
|
|
|
}
|
2016-08-05 20:29:12 +03:00
|
|
|
}
|
2016-02-03 21:49:36 +03:00
|
|
|
|
2016-08-05 20:29:12 +03:00
|
|
|
// The data was too big to fit in a GrTexture.
|
|
|
|
if (aSurface->GetType() == SurfaceType::SKIA) {
|
|
|
|
// It is already a Skia source surface, so just reuse it as-is.
|
|
|
|
RefPtr<SourceSurface> surface(aSurface);
|
|
|
|
return surface.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wrap it in a Skia source surface so that can do tiled uploads on-demand.
|
|
|
|
RefPtr<SourceSurfaceSkia> surface = new SourceSurfaceSkia();
|
2016-10-25 05:40:59 +03:00
|
|
|
surface->InitFromImage(image);
|
2016-08-05 20:29:12 +03:00
|
|
|
return surface.forget();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
already_AddRefed<SourceSurface>
|
|
|
|
DrawTargetSkia::OptimizeSourceSurfaceForUnknownAlpha(SourceSurface *aSurface) const
|
|
|
|
{
|
|
|
|
#ifdef USE_SKIA_GPU
|
|
|
|
if (UsingSkiaGPU()) {
|
|
|
|
return OptimizeGPUSourceSurface(aSurface);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (aSurface->GetType() == SurfaceType::SKIA) {
|
|
|
|
RefPtr<SourceSurface> surface(aSurface);
|
2016-02-03 21:49:36 +03:00
|
|
|
return surface.forget();
|
2014-05-23 09:09:34 +04:00
|
|
|
}
|
2016-08-05 20:29:12 +03:00
|
|
|
|
|
|
|
RefPtr<DataSourceSurface> dataSurface = aSurface->GetDataSurface();
|
|
|
|
|
|
|
|
// For plugins, GDI can sometimes just write 0 to the alpha channel
|
|
|
|
// even for RGBX formats. In this case, we have to manually write
|
|
|
|
// the alpha channel to make Skia happy with RGBX and in case GDI
|
|
|
|
// writes some bad data. Luckily, this only happens on plugins.
|
|
|
|
WriteRGBXFormat(dataSurface->GetData(), dataSurface->GetSize(),
|
|
|
|
dataSurface->Stride(), dataSurface->GetFormat());
|
|
|
|
return dataSurface.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SourceSurface>
|
|
|
|
DrawTargetSkia::OptimizeSourceSurface(SourceSurface *aSurface) const
|
|
|
|
{
|
|
|
|
#ifdef USE_SKIA_GPU
|
|
|
|
if (UsingSkiaGPU()) {
|
|
|
|
return OptimizeGPUSourceSurface(aSurface);
|
|
|
|
}
|
2016-01-21 17:52:08 +03:00
|
|
|
#endif
|
2014-05-23 09:09:34 +04:00
|
|
|
|
2016-01-21 17:52:08 +03:00
|
|
|
if (aSurface->GetType() == SurfaceType::SKIA) {
|
|
|
|
RefPtr<SourceSurface> surface(aSurface);
|
|
|
|
return surface.forget();
|
2014-05-23 09:09:34 +04:00
|
|
|
}
|
|
|
|
|
2016-01-21 17:52:08 +03:00
|
|
|
// If we're not using skia-gl then drawing doesn't require any
|
|
|
|
// uploading, so any data surface is fine. Call GetDataSurface
|
|
|
|
// to trigger any required readback so that it only happens
|
|
|
|
// once.
|
2016-07-26 02:36:35 +03:00
|
|
|
RefPtr<DataSourceSurface> dataSurface = aSurface->GetDataSurface();
|
|
|
|
MOZ_ASSERT(VerifyRGBXFormat(dataSurface->GetData(), dataSurface->GetSize(),
|
|
|
|
dataSurface->Stride(), dataSurface->GetFormat()));
|
|
|
|
return dataSurface.forget();
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2011-11-02 23:55:03 +04:00
|
|
|
DrawTargetSkia::CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const
|
|
|
|
{
|
2016-09-02 04:10:39 +03:00
|
|
|
#ifdef USE_SKIA_GPU
|
2016-01-20 21:31:44 +03:00
|
|
|
if (aSurface.mType == NativeSurfaceType::OPENGL_TEXTURE && UsingSkiaGPU()) {
|
2016-01-21 17:51:40 +03:00
|
|
|
// Wrap the OpenGL texture id in a Skia texture handle.
|
|
|
|
GrBackendTextureDesc texDesc;
|
|
|
|
texDesc.fWidth = aSurface.mSize.width;
|
|
|
|
texDesc.fHeight = aSurface.mSize.height;
|
|
|
|
texDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
|
|
|
|
texDesc.fConfig = GfxFormatToGrConfig(aSurface.mFormat);
|
|
|
|
|
|
|
|
GrGLTextureInfo texInfo;
|
|
|
|
texInfo.fTarget = LOCAL_GL_TEXTURE_2D;
|
|
|
|
texInfo.fID = (GrGLuint)(uintptr_t)aSurface.mSurface;
|
|
|
|
texDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&texInfo);
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkImage> texture =
|
|
|
|
SkImage::MakeFromAdoptedTexture(mGrContext.get(), texDesc,
|
|
|
|
GfxFormatToSkiaAlphaType(aSurface.mFormat));
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurfaceSkia> newSurf = new SourceSurfaceSkia();
|
2016-10-25 05:40:59 +03:00
|
|
|
if (texture && newSurf->InitFromImage(texture, aSurface.mFormat)) {
|
2015-04-30 22:20:30 +03:00
|
|
|
return newSurf.forget();
|
2014-11-11 23:14:00 +03:00
|
|
|
}
|
|
|
|
return nullptr;
|
2014-07-04 01:06:48 +04:00
|
|
|
}
|
2016-01-20 21:31:44 +03:00
|
|
|
#endif
|
2014-07-04 01:06:48 +04:00
|
|
|
|
2012-08-14 22:06:12 +04:00
|
|
|
return nullptr;
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::CopySurface(SourceSurface *aSurface,
|
|
|
|
const IntRect& aSourceRect,
|
|
|
|
const IntPoint &aDestination)
|
|
|
|
{
|
2016-09-16 18:03:48 +03:00
|
|
|
MarkChanged();
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
|
|
|
|
if (!image) {
|
2011-11-02 23:55:03 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-11-02 23:55:03 +04:00
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
mCanvas->save();
|
2016-06-21 23:14:28 +03:00
|
|
|
mCanvas->setMatrix(SkMatrix::MakeTrans(SkIntToScalar(aDestination.x), SkIntToScalar(aDestination.y)));
|
2017-08-14 15:29:28 +03:00
|
|
|
mCanvas->clipRect(SkRect::MakeIWH(aSourceRect.Width(), aSourceRect.Height()), SkClipOp::kReplace_deprecated);
|
2012-05-31 22:56:33 +04:00
|
|
|
|
2016-01-13 21:11:07 +03:00
|
|
|
SkPaint paint;
|
2016-10-25 05:40:59 +03:00
|
|
|
if (!image->isOpaque()) {
|
2016-01-13 21:11:07 +03:00
|
|
|
// Keep the xfermode as SOURCE_OVER for opaque bitmaps
|
2012-05-31 22:56:33 +04:00
|
|
|
// http://code.google.com/p/skia/issues/detail?id=628
|
2016-10-25 05:40:59 +03:00
|
|
|
paint.setBlendMode(SkBlendMode::kSrc);
|
2012-05-31 22:56:33 +04:00
|
|
|
}
|
2016-10-25 05:40:59 +03:00
|
|
|
// drawImage with A8 images ends up doing a mask operation
|
2014-06-11 07:42:32 +04:00
|
|
|
// so we need to clear before
|
2016-10-25 05:40:59 +03:00
|
|
|
if (SkImageIsMask(image)) {
|
2016-01-13 21:11:07 +03:00
|
|
|
mCanvas->clear(SK_ColorTRANSPARENT);
|
2014-06-11 07:42:32 +04:00
|
|
|
}
|
2016-10-25 05:40:59 +03:00
|
|
|
mCanvas->drawImage(image, -SkIntToScalar(aSourceRect.x), -SkIntToScalar(aSourceRect.y), &paint);
|
2011-11-02 23:55:03 +04:00
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DrawTargetSkia::Init(const IntSize &aSize, SurfaceFormat aFormat)
|
|
|
|
{
|
2015-11-19 21:35:31 +03:00
|
|
|
if (size_t(std::max(aSize.width, aSize.height)) > GetMaxSurfaceSize()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-08 19:16:46 +03:00
|
|
|
// we need to have surfaces that have a stride aligned to 4 for interop with cairo
|
2016-10-25 05:40:59 +03:00
|
|
|
SkImageInfo info = MakeSkiaImageInfo(aSize, aFormat);
|
|
|
|
size_t stride = SkAlign4(info.minRowBytes());
|
|
|
|
mSurface = SkSurface::MakeRaster(info, stride, nullptr);
|
|
|
|
if (!mSurface) {
|
2011-11-02 23:55:03 +04:00
|
|
|
return false;
|
|
|
|
}
|
2013-05-29 20:49:40 +04:00
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
mSize = aSize;
|
2016-10-25 02:45:46 +03:00
|
|
|
mFormat = aFormat;
|
2017-05-10 05:31:07 +03:00
|
|
|
mCanvas = mSurface->getCanvas();
|
2016-12-16 19:02:04 +03:00
|
|
|
SetPermitSubpixelAA(IsOpaque(mFormat));
|
2016-10-25 05:40:59 +03:00
|
|
|
|
|
|
|
if (info.isOpaque()) {
|
|
|
|
mCanvas->clear(SK_ColorBLACK);
|
|
|
|
}
|
2011-11-02 23:55:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-26 21:23:07 +03:00
|
|
|
bool
|
|
|
|
DrawTargetSkia::Init(SkCanvas* aCanvas)
|
|
|
|
{
|
2017-05-10 05:31:07 +03:00
|
|
|
mCanvas = aCanvas;
|
2016-10-26 21:23:07 +03:00
|
|
|
|
|
|
|
SkImageInfo imageInfo = mCanvas->imageInfo();
|
|
|
|
|
|
|
|
// If the canvas is backed by pixels we clear it to be on the safe side. If
|
|
|
|
// it's not (for example, for PDF output) we don't.
|
2017-05-10 05:31:07 +03:00
|
|
|
if (IsBackedByPixels(mCanvas)) {
|
2016-10-26 21:23:07 +03:00
|
|
|
SkColor clearColor = imageInfo.isOpaque() ? SK_ColorBLACK : SK_ColorTRANSPARENT;
|
|
|
|
mCanvas->clear(clearColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize size = mCanvas->getBaseLayerSize();
|
|
|
|
mSize.width = size.width();
|
|
|
|
mSize.height = size.height();
|
|
|
|
mFormat = SkiaColorTypeToGfxFormat(imageInfo.colorType(),
|
|
|
|
imageInfo.alphaType());
|
2016-12-16 19:02:04 +03:00
|
|
|
SetPermitSubpixelAA(IsOpaque(mFormat));
|
2016-10-26 21:23:07 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-14 03:29:47 +04:00
|
|
|
#ifdef USE_SKIA_GPU
|
2016-02-03 21:49:36 +03:00
|
|
|
/** Indicating a DT should be cached means that space will be reserved in Skia's cache
|
|
|
|
* for the render target at creation time, with any unused resources exceeding the cache
|
|
|
|
* limits being purged. When the DT is freed, it will then be guaranteed to be kept around
|
|
|
|
* for subsequent allocations until it gets incidentally purged.
|
|
|
|
*
|
|
|
|
* If it is not marked as cached, no space will be purged to make room for the render
|
|
|
|
* target in the cache. When the DT is freed, If there is space within the resource limits
|
|
|
|
* it may be added to the cache, otherwise it will be freed immediately if the cache is
|
|
|
|
* already full.
|
|
|
|
*
|
|
|
|
* If you want to ensure that the resources will be kept around for reuse, it is better
|
|
|
|
* to mark them as cached. Such resources should be short-lived to ensure they don't
|
|
|
|
* permanently tie up cache resource limits. Long-lived resources should generally be
|
|
|
|
* left as uncached.
|
|
|
|
*
|
|
|
|
* In neither case will cache resource limits affect whether the resource allocation
|
|
|
|
* succeeds. The amount of in-use GPU resources is allowed to exceed the size of the cache.
|
|
|
|
* Thus, only hard GPU out-of-memory conditions will cause resource allocation to fail.
|
|
|
|
*/
|
2014-03-26 22:21:50 +04:00
|
|
|
bool
|
2014-03-06 01:49:37 +04:00
|
|
|
DrawTargetSkia::InitWithGrContext(GrContext* aGrContext,
|
|
|
|
const IntSize &aSize,
|
2016-02-03 21:49:36 +03:00
|
|
|
SurfaceFormat aFormat,
|
|
|
|
bool aCached)
|
2012-12-01 03:57:38 +04:00
|
|
|
{
|
2014-03-24 18:13:55 +04:00
|
|
|
MOZ_ASSERT(aGrContext, "null GrContext");
|
|
|
|
|
2015-11-19 21:35:31 +03:00
|
|
|
if (size_t(std::max(aSize.width, aSize.height)) > GetMaxSurfaceSize()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-21 17:51:40 +03:00
|
|
|
// Create a GPU rendertarget/texture using the supplied GrContext.
|
2017-05-10 05:31:07 +03:00
|
|
|
// MakeRenderTarget also implicitly clears the underlying texture on creation.
|
2016-10-25 05:40:59 +03:00
|
|
|
mSurface =
|
2016-04-29 05:55:27 +03:00
|
|
|
SkSurface::MakeRenderTarget(aGrContext,
|
|
|
|
SkBudgeted(aCached),
|
|
|
|
MakeSkiaImageInfo(aSize, aFormat));
|
2016-10-25 05:40:59 +03:00
|
|
|
if (!mSurface) {
|
2015-12-18 21:53:25 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
mGrContext = sk_ref_sp(aGrContext);
|
2016-01-21 17:51:40 +03:00
|
|
|
mSize = aSize;
|
|
|
|
mFormat = aFormat;
|
2017-05-10 05:31:07 +03:00
|
|
|
mCanvas = mSurface->getCanvas();
|
2016-12-16 19:02:04 +03:00
|
|
|
SetPermitSubpixelAA(IsOpaque(mFormat));
|
2014-03-26 22:21:50 +04:00
|
|
|
return true;
|
2013-08-28 18:08:10 +04:00
|
|
|
}
|
|
|
|
|
2013-03-14 03:29:47 +04:00
|
|
|
#endif
|
2012-12-01 03:57:38 +04:00
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
bool
|
2016-03-18 23:58:55 +03:00
|
|
|
DrawTargetSkia::Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat, bool aUninitialized)
|
2012-01-19 08:48:33 +04:00
|
|
|
{
|
2016-02-17 18:34:37 +03:00
|
|
|
MOZ_ASSERT((aFormat != SurfaceFormat::B8G8R8X8) ||
|
2016-03-18 23:58:55 +03:00
|
|
|
aUninitialized || VerifyRGBXFormat(aData, aSize, aStride, aFormat));
|
2014-03-26 23:58:07 +04:00
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
mSurface = SkSurface::MakeRasterDirect(MakeSkiaImageInfo(aSize, aFormat), aData, aStride);
|
|
|
|
if (!mSurface) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-29 20:49:40 +04:00
|
|
|
|
2012-01-19 08:48:33 +04:00
|
|
|
mSize = aSize;
|
|
|
|
mFormat = aFormat;
|
2017-05-10 05:31:07 +03:00
|
|
|
mCanvas = mSurface->getCanvas();
|
2016-12-16 19:02:04 +03:00
|
|
|
SetPermitSubpixelAA(IsOpaque(mFormat));
|
2016-10-25 05:40:59 +03:00
|
|
|
return true;
|
2012-01-19 08:48:33 +04:00
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
void
|
|
|
|
DrawTargetSkia::SetTransform(const Matrix& aTransform)
|
|
|
|
{
|
|
|
|
SkMatrix mat;
|
|
|
|
GfxMatrixToSkiaMatrix(aTransform, mat);
|
|
|
|
mCanvas->setMatrix(mat);
|
|
|
|
mTransform = aTransform;
|
|
|
|
}
|
|
|
|
|
2014-03-06 01:49:37 +04:00
|
|
|
void*
|
|
|
|
DrawTargetSkia::GetNativeSurface(NativeSurfaceType aType)
|
|
|
|
{
|
2014-10-15 07:55:37 +04:00
|
|
|
#ifdef USE_SKIA_GPU
|
2016-10-26 20:41:07 +03:00
|
|
|
if (aType == NativeSurfaceType::OPENGL_TEXTURE && mSurface) {
|
2016-10-25 05:40:59 +03:00
|
|
|
GrBackendObject handle = mSurface->getTextureHandle(SkSurface::kFlushRead_BackendHandleAccess);
|
|
|
|
if (handle) {
|
|
|
|
return (void*)(uintptr_t)reinterpret_cast<GrGLTextureInfo *>(handle)->fID;
|
2016-01-21 17:51:40 +03:00
|
|
|
}
|
2014-03-06 01:49:37 +04:00
|
|
|
}
|
2014-10-15 07:55:37 +04:00
|
|
|
#endif
|
2014-10-08 08:16:14 +04:00
|
|
|
return nullptr;
|
2014-03-06 01:49:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<PathBuilder>
|
2011-11-02 23:55:03 +04:00
|
|
|
DrawTargetSkia::CreatePathBuilder(FillRule aFillRule) const
|
|
|
|
{
|
2015-04-30 22:20:30 +03:00
|
|
|
return MakeAndAddRef<PathBuilderSkia>(aFillRule);
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::ClearRect(const Rect &aRect)
|
|
|
|
{
|
2011-11-02 23:55:03 +04:00
|
|
|
MarkChanged();
|
2011-11-02 23:55:03 +04:00
|
|
|
mCanvas->save();
|
2017-05-10 05:31:07 +03:00
|
|
|
mCanvas->clipRect(RectToSkRect(aRect), SkClipOp::kIntersect, true);
|
2016-07-26 02:36:35 +03:00
|
|
|
SkColor clearColor = (mFormat == SurfaceFormat::B8G8R8X8) ? SK_ColorBLACK : SK_ColorTRANSPARENT;
|
|
|
|
mCanvas->clear(clearColor);
|
2011-11-02 23:55:03 +04:00
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::PushClip(const Path *aPath)
|
|
|
|
{
|
2014-01-10 23:06:16 +04:00
|
|
|
if (aPath->GetBackendType() != BackendType::SKIA) {
|
2011-11-02 23:55:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathSkia *skiaPath = static_cast<const PathSkia*>(aPath);
|
2014-07-28 04:51:09 +04:00
|
|
|
mCanvas->save();
|
2017-05-10 05:31:07 +03:00
|
|
|
mCanvas->clipPath(skiaPath->GetPath(), SkClipOp::kIntersect, true);
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2016-09-22 00:03:20 +03:00
|
|
|
void
|
|
|
|
DrawTargetSkia::PushDeviceSpaceClipRects(const IntRect* aRects, uint32_t aCount)
|
|
|
|
{
|
|
|
|
// Build a region by unioning all the rects together.
|
|
|
|
SkRegion region;
|
|
|
|
for (uint32_t i = 0; i < aCount; i++) {
|
|
|
|
region.op(IntRectToSkIRect(aRects[i]), SkRegion::kUnion_Op);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clip with the resulting region. clipRegion does not transform
|
|
|
|
// this region by the current transform, unlike the other SkCanvas
|
|
|
|
// clip methods, so it is just passed through in device-space.
|
|
|
|
mCanvas->save();
|
2017-05-10 05:31:07 +03:00
|
|
|
mCanvas->clipRegion(region, SkClipOp::kIntersect);
|
2016-09-22 00:03:20 +03:00
|
|
|
}
|
|
|
|
|
2012-01-19 08:48:33 +04:00
|
|
|
void
|
|
|
|
DrawTargetSkia::PushClipRect(const Rect& aRect)
|
|
|
|
{
|
|
|
|
SkRect rect = RectToSkRect(aRect);
|
|
|
|
|
2014-07-28 04:51:09 +04:00
|
|
|
mCanvas->save();
|
2017-05-10 05:31:07 +03:00
|
|
|
mCanvas->clipRect(rect, SkClipOp::kIntersect, true);
|
2012-01-19 08:48:33 +04:00
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
void
|
|
|
|
DrawTargetSkia::PopClip()
|
|
|
|
{
|
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
|
2016-01-13 07:30:33 +03:00
|
|
|
void
|
|
|
|
DrawTargetSkia::PushLayer(bool aOpaque, Float aOpacity, SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform, const IntRect& aBounds,
|
|
|
|
bool aCopyBackground)
|
|
|
|
{
|
2016-12-16 19:02:04 +03:00
|
|
|
PushedLayer layer(GetPermitSubpixelAA(), aOpaque, aOpacity, aMask, aMaskTransform,
|
|
|
|
mCanvas->getTopDevice());
|
2016-01-13 07:30:33 +03:00
|
|
|
mPushedLayers.push_back(layer);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
// If we have a mask, set the opacity to 0 so that SkCanvas::restore skips
|
|
|
|
// implicitly drawing the layer so that we can properly mask it in PopLayer.
|
|
|
|
paint.setAlpha(aMask ? 0 : ColorFloatToByte(aOpacity));
|
|
|
|
|
2016-12-16 19:02:04 +03:00
|
|
|
// aBounds is supplied in device space, but SaveLayerRec wants local space.
|
2016-01-13 07:30:33 +03:00
|
|
|
SkRect bounds = IntRectToSkRect(aBounds);
|
2016-12-16 19:02:04 +03:00
|
|
|
if (!bounds.isEmpty()) {
|
|
|
|
SkMatrix inverseCTM;
|
|
|
|
if (mCanvas->getTotalMatrix().invert(&inverseCTM)) {
|
|
|
|
inverseCTM.mapRect(&bounds);
|
|
|
|
} else {
|
|
|
|
bounds.setEmpty();
|
|
|
|
}
|
|
|
|
}
|
2016-01-13 07:30:33 +03:00
|
|
|
|
2016-02-09 21:36:19 +03:00
|
|
|
SkCanvas::SaveLayerRec saveRec(aBounds.IsEmpty() ? nullptr : &bounds,
|
|
|
|
&paint,
|
2016-12-16 19:02:04 +03:00
|
|
|
SkCanvas::kPreserveLCDText_SaveLayerFlag |
|
2017-05-10 05:31:07 +03:00
|
|
|
(aOpaque ? SkCanvas::kIsOpaque_SaveLayerFlag : 0) |
|
|
|
|
(aCopyBackground ? SkCanvas::kInitWithPrevious_SaveLayerFlag : 0));
|
2016-02-09 21:36:19 +03:00
|
|
|
|
|
|
|
mCanvas->saveLayer(saveRec);
|
2016-01-13 07:30:33 +03:00
|
|
|
|
|
|
|
SetPermitSubpixelAA(aOpaque);
|
2016-05-17 21:41:38 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
|
|
|
CGContextRelease(mCG);
|
|
|
|
mCG = nullptr;
|
|
|
|
#endif
|
2016-01-13 07:30:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::PopLayer()
|
|
|
|
{
|
|
|
|
MarkChanged();
|
|
|
|
|
|
|
|
MOZ_ASSERT(mPushedLayers.size());
|
|
|
|
const PushedLayer& layer = mPushedLayers.back();
|
|
|
|
|
2016-12-16 19:02:04 +03:00
|
|
|
// Ensure that the top device has actually changed. If it hasn't, then there
|
|
|
|
// is no layer image to be masked.
|
|
|
|
if (layer.mMask &&
|
|
|
|
layer.mPreviousDevice != mCanvas->getTopDevice()) {
|
2016-10-25 05:40:59 +03:00
|
|
|
// If we have a mask, take a reference to the top layer's device so that
|
2016-01-13 07:30:33 +03:00
|
|
|
// we can mask it ourselves. This assumes we forced SkCanvas::restore to
|
|
|
|
// skip implicitly drawing the layer.
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkBaseDevice> layerDevice = sk_ref_sp(mCanvas->getTopDevice());
|
2016-01-13 07:30:33 +03:00
|
|
|
SkIRect layerBounds = layerDevice->getGlobalBounds();
|
2016-10-25 05:40:59 +03:00
|
|
|
sk_sp<SkImage> layerImage;
|
|
|
|
SkPixmap layerPixmap;
|
|
|
|
if (layerDevice->peekPixels(&layerPixmap)) {
|
|
|
|
layerImage = SkImage::MakeFromRaster(layerPixmap, nullptr, nullptr);
|
|
|
|
#ifdef USE_SKIA_GPU
|
2017-05-10 05:31:07 +03:00
|
|
|
} else if (GrRenderTargetContext* drawCtx = mCanvas->internal_private_accessTopLayerRenderTargetContext()) {
|
2016-10-25 05:40:59 +03:00
|
|
|
drawCtx->prepareForExternalIO();
|
2017-05-10 05:31:07 +03:00
|
|
|
if (sk_sp<GrTextureProxy> tex = drawCtx->asTextureProxyRef()) {
|
|
|
|
layerImage = sk_make_sp<SkImage_Gpu>(mGrContext.get(),
|
2016-10-25 05:40:59 +03:00
|
|
|
kNeedNewImageUniqueID,
|
|
|
|
layerDevice->imageInfo().alphaType(),
|
|
|
|
tex, nullptr, SkBudgeted::kNo);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2016-01-13 07:30:33 +03:00
|
|
|
|
|
|
|
// Restore the background with the layer's device left alive.
|
|
|
|
mCanvas->restore();
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAlpha(ColorFloatToByte(layer.mOpacity));
|
|
|
|
|
|
|
|
SkMatrix maskMat, layerMat;
|
|
|
|
// Get the total transform affecting the mask, considering its pattern
|
|
|
|
// transform and the current canvas transform.
|
|
|
|
GfxMatrixToSkiaMatrix(layer.mMaskTransform, maskMat);
|
|
|
|
maskMat.postConcat(mCanvas->getTotalMatrix());
|
|
|
|
if (!maskMat.invert(&layerMat)) {
|
|
|
|
gfxDebug() << *this << ": PopLayer() failed to invert mask transform";
|
|
|
|
} else {
|
|
|
|
// The layer should not be affected by the current canvas transform,
|
|
|
|
// even though the mask is. So first we use the inverse of the transform
|
|
|
|
// affecting the mask, then add back on the layer's origin.
|
|
|
|
layerMat.preTranslate(layerBounds.x(), layerBounds.y());
|
2016-10-25 05:40:59 +03:00
|
|
|
|
|
|
|
if (layerImage) {
|
|
|
|
paint.setShader(layerImage->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &layerMat));
|
|
|
|
} else {
|
|
|
|
paint.setColor(SK_ColorTRANSPARENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_sp<SkImage> alphaMask = ExtractAlphaForSurface(layer.mMask);
|
|
|
|
if (!alphaMask) {
|
2016-01-13 07:30:33 +03:00
|
|
|
gfxDebug() << *this << ": PopLayer() failed to extract alpha for mask";
|
|
|
|
} else {
|
|
|
|
mCanvas->save();
|
|
|
|
|
|
|
|
// The layer may be smaller than the canvas size, so make sure drawing is
|
|
|
|
// clipped to within the bounds of the layer.
|
|
|
|
mCanvas->resetMatrix();
|
|
|
|
mCanvas->clipRect(SkRect::Make(layerBounds));
|
|
|
|
|
|
|
|
mCanvas->setMatrix(maskMat);
|
2016-10-25 05:40:59 +03:00
|
|
|
mCanvas->drawImage(alphaMask, 0, 0, &paint);
|
2016-01-13 07:30:33 +03:00
|
|
|
|
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
SetPermitSubpixelAA(layer.mOldPermitSubpixelAA);
|
|
|
|
|
|
|
|
mPushedLayers.pop_back();
|
2016-05-17 21:41:38 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
|
|
|
CGContextRelease(mCG);
|
|
|
|
mCG = nullptr;
|
|
|
|
#endif
|
2016-01-13 07:30:33 +03:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<GradientStops>
|
2011-12-28 09:56:11 +04:00
|
|
|
DrawTargetSkia::CreateGradientStops(GradientStop *aStops, uint32_t aNumStops, ExtendMode aExtendMode) const
|
2011-11-02 23:55:03 +04:00
|
|
|
{
|
|
|
|
std::vector<GradientStop> stops;
|
|
|
|
stops.resize(aNumStops);
|
|
|
|
for (uint32_t i = 0; i < aNumStops; i++) {
|
|
|
|
stops[i] = aStops[i];
|
|
|
|
}
|
|
|
|
std::stable_sort(stops.begin(), stops.end());
|
2014-10-08 08:16:14 +04:00
|
|
|
|
2015-04-30 22:20:30 +03:00
|
|
|
return MakeAndAddRef<GradientStopsSkia>(stops, aNumStops, aExtendMode);
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<FilterNode>
|
2013-11-27 15:25:28 +04:00
|
|
|
DrawTargetSkia::CreateFilter(FilterType aType)
|
|
|
|
{
|
|
|
|
return FilterNodeSoftware::Create(aType);
|
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
void
|
2013-08-02 05:12:16 +04:00
|
|
|
DrawTargetSkia::MarkChanged()
|
2013-08-03 07:35:39 +04:00
|
|
|
{
|
2013-08-02 05:12:16 +04:00
|
|
|
if (mSnapshot) {
|
|
|
|
mSnapshot->DrawTargetWillChange();
|
|
|
|
mSnapshot = nullptr;
|
2016-10-25 05:40:59 +03:00
|
|
|
|
|
|
|
// Handle copying of any image snapshots bound to the surface.
|
2016-10-26 20:41:07 +03:00
|
|
|
if (mSurface) {
|
|
|
|
mSurface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMode);
|
|
|
|
}
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-26 10:00:19 +03:00
|
|
|
void
|
|
|
|
DrawTargetSkia::SnapshotDestroyed()
|
|
|
|
{
|
|
|
|
mSnapshot = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|