2012-06-29 10:01:34 +04:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2014-04-01 08:02:09 +04:00
|
|
|
#include "BasicLayersImpl.h" // for FillRectWithMask, etc
|
2013-08-12 03:17:23 +04:00
|
|
|
#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 "nsCOMPtr.h" // for already_AddRefed
|
|
|
|
#include "nsDebug.h" // for NS_ASSERTION
|
|
|
|
#include "nsISupportsImpl.h" // for gfxPattern::Release, etc
|
2015-05-07 12:07:35 +03:00
|
|
|
#include "nsRect.h" // for mozilla::gfx::IntRect
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "nsRegion.h" // for nsIntRegion
|
2013-12-13 21:32:02 +04:00
|
|
|
#include "mozilla/gfx/Point.h" // for IntSize
|
2012-06-29 10:01:34 +04:00
|
|
|
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2012-07-12 16:51:57 +04:00
|
|
|
namespace layers {
|
2012-06-29 10:01:34 +04:00
|
|
|
|
|
|
|
class BasicImageLayer : public ImageLayer, public BasicImplData {
|
|
|
|
public:
|
2014-08-20 08:55:14 +04:00
|
|
|
explicit BasicImageLayer(BasicLayerManager* aLayerManager) :
|
2015-01-07 08:39:46 +03:00
|
|
|
ImageLayer(aLayerManager, static_cast<BasicImplData*>(this)),
|
2012-06-29 10:01:34 +04:00
|
|
|
mSize(-1, -1)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicImageLayer);
|
|
|
|
}
|
2014-07-15 19:37:45 +04:00
|
|
|
protected:
|
2012-06-29 10:01:34 +04:00
|
|
|
virtual ~BasicImageLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicImageLayer);
|
|
|
|
}
|
|
|
|
|
2014-07-15 19:37:45 +04:00
|
|
|
public:
|
2015-11-29 10:07:55 +03:00
|
|
|
virtual void SetVisibleRegion(const LayerIntRegion& aRegion) override
|
2012-06-29 10:01:34 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
|
|
|
ImageLayer::SetVisibleRegion(aRegion);
|
|
|
|
}
|
|
|
|
|
2014-05-12 04:31:27 +04:00
|
|
|
virtual void Paint(DrawTarget* aDT,
|
|
|
|
const gfx::Point& aDeviceOffset,
|
2015-03-21 19:28:04 +03:00
|
|
|
Layer* aMaskLayer) override;
|
2012-06-29 10:01:34 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> GetAsSourceSurface() override;
|
2012-06-29 10:01:34 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
BasicLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
2013-12-13 21:32:02 +04:00
|
|
|
gfx::IntSize mSize;
|
2012-06-29 10:01:34 +04:00
|
|
|
};
|
|
|
|
|
2014-02-12 19:07:46 +04:00
|
|
|
void
|
2014-05-12 04:31:27 +04:00
|
|
|
BasicImageLayer::Paint(DrawTarget* aDT,
|
|
|
|
const gfx::Point& aDeviceOffset,
|
|
|
|
Layer* aMaskLayer)
|
2012-06-29 10:01:34 +04:00
|
|
|
{
|
2014-04-01 08:02:09 +04:00
|
|
|
if (IsHidden() || !mContainer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageFactory> originalIF = mContainer->GetImageFactory();
|
2014-04-01 08:02:09 +04:00
|
|
|
mContainer->SetImageFactory(mManager->IsCompositingCheap() ? nullptr : BasicManager()->GetImageFactory());
|
|
|
|
|
2015-03-27 02:07:53 +03:00
|
|
|
AutoLockImage autoLock(mContainer);
|
2014-04-01 08:02:09 +04:00
|
|
|
Image *image = autoLock.GetImage();
|
2015-03-27 02:07:53 +03:00
|
|
|
if (!image) {
|
|
|
|
mContainer->SetImageFactory(originalIF);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfx::SourceSurface> surface = image->GetAsSourceSurface();
|
2014-04-01 08:02:09 +04:00
|
|
|
if (!surface || !surface->IsValid()) {
|
2014-06-21 16:32:30 +04:00
|
|
|
mContainer->SetImageFactory(originalIF);
|
2012-06-29 10:01:34 +04:00
|
|
|
return;
|
2014-02-12 19:07:47 +04:00
|
|
|
}
|
2014-04-01 08:02:09 +04:00
|
|
|
|
2015-03-27 02:07:53 +03:00
|
|
|
gfx::IntSize size = mSize = surface->GetSize();
|
2015-10-06 03:12:46 +03:00
|
|
|
FillRectWithMask(aDT, aDeviceOffset, Rect(0, 0, size.width, size.height),
|
2016-05-25 19:01:18 +03:00
|
|
|
surface, mSamplingFilter,
|
2014-04-01 08:02:09 +04:00
|
|
|
DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)),
|
|
|
|
aMaskLayer);
|
|
|
|
|
2014-06-21 16:32:30 +04:00
|
|
|
mContainer->SetImageFactory(originalIF);
|
2012-06-29 10:01:34 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2014-04-01 08:02:09 +04:00
|
|
|
BasicImageLayer::GetAsSourceSurface()
|
|
|
|
{
|
|
|
|
if (!mContainer) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-27 02:07:53 +03:00
|
|
|
AutoLockImage lockImage(mContainer);
|
|
|
|
Image* image = lockImage.GetImage();
|
|
|
|
if (!image) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return image->GetAsSourceSurface();
|
2014-04-01 08:02:09 +04:00
|
|
|
}
|
|
|
|
|
2012-06-29 10:01:34 +04:00
|
|
|
already_AddRefed<ImageLayer>
|
|
|
|
BasicLayerManager::CreateImageLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageLayer> layer = new BasicImageLayer(this);
|
2012-06-29 10:01:34 +04:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|