Commit 12ebe1b8 authored by fgorski's avatar fgorski Committed by Commit bot

Revert of Add sk_sp helpers and switch Blink SkShader clients to the new APIs...

Revert of Add sk_sp helpers and switch Blink SkShader clients to the new APIs (patchset #7 id:120001 of https://codereview.chromium.org/1789063005/ )

Reason for revert:
Suspecting this patch to have caused the compilation failure: https://build.chromium.org/p/chromium.webkit/builders/WebKit%20Win%20non-Oilpan/builds/811

https://build.chromium.org/p/chromium.webkit/builders/WebKit%20Win%20non-Oilpan/builds/811/steps/compile/logs/stdio

Original issue's description:
> Add sk_sp helpers and switch Blink SkShader clients to the new APIs
>
> Introduce a couple of Skia utilities to support PassRefPtr <-> sk_sp
> interoperability:
>
>  * adoptRef(sk_sp<T>)       - for adopting sk_sps rvals into PassRevPtr
>                               (when transferring ownership from Skia->Blink)
>  * adoptSkSp(PassRefPtr<T>) - for adopting PassRefPtr rvals into sk_sp
>                               (when transferring ownership from Blink->Skia)
>
> Update clients to use the new Skia shader factories ("makers" vs. prev
> "creators"), and sk_sp-based setters.
>
> A tangential change: deconstify SkPicture fields/args to align with the new
> Skia APIs (SkPicture is inherently const - no non-cost methods - and Skia now
> expects non-const SkPicture args).
>
> BUG=skia:5077
> R=jbroman@chromium.org,reed@google.com,senorblanco@chromium.org
>
> Committed: https://crrev.com/2df3d4433fc756f1297c4e0ced6524cbfcba9571
> Cr-Commit-Position: refs/heads/master@{#381563}

TBR=jbroman@chromium.org,bungeman@chromium.org,reed@google.com,senorblanco@chromium.org,danakj@chromium.org,fmalita@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:5077

Review URL: https://codereview.chromium.org/1814473003

Cr-Commit-Position: refs/heads/master@{#381575}
parent 0adc0178
...@@ -179,7 +179,7 @@ const LayoutSVGResourceContainer* LayoutSVGResourcePattern::resolveContentElemen ...@@ -179,7 +179,7 @@ const LayoutSVGResourceContainer* LayoutSVGResourcePattern::resolveContentElemen
return this; return this;
} }
PassRefPtr<SkPicture> LayoutSVGResourcePattern::asPicture(const FloatRect& tileBounds, PassRefPtr<const SkPicture> LayoutSVGResourcePattern::asPicture(const FloatRect& tileBounds,
const AffineTransform& tileTransform) const const AffineTransform& tileTransform) const
{ {
ASSERT(!m_shouldCollectPatternAttributes); ASSERT(!m_shouldCollectPatternAttributes);
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
private: private:
PassOwnPtr<PatternData> buildPatternData(const LayoutObject&); PassOwnPtr<PatternData> buildPatternData(const LayoutObject&);
PassRefPtr<SkPicture> asPicture(const FloatRect& tile, const AffineTransform&) const; PassRefPtr<const SkPicture> asPicture(const FloatRect& tile, const AffineTransform&) const;
PatternData* patternForLayoutObject(const LayoutObject&); PatternData* patternForLayoutObject(const LayoutObject&);
const LayoutSVGResourceContainer* resolveContentElement() const; const LayoutSVGResourceContainer* resolveContentElement() const;
......
...@@ -286,14 +286,16 @@ void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize ...@@ -286,14 +286,16 @@ void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize
SkPaint paint; SkPaint paint;
drawForContainer(patternPicture.context().canvas(), paint, containerSize, zoom, tile, srcRect, url); drawForContainer(patternPicture.context().canvas(), paint, containerSize, zoom, tile, srcRect, url);
} }
RefPtr<SkPicture> tilePicture = patternPicture.endRecording(); RefPtr<const SkPicture> tilePicture = patternPicture.endRecording();
SkMatrix patternTransform; SkMatrix patternTransform;
patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spacedTile.y()); patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spacedTile.y());
RefPtr<SkShader> patternShader = adoptRef(SkShader::CreatePictureShader(
tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
&patternTransform, nullptr));
SkPaint paint; SkPaint paint;
paint.setShader(SkShader::MakePictureShader(adoptSkSp(tilePicture.release()), paint.setShader(patternShader.get());
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &patternTransform, nullptr));
paint.setXfermodeMode(compositeOp); paint.setXfermodeMode(compositeOp);
paint.setColorFilter(context.colorFilter()); paint.setColorFilter(context.colorFilter());
context.drawRect(dstRect, paint); context.drawRect(dstRect, paint);
......
...@@ -47,14 +47,14 @@ void GeneratedImage::drawPattern(GraphicsContext& destContext, const FloatRect& ...@@ -47,14 +47,14 @@ void GeneratedImage::drawPattern(GraphicsContext& destContext, const FloatRect&
SkPictureBuilder builder(tileRect, nullptr, &destContext); SkPictureBuilder builder(tileRect, nullptr, &destContext);
builder.context().beginRecording(tileRect); builder.context().beginRecording(tileRect);
drawTile(builder.context(), srcRect); drawTile(builder.context(), srcRect);
RefPtr<SkPicture> tilePicture = builder.endRecording(); RefPtr<const SkPicture> tilePicture = builder.endRecording();
AffineTransform patternTransform; AffineTransform patternTransform;
patternTransform.translate(phase.x(), phase.y()); patternTransform.translate(phase.x(), phase.y());
patternTransform.scale(scale.width(), scale.height()); patternTransform.scale(scale.width(), scale.height());
patternTransform.translate(tileRect.x(), tileRect.y()); patternTransform.translate(tileRect.x(), tileRect.y());
RefPtr<Pattern> picturePattern = Pattern::createPicturePattern(tilePicture.release()); RefPtr<Pattern> picturePattern = Pattern::createPicturePattern(tilePicture);
picturePattern->setPatternSpaceTransform(patternTransform); picturePattern->setPatternSpaceTransform(patternTransform);
SkPaint fillPaint = destContext.fillPaint(); SkPaint fillPaint = destContext.fillPaint();
......
...@@ -189,10 +189,10 @@ static void fillStops(const Gradient::ColorStop* stopData, ...@@ -189,10 +189,10 @@ static void fillStops(const Gradient::ColorStop* stopData,
} }
} }
PassRefPtr<SkShader> Gradient::refShader() SkShader* Gradient::shader()
{ {
if (m_gradient) if (m_gradient)
return m_gradient; return m_gradient.get();
sortStopsIfNecessary(); sortStopsIfNecessary();
ASSERT(m_stopsSorted); ASSERT(m_stopsSorted);
...@@ -233,33 +233,32 @@ PassRefPtr<SkShader> Gradient::refShader() ...@@ -233,33 +233,32 @@ PassRefPtr<SkShader> Gradient::refShader()
// Since the two-point radial gradient is slower than the plain radial, // Since the two-point radial gradient is slower than the plain radial,
// only use it if we have to. // only use it if we have to.
if (m_p0 == m_p1 && m_r0 <= 0.0f) { if (m_p0 == m_p1 && m_r0 <= 0.0f) {
m_gradient = adoptRef(SkGradientShader::MakeRadial(m_p1.data(), m_r1, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &localMatrix)); m_gradient = adoptRef(SkGradientShader::CreateRadial(m_p1.data(), m_r1, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &localMatrix));
} else { } else {
// The radii we give to Skia must be positive. If we're given a // The radii we give to Skia must be positive. If we're given a
// negative radius, ask for zero instead. // negative radius, ask for zero instead.
SkScalar radius0 = m_r0 >= 0.0f ? WebCoreFloatToSkScalar(m_r0) : 0; SkScalar radius0 = m_r0 >= 0.0f ? WebCoreFloatToSkScalar(m_r0) : 0;
SkScalar radius1 = m_r1 >= 0.0f ? WebCoreFloatToSkScalar(m_r1) : 0; SkScalar radius1 = m_r1 >= 0.0f ? WebCoreFloatToSkScalar(m_r1) : 0;
m_gradient = adoptRef(SkGradientShader::MakeTwoPointConical(m_p0.data(), radius0, m_p1.data(), radius1, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &localMatrix)); m_gradient = adoptRef(SkGradientShader::CreateTwoPointConical(m_p0.data(), radius0, m_p1.data(), radius1, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &localMatrix));
} }
} else { } else {
SkPoint pts[2] = { m_p0.data(), m_p1.data() }; SkPoint pts[2] = { m_p0.data(), m_p1.data() };
SkMatrix localMatrix = affineTransformToSkMatrix(m_gradientSpaceTransformation); SkMatrix localMatrix = affineTransformToSkMatrix(m_gradientSpaceTransformation);
m_gradient = adoptRef(SkGradientShader::MakeLinear(pts, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &localMatrix)); m_gradient = adoptRef(SkGradientShader::CreateLinear(pts, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &localMatrix));
} }
if (!m_gradient) { if (!m_gradient) {
// use last color, since our "geometry" was degenerate (e.g. radius==0) // use last color, since our "geometry" was degenerate (e.g. radius==0)
m_gradient = adoptRef(SkShader::MakeColorShader(colors[countUsed - 1])); m_gradient = adoptRef(SkShader::CreateColorShader(colors[countUsed - 1]));
} }
return m_gradient; return m_gradient.get();
} }
void Gradient::applyToPaint(SkPaint& paint) void Gradient::applyToPaint(SkPaint& paint)
{ {
paint.setShader(adoptSkSp(refShader())); paint.setShader(shader());
// Legacy behavior: gradients are always dithered. // Legacy behavior: gradients are always dithered.
paint.setDither(true); paint.setDither(true);
} }
} // namespace blink } // namespace blink
...@@ -126,7 +126,7 @@ private: ...@@ -126,7 +126,7 @@ private:
Gradient(const FloatPoint& p0, const FloatPoint& p1); Gradient(const FloatPoint& p0, const FloatPoint& p1);
Gradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, float aspectRatio); Gradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, float aspectRatio);
PassRefPtr<SkShader> refShader(); SkShader* shader();
void destroyShader(); void destroyShader();
void sortStopsIfNecessary(); void sortStopsIfNecessary();
......
...@@ -303,12 +303,12 @@ void GraphicsContext::beginRecording(const FloatRect& bounds) ...@@ -303,12 +303,12 @@ void GraphicsContext::beginRecording(const FloatRect& bounds)
skia::GetMetaData(*m_canvas) = m_metaData; skia::GetMetaData(*m_canvas) = m_metaData;
} }
PassRefPtr<SkPicture> GraphicsContext::endRecording() PassRefPtr<const SkPicture> GraphicsContext::endRecording()
{ {
if (contextDisabled()) if (contextDisabled())
return nullptr; return nullptr;
RefPtr<SkPicture> picture = adoptRef(m_pictureRecorder.endRecordingAsPicture()); RefPtr<const SkPicture> picture = adoptRef(m_pictureRecorder.endRecordingAsPicture());
m_canvas = nullptr; m_canvas = nullptr;
ASSERT(picture); ASSERT(picture);
return picture.release(); return picture.release();
...@@ -635,10 +635,11 @@ void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt, float widt ...@@ -635,10 +635,11 @@ void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt, float widt
SkMatrix localMatrix; SkMatrix localMatrix;
localMatrix.setTranslate(originX, originY); localMatrix.setTranslate(originX, originY);
RefPtr<SkShader> shader = adoptRef(SkShader::CreateBitmapShader(
*misspellBitmap[index], SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix));
SkPaint paint; SkPaint paint;
paint.setShader(SkShader::MakeBitmapShader( paint.setShader(shader.get());
*misspellBitmap[index], SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix));
SkRect rect; SkRect rect;
rect.set(originX, originY, originX + WebCoreFloatToSkScalar(width) * deviceScaleFactor, originY + SkIntToScalar(misspellBitmap[index]->height())); rect.set(originX, originY, originX + WebCoreFloatToSkScalar(width) * deviceScaleFactor, originY + SkIntToScalar(misspellBitmap[index]->height()));
......
...@@ -211,7 +211,7 @@ public: ...@@ -211,7 +211,7 @@ public:
// are stored in a display list that can be replayed at a later time. Pass in the bounding // are stored in a display list that can be replayed at a later time. Pass in the bounding
// rectangle for the content in the list. // rectangle for the content in the list.
void beginRecording(const FloatRect&); void beginRecording(const FloatRect&);
PassRefPtr<SkPicture> endRecording(); PassRefPtr<const SkPicture> endRecording();
void setShadow(const FloatSize& offset, float blur, const Color&, void setShadow(const FloatSize& offset, float blur, const Color&,
DrawLooperBuilder::ShadowTransformMode = DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowTransformMode = DrawLooperBuilder::ShadowRespectsTransforms,
......
...@@ -185,11 +185,11 @@ void Image::drawTiled(GraphicsContext& ctxt, const FloatRect& dstRect, const Flo ...@@ -185,11 +185,11 @@ void Image::drawTiled(GraphicsContext& ctxt, const FloatRect& dstRect, const Flo
namespace { namespace {
sk_sp<SkShader> createPatternShader(const SkImage* image, const SkMatrix& shaderMatrix, PassRefPtr<SkShader> createPatternShader(const SkImage* image, const SkMatrix& shaderMatrix,
const SkPaint& paint, const FloatSize& spacing) const SkPaint& paint, const FloatSize& spacing)
{ {
if (spacing.isZero()) if (spacing.isZero())
return image->makeShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &shaderMatrix); return adoptRef(image->newShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &shaderMatrix));
// Arbitrary tiling is currently only supported for SkPictureShader - so we use it instead // Arbitrary tiling is currently only supported for SkPictureShader - so we use it instead
// of a plain bitmap shader to implement spacing. // of a plain bitmap shader to implement spacing.
...@@ -200,10 +200,10 @@ sk_sp<SkShader> createPatternShader(const SkImage* image, const SkMatrix& shader ...@@ -200,10 +200,10 @@ sk_sp<SkShader> createPatternShader(const SkImage* image, const SkMatrix& shader
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(tileRect); SkCanvas* canvas = recorder.beginRecording(tileRect);
canvas->drawImage(image, 0, 0, &paint); canvas->drawImage(image, 0, 0, &paint);
sk_sp<SkPicture> picture(recorder.endRecordingAsPicture()); RefPtr<const SkPicture> picture = adoptRef(recorder.endRecordingAsPicture());
return SkShader::MakePictureShader( return adoptRef(SkShader::CreatePictureShader(
std::move(picture), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &shaderMatrix, nullptr); picture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &shaderMatrix, nullptr));
} }
} // anonymous namespace } // anonymous namespace
...@@ -249,8 +249,9 @@ void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect, ...@@ -249,8 +249,9 @@ void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect,
paint.setXfermodeMode(compositeOp); paint.setXfermodeMode(compositeOp);
paint.setFilterQuality(context.computeFilterQuality(this, destRect, normSrcRect)); paint.setFilterQuality(context.computeFilterQuality(this, destRect, normSrcRect));
paint.setAntiAlias(context.shouldAntialias()); paint.setAntiAlias(context.shouldAntialias());
paint.setShader(createPatternShader(image.get(), localMatrix, paint, RefPtr<SkShader> shader = createPatternShader(image.get(), localMatrix, paint,
FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.height() / scale.height()))); FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.height() / scale.height()));
paint.setShader(shader.get());
context.drawRect(destRect, paint); context.drawRect(destRect, paint);
} }
......
...@@ -33,13 +33,13 @@ ImagePattern::ImagePattern(PassRefPtr<Image> image, RepeatMode repeatMode) ...@@ -33,13 +33,13 @@ ImagePattern::ImagePattern(PassRefPtr<Image> image, RepeatMode repeatMode)
PassRefPtr<SkShader> ImagePattern::createShader() PassRefPtr<SkShader> ImagePattern::createShader()
{ {
if (!m_tileImage) if (!m_tileImage)
return adoptRef(SkShader::MakeColorShader(SK_ColorTRANSPARENT)); return adoptRef(SkShader::CreateColorShader(SK_ColorTRANSPARENT));
SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformation); SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformation);
if (isRepeatXY()) { if (isRepeatXY()) {
// Fast path: for repeatXY we just return a shader from the original image. // Fast path: for repeatXY we just return a shader from the original image.
return adoptRef(m_tileImage->makeShader(SkShader::kRepeat_TileMode, return adoptRef(m_tileImage->newShader(SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode, &localMatrix)); SkShader::kRepeat_TileMode, &localMatrix));
} }
...@@ -61,7 +61,7 @@ PassRefPtr<SkShader> ImagePattern::createShader() ...@@ -61,7 +61,7 @@ PassRefPtr<SkShader> ImagePattern::createShader()
RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul( RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(
m_tileImage->width() + expandW, m_tileImage->height() + expandH)); m_tileImage->width() + expandW, m_tileImage->height() + expandH));
if (!surface) if (!surface)
return adoptRef(SkShader::MakeColorShader(SK_ColorTRANSPARENT)); return adoptRef(SkShader::CreateColorShader(SK_ColorTRANSPARENT));
surface->getCanvas()->clear(SK_ColorTRANSPARENT); surface->getCanvas()->clear(SK_ColorTRANSPARENT);
SkPaint paint; SkPaint paint;
...@@ -69,7 +69,7 @@ PassRefPtr<SkShader> ImagePattern::createShader() ...@@ -69,7 +69,7 @@ PassRefPtr<SkShader> ImagePattern::createShader()
surface->getCanvas()->drawImage(m_tileImage.get(), 0, 0, &paint); surface->getCanvas()->drawImage(m_tileImage.get(), 0, 0, &paint);
RefPtr<SkImage> expandedImage = adoptRef(surface->newImageSnapshot()); RefPtr<SkImage> expandedImage = adoptRef(surface->newImageSnapshot());
return adoptRef(expandedImage->makeShader(tileModeX, tileModeY, &localMatrix)); return adoptRef(expandedImage->newShader(tileModeX, tileModeY, &localMatrix));
} }
bool ImagePattern::isTextureBacked() const bool ImagePattern::isTextureBacked() const
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "platform/graphics/ImagePattern.h" #include "platform/graphics/ImagePattern.h"
#include "platform/graphics/PicturePattern.h" #include "platform/graphics/PicturePattern.h"
#include "platform/graphics/skia/SkiaUtils.h"
#include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkPicture.h" #include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkShader.h" #include "third_party/skia/include/core/SkShader.h"
...@@ -42,7 +41,7 @@ PassRefPtr<Pattern> Pattern::createImagePattern(PassRefPtr<Image> tileImage, Rep ...@@ -42,7 +41,7 @@ PassRefPtr<Pattern> Pattern::createImagePattern(PassRefPtr<Image> tileImage, Rep
return ImagePattern::create(tileImage, repeatMode); return ImagePattern::create(tileImage, repeatMode);
} }
PassRefPtr<Pattern> Pattern::createPicturePattern(PassRefPtr<SkPicture> picture, PassRefPtr<Pattern> Pattern::createPicturePattern(PassRefPtr<const SkPicture> picture,
RepeatMode repeatMode) RepeatMode repeatMode)
{ {
return PicturePattern::create(picture, repeatMode); return PicturePattern::create(picture, repeatMode);
...@@ -66,7 +65,7 @@ void Pattern::applyToPaint(SkPaint& paint) ...@@ -66,7 +65,7 @@ void Pattern::applyToPaint(SkPaint& paint)
m_pattern = createShader(); m_pattern = createShader();
} }
paint.setShader(adoptSkSp<SkShader>(m_pattern)); paint.setShader(m_pattern.get());
} }
void Pattern::setPatternSpaceTransform(const AffineTransform& patternSpaceTransformation) void Pattern::setPatternSpaceTransform(const AffineTransform& patternSpaceTransformation)
......
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
}; };
static PassRefPtr<Pattern> createImagePattern(PassRefPtr<Image>, RepeatMode = RepeatModeXY); static PassRefPtr<Pattern> createImagePattern(PassRefPtr<Image>, RepeatMode = RepeatModeXY);
static PassRefPtr<Pattern> createPicturePattern(PassRefPtr<SkPicture>, static PassRefPtr<Pattern> createPicturePattern(PassRefPtr<const SkPicture>,
RepeatMode = RepeatModeXY); RepeatMode = RepeatModeXY);
virtual ~Pattern(); virtual ~Pattern();
......
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
namespace blink { namespace blink {
PassRefPtr<PicturePattern> PicturePattern::create(PassRefPtr<SkPicture> picture, PassRefPtr<PicturePattern> PicturePattern::create(PassRefPtr<const SkPicture> picture,
RepeatMode repeatMode) RepeatMode repeatMode)
{ {
return adoptRef(new PicturePattern(picture, repeatMode)); return adoptRef(new PicturePattern(picture, repeatMode));
} }
PicturePattern::PicturePattern(PassRefPtr<SkPicture> picture, RepeatMode mode) PicturePattern::PicturePattern(PassRefPtr<const SkPicture> picture, RepeatMode mode)
: Pattern(mode) : Pattern(mode)
, m_tilePicture(picture) , m_tilePicture(picture)
{ {
...@@ -35,7 +35,7 @@ PassRefPtr<SkShader> PicturePattern::createShader() ...@@ -35,7 +35,7 @@ PassRefPtr<SkShader> PicturePattern::createShader()
SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformation); SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformation);
SkRect tileBounds = m_tilePicture->cullRect(); SkRect tileBounds = m_tilePicture->cullRect();
return adoptRef(SkShader::MakePictureShader(adoptSkSp<SkPicture>(m_tilePicture), return adoptRef(SkShader::CreatePictureShader(m_tilePicture.get(),
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix, &tileBounds)); SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix, &tileBounds));
} }
......
...@@ -11,7 +11,7 @@ namespace blink { ...@@ -11,7 +11,7 @@ namespace blink {
class PLATFORM_EXPORT PicturePattern final : public Pattern { class PLATFORM_EXPORT PicturePattern final : public Pattern {
public: public:
static PassRefPtr<PicturePattern> create(PassRefPtr<SkPicture>, RepeatMode); static PassRefPtr<PicturePattern> create(PassRefPtr<const SkPicture>, RepeatMode);
~PicturePattern() override; ~PicturePattern() override;
...@@ -19,9 +19,9 @@ protected: ...@@ -19,9 +19,9 @@ protected:
PassRefPtr<SkShader> createShader() override; PassRefPtr<SkShader> createShader() override;
private: private:
PicturePattern(PassRefPtr<SkPicture>, RepeatMode); PicturePattern(PassRefPtr<const SkPicture>, RepeatMode);
RefPtr<SkPicture> m_tilePicture; RefPtr<const SkPicture> m_tilePicture;
}; };
} // namespace blink } // namespace blink
......
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
GraphicsContext& context() { return *m_context; } GraphicsContext& context() { return *m_context; }
PassRefPtr<SkPicture> endRecording() PassRefPtr<const SkPicture> endRecording()
{ {
m_context->beginRecording(m_bounds); m_context->beginRecording(m_bounds);
m_paintController->endSkippingCache(); m_paintController->endSkippingCache();
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "platform/graphics/Image.h" #include "platform/graphics/Image.h"
#include "platform/transforms/AffineTransform.h" #include "platform/transforms/AffineTransform.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "wtf/MathExtras.h" #include "wtf/MathExtras.h"
namespace blink { namespace blink {
...@@ -127,77 +126,6 @@ inline SkCanvas::SrcRectConstraint WebCoreClampingModeToSkiaRectConstraint(Image ...@@ -127,77 +126,6 @@ inline SkCanvas::SrcRectConstraint WebCoreClampingModeToSkiaRectConstraint(Image
: SkCanvas::kFast_SrcRectConstraint; : SkCanvas::kFast_SrcRectConstraint;
} }
// Skia's smart pointer APIs are preferable over their legacy raw pointer counterparts.
// The following helpers ensure interoperability between Skia's SkRefCnt wrapper sk_sp<T> and
// Blink's RefPtr<T>/PassRefPtr<T>.
//
// - adoptRef(sk_sp<T>): adopts an sk_sp rvalue into a PassRefPtr (to be used when
// transferring ownership from Skia to Blink).
// - adoptSkSp(PassRefPtr<T>): adopts a PassRefPtr rvalue into a sk_sp (to be used when
// transferring ownership from Blink to Skia).
//
// General guidelines
//
// When receiving ref counted objects from Skia:
//
// 1) use sk_sp-based Skia factories if available (e.g. SkShader::MakeFoo() instead of
// SkShader::CreateFoo())
//
// 2) use sk_sp<T> locals for temporary objects (to be immediately transferred back to Skia)
//
// 3) use RefPtr<T>/PassRefPtr<T> for objects to be retained in Blink, use
// adoptRef(sk_sp<T>) to convert
//
// When passing ref counted objects to Skia:
//
// 1) use sk_sk-based Skia APIs when available (e.g. SkPaint::setShader(sk_sp<SkShader>)
// instead of SkPaint::setShader(SkShader*))
//
// 2) if the object ownership is being passed to Skia, use std::move(sk_sp<T>) or
// adoptSkSp(PassRefPtr<T>) to transfer without refcount churn
//
// 3) if the object ownership is shared with Skia (Blink retains a reference), use
// sk_ref_sp(RefPtr<T>::get())
//
// Example (creating a SkShader and setting it on SkPaint):
//
// a) legacy/old style
//
// RefPtr<SkShader> shader = adoptRef(SkShader::CreateFoo(...));
// paint.setShader(shader.get());
//
// (Note: the legacy approach introduces refcount churn as Skia grabs a ref while Blink is
// temporarily holding on to its own)
//
// b) new style, ownership transferred
//
// // using Skia smart pointer locals
// sk_sp<SkShader> shader = SkShader::MakeFoo(...);
// paint.setShader(std::move(shader));
//
// // using Blink smart pointer locals
// RefPtr<SkShader> shader = adoptRef(SkShader::MakeFoo(...));
// paint.setShader(adoptSkSp(shader.release());
//
// // using no locals
// paint.setShader(SkShader::MakeFoo(...));
//
// c) new style, shared ownership
//
// RefPtr<SkShader> m_shader = adoptRef(SkShader::MakeFoo(...));
// paint.setShader(adoptSkSp<SkShader>(m_shader));
//
template <typename T> PassRefPtr<T> adoptRef(sk_sp<T> sp)
{
return adoptRef(sp.release());
}
template <typename T> sk_sp<T> adoptSkSp(PassRefPtr<T> ref)
{
return sk_sp<T>(ref.leakRef());
}
} // namespace blink } // namespace blink
#endif // SkiaUtils_h #endif // SkiaUtils_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment