Files
palemoon27/gfx/layers/basic/BasicImageLayer.cpp
T
roytam1 721ef90dc3 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1107096 - Suppress improper drawing of zero-width invisible glyphs in canvas. r=roc (6f78376bc)
- Bug 1107096 - Reftest for zero-width invisible glyphs in canvas. (ded6cb516)
- Bug 1153958 - Make manifest processor e10s friendly. r=ehsan (ba5f6edf5)
- Bug 1162808 - Add splash_screens support to web manifest processor. r=ehsan (688bbe3d6)
- Bug 1164235 - Add theme_color support to web manifest processor. r=ehsan (0134f58fe)
- Bug 1143879 - Implement lang member of Web manifest. r=ehsan. (0b426965a)
- Bug 1166405 - Consolidate classes into a general web manifest module. r=ehsan. (98a6a4531)
- Bug 1162729 - CORS check is always performed when fetching a manifest. r=ehsan (aab278c12)
- Bug 1167335 - Make manifest obtainer use Task.jsm. r=oyiptong. (a4a48d767)
- Bug 1089255 - Implement and test manifest-src CSP directive. r=bholley, r=dveditz, r=ckerschb (63353eff3)
- Bug 968520 - Use move assignment instead of fallible copy assignment in nsCSPUtils.cpp. r=froydnj (fcaa9e865)
- Bug 968520 - Add mozilla::fallible to Fallible{Auto,}TArray::ReplaceElementsAt calls. r=froydnj (fb81d2305)
- Bug 968520 - Use FallibleTArray::Clear instead of SetLength(0). r=froydnj (3945e3e86)
- Bug 968520 - Add mozilla::fallible to FallibleTArray::InsertElementSorted calls. r=froydnj (dda295d5b)
- make some calls fallible - to get 968520 working (7722d850e)
- Bug 968520 - Always require fallible argument with FallibleTArray calls. r=froydnj (b9e630a76)
- Bug 968520 - Add mozilla::fallible to FallibleArray calls in tests. r=froydnj (53b58ac40)
- Bug 968520 - Explicitly use infallible allocator for ShiftData call in nsTArray::RemoveElementsAt. r=froydnj (9453996c3)
- Bug 1182808 - Part 1: Add and use fallible variant of AlignedTArray_Impl::SetLength. r=padenot (f6330791d)
- Bug 1143575. Replace ImageContainer Lock methods with simplified AutoLockImage. r=nical (c87ffec51)
2021-03-20 10:41:54 +08:00

122 lines
3.8 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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/. */
#include "BasicLayersImpl.h" // for FillRectWithMask, etc
#include "ImageContainer.h" // for AutoLockImage, etc
#include "ImageLayers.h" // for ImageLayer
#include "Layers.h" // for Layer (ptr only), etc
#include "basic/BasicImplData.h" // for BasicImplData
#include "basic/BasicLayers.h" // for BasicLayerManager
#include "mozilla/mozalloc.h" // for operator new
#include "nsAutoPtr.h" // for nsRefPtr, getter_AddRefs, etc
#include "nsCOMPtr.h" // for already_AddRefed
#include "nsDebug.h" // for NS_ASSERTION
#include "nsISupportsImpl.h" // for gfxPattern::Release, etc
#include "nsRect.h" // for mozilla::gfx::IntRect
#include "nsRegion.h" // for nsIntRegion
#include "mozilla/gfx/Point.h" // for IntSize
using namespace mozilla::gfx;
namespace mozilla {
namespace layers {
class BasicImageLayer : public ImageLayer, public BasicImplData {
public:
explicit BasicImageLayer(BasicLayerManager* aLayerManager) :
ImageLayer(aLayerManager, static_cast<BasicImplData*>(this)),
mSize(-1, -1)
{
MOZ_COUNT_CTOR(BasicImageLayer);
}
protected:
virtual ~BasicImageLayer()
{
MOZ_COUNT_DTOR(BasicImageLayer);
}
public:
virtual void SetVisibleRegion(const nsIntRegion& aRegion) override
{
NS_ASSERTION(BasicManager()->InConstruction(),
"Can only set properties in construction phase");
ImageLayer::SetVisibleRegion(aRegion);
}
virtual void Paint(DrawTarget* aDT,
const gfx::Point& aDeviceOffset,
Layer* aMaskLayer) override;
virtual already_AddRefed<SourceSurface> GetAsSourceSurface() override;
protected:
BasicLayerManager* BasicManager()
{
return static_cast<BasicLayerManager*>(mManager);
}
gfx::IntSize mSize;
};
void
BasicImageLayer::Paint(DrawTarget* aDT,
const gfx::Point& aDeviceOffset,
Layer* aMaskLayer)
{
if (IsHidden() || !mContainer) {
return;
}
nsRefPtr<ImageFactory> originalIF = mContainer->GetImageFactory();
mContainer->SetImageFactory(mManager->IsCompositingCheap() ? nullptr : BasicManager()->GetImageFactory());
AutoLockImage autoLock(mContainer);
Image *image = autoLock.GetImage();
if (!image) {
mContainer->SetImageFactory(originalIF);
return;
}
RefPtr<gfx::SourceSurface> surface = image->GetAsSourceSurface();
if (!surface || !surface->IsValid()) {
mContainer->SetImageFactory(originalIF);
return;
}
gfx::IntSize size = mSize = surface->GetSize();
FillRectWithMask(aDT, aDeviceOffset, Rect(0, 0, size.width, size.height),
surface, ToFilter(mFilter),
DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)),
aMaskLayer);
mContainer->SetImageFactory(originalIF);
GetContainer()->NotifyPaintedImage(image);
}
already_AddRefed<SourceSurface>
BasicImageLayer::GetAsSourceSurface()
{
if (!mContainer) {
return nullptr;
}
AutoLockImage lockImage(mContainer);
Image* image = lockImage.GetImage();
if (!image) {
return nullptr;
}
return image->GetAsSourceSurface();
}
already_AddRefed<ImageLayer>
BasicLayerManager::CreateImageLayer()
{
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
nsRefPtr<ImageLayer> layer = new BasicImageLayer(this);
return layer.forget();
}
} // namespace layers
} // namespace mozilla