2015-06-19 02:07:21 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; 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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_PersistentBUFFERPROVIDER_H
|
|
|
|
#define MOZILLA_GFX_PersistentBUFFERPROVIDER_H
|
|
|
|
|
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h" // for RefPtr, already_AddRefed, etc
|
2015-06-19 02:07:21 +03:00
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
|
|
|
#include "mozilla/layers/CompositableForwarder.h"
|
|
|
|
#include "mozilla/gfx/Types.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
class CopyableCanvasLayer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A PersistentBufferProvider is for users which require the temporary use of
|
|
|
|
* a DrawTarget to draw into. When they're done drawing they return the
|
|
|
|
* DrawTarget, when they later need to continue drawing they get a DrawTarget
|
|
|
|
* from the provider again, the provider will guarantee the contents of the
|
|
|
|
* previously returned DrawTarget is persisted into the one newly returned.
|
|
|
|
*/
|
|
|
|
class PersistentBufferProvider : public RefCounted<PersistentBufferProvider>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PersistentBufferProvider)
|
|
|
|
|
|
|
|
virtual ~PersistentBufferProvider() { }
|
|
|
|
|
|
|
|
virtual LayersBackend GetType() { return LayersBackend::LAYERS_NONE; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a DrawTarget from the PersistentBufferProvider.
|
|
|
|
*
|
|
|
|
* \param aPersistedRect This indicates the area of the DrawTarget that needs
|
|
|
|
* to have remained the same since the call to
|
|
|
|
* ReturnAndUseDT.
|
|
|
|
*/
|
2016-02-10 21:16:13 +03:00
|
|
|
virtual already_AddRefed<gfx::DrawTarget> GetDT(const gfx::IntRect& aPersistedRect) = 0;
|
2015-06-19 02:07:21 +03:00
|
|
|
/**
|
|
|
|
* Return a DrawTarget to the PersistentBufferProvider and indicate the
|
|
|
|
* contents of this DrawTarget is to be considered current by the
|
2016-02-10 21:16:13 +03:00
|
|
|
* BufferProvider. The caller should forget any references to the DrawTarget.
|
2015-06-19 02:07:21 +03:00
|
|
|
*/
|
2016-02-10 21:16:13 +03:00
|
|
|
virtual bool ReturnAndUseDT(already_AddRefed<gfx::DrawTarget> aDT) = 0;
|
2015-06-19 02:07:21 +03:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<gfx::SourceSurface> GetSnapshot() = 0;
|
2015-06-19 02:07:21 +03:00
|
|
|
protected:
|
2015-06-19 02:07:21 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class PersistentBufferProviderBasic : public PersistentBufferProvider
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PersistentBufferProviderBasic)
|
|
|
|
|
2015-08-26 13:58:18 +03:00
|
|
|
PersistentBufferProviderBasic(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
|
|
|
|
gfx::BackendType aBackend);
|
2015-08-05 22:37:23 +03:00
|
|
|
explicit PersistentBufferProviderBasic(gfx::DrawTarget* aTarget) : mDrawTarget(aTarget) {}
|
2015-06-19 02:07:21 +03:00
|
|
|
|
|
|
|
bool IsValid() { return !!mDrawTarget; }
|
|
|
|
virtual LayersBackend GetType() { return LayersBackend::LAYERS_BASIC; }
|
2016-02-10 21:16:13 +03:00
|
|
|
already_AddRefed<gfx::DrawTarget> GetDT(const gfx::IntRect& aPersistedRect) {
|
|
|
|
RefPtr<gfx::DrawTarget> dt(mDrawTarget);
|
|
|
|
return dt.forget();
|
|
|
|
}
|
|
|
|
bool ReturnAndUseDT(already_AddRefed<gfx::DrawTarget> aDT) {
|
|
|
|
RefPtr<gfx::DrawTarget> dt(aDT);
|
|
|
|
MOZ_ASSERT(mDrawTarget == dt);
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<gfx::SourceSurface> GetSnapshot() { return mDrawTarget->Snapshot(); }
|
2015-06-19 02:07:21 +03:00
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfx::DrawTarget> mDrawTarget;
|
2015-06-19 02:07:21 +03:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-06-19 02:07:21 +03:00
|
|
|
#endif
|