Bug 1167235 - Part 1: Add code exposing a PersistentBufferProvider. r=nical

This commit is contained in:
Bas Schouten 2015-06-19 01:07:21 +02:00
parent 4ac4ead7b5
commit 8de3e68281
7 changed files with 149 additions and 10 deletions

View File

@ -30,6 +30,7 @@
#include "mozilla/layers/LayerManagerComposite.h" // for LayerComposite
#include "mozilla/layers/LayerMetricsWrapper.h" // for LayerMetricsWrapper
#include "mozilla/layers/LayersMessages.h" // for TransformFunction, etc
#include "mozilla/layers/PersistentBufferProvider.h"
#include "nsAString.h"
#include "nsCSSValue.h" // for nsCSSValue::Array, etc
#include "nsPrintfCString.h" // for nsPrintfCString
@ -159,6 +160,27 @@ LayerManager::CreateDrawTarget(const IntSize &aSize,
CreateOffscreenCanvasDrawTarget(aSize, aFormat);
}
TemporaryRef<PersistentBufferProvider>
LayerManager::CreatePersistentBufferProvider(const mozilla::gfx::IntSize &aSize,
mozilla::gfx::SurfaceFormat aFormat)
{
RefPtr<PersistentBufferProviderBasic> bufferProvider =
new PersistentBufferProviderBasic(this, aSize, aFormat,
gfxPlatform::GetPlatform()->GetPreferredCanvasBackend());
if (!bufferProvider->IsValid()) {
bufferProvider =
new PersistentBufferProviderBasic(this, aSize, aFormat,
gfxPlatform::GetPlatform()->GetFallbackCanvasBackend());
}
if (!bufferProvider->IsValid()) {
return nullptr;
}
return bufferProvider.forget();
}
#ifdef DEBUG
void
LayerManager::Mutated(Layer* aLayer)

View File

@ -93,6 +93,7 @@ class LayerManagerComposite;
class SpecificLayerAttributes;
class Compositor;
class FrameUniformityData;
class PersistentBufferProvider;
namespace layerscope {
class LayersPacket;
@ -481,6 +482,14 @@ public:
CreateDrawTarget(const mozilla::gfx::IntSize &aSize,
mozilla::gfx::SurfaceFormat aFormat);
/**
* Creates a PersistentBufferProvider for use with canvas which is optimized for
* inter-operating with this layermanager.
*/
virtual TemporaryRef<PersistentBufferProvider>
CreatePersistentBufferProvider(const mozilla::gfx::IntSize &aSize,
mozilla::gfx::SurfaceFormat aFormat);
virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize) { return true; }
/**

View File

@ -0,0 +1,26 @@
/* -*- 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/. */
#include "PersistentBufferProvider.h"
#include "Layers.h"
#include "mozilla/gfx/Logging.h"
#include "pratom.h"
#include "gfxPlatform.h"
namespace mozilla {
using namespace gfx;
namespace layers {
PersistentBufferProviderBasic::PersistentBufferProviderBasic(LayerManager* aManager, gfx::IntSize aSize,
gfx::SurfaceFormat aFormat, gfx::BackendType aBackend)
{
mDrawTarget = gfxPlatform::GetPlatform()->CreateDrawTargetForBackend(aBackend, aSize, aFormat);
}
}
}

View File

@ -0,0 +1,76 @@
/* -*- 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
#include "mozilla/RefPtr.h" // for RefPtr, TemporaryRef, etc
#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.
*/
virtual gfx::DrawTarget* GetDT(const gfx::IntRect& aPersistedRect) = 0;
/**
* Return a DrawTarget to the PersistentBufferProvider and indicate the
* contents of this DrawTarget is to be considered current by the
* BufferProvider
*/
virtual bool ReturnAndUseDT(gfx::DrawTarget* aDT) = 0;
protected:
friend class CopyableCanvasLayer;
virtual TemporaryRef<gfx::SourceSurface> GetSnapshot() = 0;
};
class PersistentBufferProviderBasic : public PersistentBufferProvider
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PersistentBufferProviderBasic)
PersistentBufferProviderBasic(LayerManager* aManager, gfx::IntSize aSize,
gfx::SurfaceFormat aFormat, gfx::BackendType aBackend);
bool IsValid() { return !!mDrawTarget; }
virtual LayersBackend GetType() { return LayersBackend::LAYERS_BASIC; }
gfx::DrawTarget* GetDT(const gfx::IntRect& aPersistedRect) { return mDrawTarget; }
bool ReturnAndUseDT(gfx::DrawTarget* aDT) { MOZ_ASSERT(mDrawTarget == aDT); return true; }
virtual TemporaryRef<gfx::SourceSurface> GetSnapshot() { return mDrawTarget->Snapshot(); }
private:
RefPtr<gfx::DrawTarget> mDrawTarget;
};
}
}
#endif

View File

@ -21,6 +21,7 @@
#include "mozilla/layers/PLayerChild.h" // for PLayerChild
#include "mozilla/layers/LayerTransactionChild.h"
#include "mozilla/layers/TextureClientPool.h" // for TextureClientPool
#include "mozilla/layers/PersistentBufferProvider.h"
#include "ClientReadbackLayer.h" // for ClientReadbackLayer
#include "nsAString.h"
#include "nsIWidgetListener.h"

View File

@ -165,6 +165,7 @@ EXPORTS.mozilla.layers += [
'opengl/MacIOSurfaceTextureHostOGL.h',
'opengl/TextureClientOGL.h',
'opengl/TextureHostOGL.h',
'PersistentBufferProvider.h',
'RenderTrace.h',
'TransactionIdAllocator.h',
'YCbCrImageDataSerializer.h',
@ -334,6 +335,7 @@ SOURCES += [
'ImageContainer.cpp',
'Layers.cpp',
'LayerTreeInvalidation.cpp',
'PersistentBufferProvider.cpp',
]
# Disable RTTI in google protocol buffer

View File

@ -308,7 +308,9 @@ public:
mozilla::gfx::BackendType GetPreferredCanvasBackend() {
return mPreferredCanvasBackend;
}
mozilla::gfx::BackendType GetFallbackCanvasBackend() {
return mFallbackCanvasBackend;
}
/*
* Font bits
*/
@ -638,6 +640,16 @@ public:
}
virtual void FlushContentDrawing() {}
/**
* Helper method, creates a draw target for a specific Azure backend.
* Used by CreateOffscreenDrawTarget.
*/
mozilla::TemporaryRef<DrawTarget>
CreateDrawTargetForBackend(mozilla::gfx::BackendType aBackend,
const mozilla::gfx::IntSize& aSize,
mozilla::gfx::SurfaceFormat aFormat);
protected:
gfxPlatform();
virtual ~gfxPlatform();
@ -650,15 +662,6 @@ protected:
*/
virtual already_AddRefed<mozilla::gfx::VsyncSource> CreateHardwareVsyncSource();
/**
* Helper method, creates a draw target for a specific Azure backend.
* Used by CreateOffscreenDrawTarget.
*/
mozilla::TemporaryRef<DrawTarget>
CreateDrawTargetForBackend(mozilla::gfx::BackendType aBackend,
const mozilla::gfx::IntSize& aSize,
mozilla::gfx::SurfaceFormat aFormat);
/**
* Initialise the preferred and fallback canvas backends
* aBackendBitmask specifies the backends which are acceptable to the caller.