summaryrefslogtreecommitdiffstats
path: root/gfx
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-11-20 09:47:03 +0000
committerMoonchild <moonchild@palemoon.org>2020-11-20 09:47:03 +0000
commit5165ed02285315cc0bed7977c7bac6d0a90ca43c (patch)
tree9b761a21eb924915e51c2d803208e6c01b505a45 /gfx
parente1db27e19989db11fef70f439cf95821316535b3 (diff)
parentca9abcdf1702c37bf00048dab3f460b2252873a3 (diff)
downloadUXP-5165ed02285315cc0bed7977c7bac6d0a90ca43c.tar
UXP-5165ed02285315cc0bed7977c7bac6d0a90ca43c.tar.gz
UXP-5165ed02285315cc0bed7977c7bac6d0a90ca43c.tar.lz
UXP-5165ed02285315cc0bed7977c7bac6d0a90ca43c.tar.xz
UXP-5165ed02285315cc0bed7977c7bac6d0a90ca43c.zip
Merge branch 'redwood' into releaseRELBASE_20201124RELBASE_20201120RC_20201120
Diffstat (limited to 'gfx')
-rw-r--r--gfx/2d/DrawTargetSkia.cpp46
-rw-r--r--gfx/2d/SourceSurfaceSkia.cpp19
-rw-r--r--gfx/2d/SourceSurfaceSkia.h6
3 files changed, 54 insertions, 17 deletions
diff --git a/gfx/2d/DrawTargetSkia.cpp b/gfx/2d/DrawTargetSkia.cpp
index 9eaac5674..7e71e54cc 100644
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -212,7 +212,7 @@ VerifyRGBXCorners(uint8_t* aData, const IntSize &aSize, const int32_t aStride, S
#endif
static sk_sp<SkImage>
-GetSkImageForSurface(SourceSurface* aSurface)
+GetSkImageForSurface(SourceSurface* aSurface, Maybe<MutexAutoLock>* aLock)
{
if (!aSurface) {
gfxDebug() << "Creating null Skia image from null SourceSurface";
@@ -220,7 +220,7 @@ GetSkImageForSurface(SourceSurface* aSurface)
}
if (aSurface->GetType() == SurfaceType::SKIA) {
- return static_cast<SourceSurfaceSkia*>(aSurface)->GetImage();
+ return static_cast<SourceSurfaceSkia*>(aSurface)->GetImage(aLock);
}
DataSourceSurface* surf = aSurface->GetDataSurface().take();
@@ -390,9 +390,9 @@ ExtractAlphaBitmap(sk_sp<SkImage> aImage, SkBitmap* aResultBitmap)
}
static sk_sp<SkImage>
-ExtractAlphaForSurface(SourceSurface* aSurface)
+ExtractAlphaForSurface(SourceSurface* aSurface, Maybe<MutexAutoLock>& aLock)
{
- sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
+ sk_sp<SkImage> image = GetSkImageForSurface(aSurface, &aLock);
if (!image) {
return nullptr;
}
@@ -411,7 +411,11 @@ ExtractAlphaForSurface(SourceSurface* aSurface)
}
static void
-SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, Float aAlpha = 1.0, Point aOffset = Point(0, 0))
+SetPaintPattern(SkPaint& aPaint,
+ const Pattern& aPattern,
+ Maybe<MutexAutoLock>& aLock,
+ Float aAlpha = 1.0,
+ Point aOffset = Point(0, 0))
{
switch (aPattern.GetType()) {
case PatternType::COLOR: {
@@ -473,7 +477,7 @@ SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, Float aAlpha = 1.0, Po
}
case PatternType::SURFACE: {
const SurfacePattern& pat = static_cast<const SurfacePattern&>(aPattern);
- sk_sp<SkImage> image = GetSkImageForSurface(pat.mSurface);
+ sk_sp<SkImage> image = GetSkImageForSurface(pat.mSurface, &aLock);
if (!image) {
aPaint.setColor(SK_ColorTRANSPARENT);
break;
@@ -525,7 +529,7 @@ struct AutoPaintSetup {
: mNeedsRestore(false), mAlpha(1.0)
{
Init(aCanvas, aOptions, aMaskBounds, false);
- SetPaintPattern(mPaint, aPattern, mAlpha, aOffset);
+ SetPaintPattern(mPaint, aPattern, mLock, mAlpha, aOffset);
}
AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions, const Rect* aMaskBounds = nullptr, bool aForceGroup = false)
@@ -579,6 +583,7 @@ struct AutoPaintSetup {
SkPaint mPaint;
bool mNeedsRestore;
SkCanvas* mCanvas;
+ Maybe<MutexAutoLock> mLock;
Float mAlpha;
};
@@ -601,7 +606,8 @@ DrawTargetSkia::DrawSurface(SourceSurface *aSurface,
MarkChanged();
- sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
+ Maybe<MutexAutoLock> lock;
+ sk_sp<SkImage> image = GetSkImageForSurface(aSurface, &lock);
if (!image) {
return;
}
@@ -654,7 +660,8 @@ DrawTargetSkia::DrawSurfaceWithShadow(SourceSurface *aSurface,
MarkChanged();
- sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
+ Maybe<MutexAutoLock> lock;
+ sk_sp<SkImage> image = GetSkImageForSurface(aSurface, &lock);
if (!image) {
return;
}
@@ -1407,8 +1414,9 @@ DrawTargetSkia::Mask(const Pattern &aSource,
MarkChanged();
AutoPaintSetup paint(mCanvas.get(), aOptions, aSource);
+ Maybe<MutexAutoLock> lock;
SkPaint maskPaint;
- SetPaintPattern(maskPaint, aMask);
+ SetPaintPattern(maskPaint, aMask, lock);
SkLayerRasterizer::Builder builder;
builder.addLayer(maskPaint);
@@ -1427,7 +1435,8 @@ DrawTargetSkia::MaskSurface(const Pattern &aSource,
MarkChanged();
AutoPaintSetup paint(mCanvas.get(), aOptions, aSource, nullptr, -aOffset);
- sk_sp<SkImage> alphaMask = ExtractAlphaForSurface(aMask);
+ Maybe<MutexAutoLock> lock;
+ sk_sp<SkImage> alphaMask = ExtractAlphaForSurface(aMask, lock);
if (!alphaMask) {
gfxDebug() << *this << ": MaskSurface() failed to extract alpha for mask";
return;
@@ -1456,7 +1465,8 @@ DrawTarget::Draw3DTransformedSurface(SourceSurface* aSurface, const Matrix4x4& a
fullMat.PostTranslate(-xformBounds.x, -xformBounds.y, 0);
// Read in the source data.
- sk_sp<SkImage> srcImage = GetSkImageForSurface(aSurface);
+ Maybe<MutexAutoLock> lock;
+ sk_sp<SkImage> srcImage = GetSkImageForSurface(aSurface, &lock);
if (!srcImage) {
return true;
}
@@ -1515,7 +1525,8 @@ DrawTargetSkia::Draw3DTransformedSurface(SourceSurface* aSurface, const Matrix4x
MarkChanged();
- sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
+ Maybe<MutexAutoLock> lock;
+ sk_sp<SkImage> image = GetSkImageForSurface(aSurface, &lock);
if (!image) {
return true;
}
@@ -1599,7 +1610,8 @@ already_AddRefed<SourceSurface>
DrawTargetSkia::OptimizeGPUSourceSurface(SourceSurface *aSurface) const
{
// Check if the underlying SkImage already has an associated GrTexture.
- sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
+ Maybe<MutexAutoLock> lock;
+ sk_sp<SkImage> image = GetSkImageForSurface(aSurface, &lock);
if (!image || image->isTextureBacked()) {
RefPtr<SourceSurface> surface(aSurface);
return surface.forget();
@@ -1716,7 +1728,8 @@ DrawTargetSkia::CopySurface(SourceSurface *aSurface,
{
MarkChanged();
- sk_sp<SkImage> image = GetSkImageForSurface(aSurface);
+ Maybe<MutexAutoLock> lock;
+ sk_sp<SkImage> image = GetSkImageForSurface(aSurface, &lock);
if (!image) {
return;
}
@@ -2061,7 +2074,8 @@ DrawTargetSkia::PopLayer()
paint.setColor(SK_ColorTRANSPARENT);
}
- sk_sp<SkImage> alphaMask = ExtractAlphaForSurface(layer.mMask);
+ Maybe<MutexAutoLock> lock;
+ sk_sp<SkImage> alphaMask = ExtractAlphaForSurface(layer.mMask, lock);
if (!alphaMask) {
gfxDebug() << *this << ": PopLayer() failed to extract alpha for mask";
} else {
diff --git a/gfx/2d/SourceSurfaceSkia.cpp b/gfx/2d/SourceSurfaceSkia.cpp
index 14cbf6a84..0738f3d39 100644
--- a/gfx/2d/SourceSurfaceSkia.cpp
+++ b/gfx/2d/SourceSurfaceSkia.cpp
@@ -40,6 +40,25 @@ SourceSurfaceSkia::GetFormat() const
return mFormat;
}
+sk_sp<SkImage>
+SourceSurfaceSkia::GetImage(Maybe<MutexAutoLock>* aLock) {
+ // If we were provided a lock object, we can let the caller access
+ // a shared SkImage and we know it won't go away while the lock is held.
+ if (aLock) {
+ // We are locked, so now we can check mDrawTarget.
+ // If it's null, then we're not shared and we can unlock eagerly.
+ if (!mDrawTarget) {
+ aLock->reset();
+ }
+ } else {
+ // Otherwise we need to call DrawTargetWillChange to ensure we have our
+ // own copy of the SkImage.
+ DrawTargetWillChange();
+ }
+ sk_sp<SkImage> image = mImage;
+ return image;
+}
+
static sk_sp<SkData>
MakeSkData(unsigned char* aData, const IntSize& aSize, int32_t aStride)
{
diff --git a/gfx/2d/SourceSurfaceSkia.h b/gfx/2d/SourceSurfaceSkia.h
index a91ae93ed..ffb8e47bf 100644
--- a/gfx/2d/SourceSurfaceSkia.h
+++ b/gfx/2d/SourceSurfaceSkia.h
@@ -10,6 +10,10 @@
#include <vector>
#include "skia/include/core/SkCanvas.h"
#include "skia/include/core/SkImage.h"
+#include "mozilla/Maybe.h"
+#include "mozilla/Mutex.h"
+
+typedef mozilla::MutexAutoLock MutexAutoLock;
namespace mozilla {
@@ -28,7 +32,7 @@ public:
virtual IntSize GetSize() const;
virtual SurfaceFormat GetFormat() const;
- sk_sp<SkImage>& GetImage() { return mImage; }
+ sk_sp<SkImage> GetImage(Maybe<MutexAutoLock>* aLock);
bool InitFromData(unsigned char* aData,
const IntSize &aSize,