Bug 991028 - Remove AutoOpenSurface. r=nical

This commit is contained in:
Matt Woodrow 2014-04-07 13:32:48 +12:00
Родитель 6bba9e227e
Коммит 29d8737832
22 изменённых файлов: 61 добавлений и 218 удалений

Просмотреть файл

@ -89,6 +89,7 @@ public:
{
Validate();
}
};
} // namespace layers

Просмотреть файл

@ -14,12 +14,8 @@ namespace layers {
/**
* Drawing with a mask requires a mask surface and a transform.
* Sometimes the mask surface is a direct gfxASurface, but other times
* it's a SurfaceDescriptor. For SurfaceDescriptor, we need to use a
* scoped AutoOpenSurface to get a gfxASurface for the
* SurfaceDescriptor.
*
* This helper class manages the gfxASurface-or-SurfaceDescriptor
* This helper class manages the gfxASurface
* logic.
*/
class MOZ_STACK_CLASS AutoMaskData {
@ -37,9 +33,6 @@ public:
void Construct(const gfx::Matrix& aTransform,
gfxASurface* aSurface);
void Construct(const gfx::Matrix& aTransform,
const SurfaceDescriptor& aSurface);
/** The returned surface can't escape the scope of |this|. */
gfxASurface* GetSurface();
const gfx::Matrix& GetTransform();
@ -49,7 +42,6 @@ private:
gfx::Matrix mTransform;
nsRefPtr<gfxASurface> mSurface;
Maybe<AutoOpenSurface> mSurfaceOpener;
AutoMaskData(const AutoMaskData&) MOZ_DELETE;
AutoMaskData& operator=(const AutoMaskData&) MOZ_DELETE;

Просмотреть файл

@ -5,7 +5,6 @@
#include "BasicCompositor.h"
#include "TextureHostBasic.h"
#include "ipc/AutoOpenSurface.h"
#include "mozilla/layers/Effects.h"
#include "mozilla/layers/YCbCrImageDataSerializer.h"
#include "nsIWidget.h"

Просмотреть файл

@ -53,8 +53,7 @@ public:
virtual void Paint(DrawTarget* aDT, Layer* aMaskLayer) MOZ_OVERRIDE;
virtual bool GetAsSurface(gfxASurface** aSurface,
SurfaceDescriptor* aDescriptor);
virtual bool GetAsSurface(gfxASurface** aSurface);
virtual TemporaryRef<SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
protected:
@ -134,8 +133,7 @@ BasicImageLayer::GetAndPaintCurrentImage(DrawTarget* aTarget,
}
bool
BasicImageLayer::GetAsSurface(gfxASurface** aSurface,
SurfaceDescriptor* aDescriptor)
BasicImageLayer::GetAsSurface(gfxASurface** aSurface)
{
if (!mContainer) {
return false;

Просмотреть файл

@ -117,8 +117,7 @@ public:
* return false if a surface cannot be created. If true is
* returned, only one of |aSurface| or |aDescriptor| is valid.
*/
virtual bool GetAsSurface(gfxASurface** aSurface,
SurfaceDescriptor* aDescriptor)
virtual bool GetAsSurface(gfxASurface** aSurface)
{ return false; }
virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() { return nullptr; }

Просмотреть файл

@ -27,23 +27,11 @@ AutoMaskData::Construct(const gfx::Matrix& aTransform,
mSurface = aSurface;
}
void
AutoMaskData::Construct(const gfx::Matrix& aTransform,
const SurfaceDescriptor& aSurface)
{
MOZ_ASSERT(!IsConstructed());
mTransform = aTransform;
mSurfaceOpener.construct(OPEN_READ_ONLY, aSurface);
}
gfxASurface*
AutoMaskData::GetSurface()
{
MOZ_ASSERT(IsConstructed());
if (mSurface) {
return mSurface.get();
}
return mSurfaceOpener.ref().Get();
return mSurface.get();
}
const gfx::Matrix&
@ -56,7 +44,7 @@ AutoMaskData::GetTransform()
bool
AutoMaskData::IsConstructed()
{
return !!mSurface || !mSurfaceOpener.empty();
return !!mSurface;
}
bool
@ -64,19 +52,14 @@ GetMaskData(Layer* aMaskLayer, AutoMaskData* aMaskData)
{
if (aMaskLayer) {
nsRefPtr<gfxASurface> surface;
SurfaceDescriptor descriptor;
if (static_cast<BasicImplData*>(aMaskLayer->ImplData())
->GetAsSurface(getter_AddRefs(surface), &descriptor) &&
(surface || IsSurfaceDescriptorValid(descriptor))) {
->GetAsSurface(getter_AddRefs(surface)) &&
surface) {
Matrix transform;
Matrix4x4 effectiveTransform = aMaskLayer->GetEffectiveTransform();
DebugOnly<bool> maskIs2D = effectiveTransform.CanDraw2D(&transform);
NS_ASSERTION(maskIs2D, "How did we end up with a 3D transform here?!");
if (surface) {
aMaskData->Construct(transform, surface);
} else {
aMaskData->Construct(transform, descriptor);
}
aMaskData->Construct(transform, surface);
return true;
}
}

Просмотреть файл

@ -11,7 +11,6 @@
#include "ReadbackLayer.h" // for ReadbackLayer
#include "gfxASurface.h" // for gfxASurface
#include "gfxContext.h" // for gfxContext, etc
#include "ipc/AutoOpenSurface.h" // for AutoOpenSurface
#include "mozilla/Attributes.h" // for MOZ_DELETE, MOZ_STACK_CLASS
#include "mozilla/Maybe.h" // for Maybe
#include "nsAutoPtr.h" // for nsRefPtr

Просмотреть файл

@ -7,7 +7,6 @@
#include "CompositorChild.h" // for CompositorChild
#include "GeckoProfiler.h" // for PROFILER_LABEL
#include "gfxASurface.h" // for gfxASurface, etc
#include "ipc/AutoOpenSurface.h" // for AutoOpenSurface
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/Hal.h"
#include "mozilla/dom/ScreenOrientation.h" // for ScreenOrientation
@ -289,10 +288,10 @@ ClientLayerManager::MakeSnapshotIfRequired()
// it through |outSnapshot|, but if it doesn't, it's
// responsible for freeing |snapshot|.
remoteRenderer->SendMakeSnapshot(inSnapshot, &snapshot)) {
AutoOpenSurface opener(OPEN_READ_ONLY, snapshot);
gfxASurface* source = opener.Get();
mShadowTarget->DrawSurface(source, source->GetSize());
RefPtr<DataSourceSurface> surf = GetSurfaceForDescriptor(snapshot);
mShadowTarget->GetDrawTarget()->CopySurface(surf,
IntRect(0, 0, bounds.Size().width, bounds.Size().height),
IntPoint(0, 0));
}
if (IsSurfaceDescriptorValid(snapshot)) {
mForwarder->DestroySharedSurface(&snapshot);

Просмотреть файл

@ -15,7 +15,6 @@
#include "nsAString.h"
#include "nsPrintfCString.h" // for nsPrintfCString
#include "nsString.h" // for nsAutoCString
#include "ipc/AutoOpenSurface.h" // for AutoOpenSurface
#include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL
namespace mozilla {
@ -622,19 +621,12 @@ ContentHostIncremental::TextureUpdateRequest::Execute(ContentHostIncremental* aH
IntPoint offset = ToIntPoint(-mUpdated.GetBounds().TopLeft());
AutoOpenSurface surf(OPEN_READ_ONLY, mDescriptor);
nsRefPtr<gfxImageSurface> thebesSurf = surf.GetAsImage();
RefPtr<DataSourceSurface> sourceSurf =
gfx::Factory::CreateWrappingDataSourceSurface(thebesSurf->Data(),
thebesSurf->Stride(),
ToIntSize(thebesSurf->GetSize()),
ImageFormatToSurfaceFormat(thebesSurf->Format()));
RefPtr<DataSourceSurface> surf = GetSurfaceForDescriptor(mDescriptor);
if (mTextureId == TextureFront) {
aHost->mSource->Update(sourceSurf, &mUpdated, &offset);
aHost->mSource->Update(surf, &mUpdated, &offset);
} else {
aHost->mSourceOnWhite->Update(sourceSurf, &mUpdated, &offset);
aHost->mSourceOnWhite->Update(surf, &mUpdated, &offset);
}
}

Просмотреть файл

@ -8,7 +8,6 @@
#include "gfxContext.h"
#include "gfxImageSurface.h"
#include "Effects.h"
#include "ipc/AutoOpenSurface.h"
#include "mozilla/layers/YCbCrImageDataSerializer.h"
#include "gfxWindowsPlatform.h"
#include "gfxD2DSurface.h"

Просмотреть файл

@ -4,7 +4,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ipc/AutoOpenSurface.h"
#include "mozilla/layers/PLayerTransaction.h"
#include "gfxImageSurface.h"

Просмотреть файл

@ -3,7 +3,6 @@
* 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 "ipc/AutoOpenSurface.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Point.h"
#include "mozilla/RefPtr.h"

Просмотреть файл

@ -8,7 +8,6 @@
#include "gfxContext.h"
#include "gfxImageSurface.h"
#include "Effects.h"
#include "ipc/AutoOpenSurface.h"
#include "mozilla/layers/YCbCrImageDataSerializer.h"
#include "gfxWindowsPlatform.h"
#include "gfx2DGlue.h"

Просмотреть файл

@ -9,8 +9,6 @@
// typedefs conflicts.
#include "mozilla/ArrayUtils.h"
#include "ipc/AutoOpenSurface.h"
#include "ThebesLayerD3D9.h"
#include "gfxPlatform.h"

Просмотреть файл

@ -1,73 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* 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_layers_AutoOpenSurface_h
#define mozilla_layers_AutoOpenSurface_h 1
#include "base/basictypes.h"
#include "gfxASurface.h"
#include "mozilla/layers/PLayerTransaction.h"
#include "ShadowLayers.h"
namespace mozilla {
namespace layers {
/**
* Some surface types can be fairly expensive to open. This helper
* tries to put off opening surfaces as long as it can, until
* ahsolutely necessary. And after being forced to open, it remembers
* the mapping so it doesn't need to be redone.
*/
class MOZ_STACK_CLASS AutoOpenSurface
{
public:
/** |aDescriptor| must be valid while AutoOpenSurface is
* in scope. */
AutoOpenSurface(OpenMode aMode, const SurfaceDescriptor& aDescriptor);
~AutoOpenSurface();
/**
* These helpers do not necessarily need to open the descriptor to
* return an answer.
*/
gfxContentType ContentType();
gfxImageFormat ImageFormat();
gfx::IntSize Size();
/** This can't escape the scope of AutoOpenSurface. */
gfxASurface* Get();
/**
* This can't escape the scope of AutoOpenSurface.
*
* This method is currently just a convenience wrapper around
* gfxASurface::GetAsImageSurface() --- it returns a valid surface
* exactly when this->Get()->GetAsImageSurface() would. Clients
* that need guaranteed (fast) ImageSurfaces should allocate the
* underlying descriptor with capability MAP_AS_IMAGE_SURFACE, in
* which case this helper is guaranteed to succeed.
*/
gfxImageSurface* GetAsImage();
private:
SurfaceDescriptor mDescriptor;
nsRefPtr<gfxASurface> mSurface;
nsRefPtr<gfxImageSurface> mSurfaceAsImage;
OpenMode mMode;
AutoOpenSurface(const AutoOpenSurface&) MOZ_DELETE;
AutoOpenSurface& operator=(const AutoOpenSurface&) MOZ_DELETE;
};
} // namespace layers
} // namespace mozilla
#endif // ifndef mozilla_layers_AutoOpenSurface_h

Просмотреть файл

@ -42,7 +42,6 @@ class PTextureChild;
*/
class CompositableForwarder : public ISurfaceAllocator
{
friend class AutoOpenSurface;
public:
CompositableForwarder()

Просмотреть файл

@ -9,7 +9,6 @@
#include <stdint.h> // for uint64_t
#include <map> // for _Rb_tree_iterator, etc
#include <utility> // for pair
#include "AutoOpenSurface.h" // for AutoOpenSurface
#include "LayerTransactionParent.h" // for LayerTransactionParent
#include "RenderTrace.h" // for RenderTraceLayers
#include "base/message_loop.h" // for MessageLoop
@ -313,12 +312,7 @@ bool
CompositorParent::RecvMakeSnapshot(const SurfaceDescriptor& aInSnapshot,
SurfaceDescriptor* aOutSnapshot)
{
AutoOpenSurface opener(OPEN_READ_WRITE, aInSnapshot);
gfx::IntSize size = opener.Size();
// XXX CreateDrawTargetForSurface will always give us a Cairo surface, we can
// do better if AutoOpenSurface uses Moz2D directly.
RefPtr<DrawTarget> target =
gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(opener.Get(), size);
RefPtr<DrawTarget> target = GetDrawTargetForDescriptor(aInSnapshot);
ForceComposeToTarget(target);
*aOutSnapshot = aInSnapshot;
return true;

Просмотреть файл

@ -20,6 +20,8 @@
#include "nsAutoPtr.h" // for nsRefPtr, getter_AddRefs, etc
#include "nsDebug.h" // for NS_RUNTIMEABORT
#include "nsXULAppAPI.h" // for XRE_GetProcessType, etc
#include "mozilla/ipc/Shmem.h"
#include "mozilla/layers/ImageDataSerializer.h"
#ifdef DEBUG
#include "prenv.h"
#endif
@ -57,6 +59,41 @@ ISurfaceAllocator::Finalize()
ShrinkShmemSectionHeap();
}
static inline uint8_t*
GetAddressFromDescriptor(const SurfaceDescriptor& aDescriptor, size_t& aSize)
{
MOZ_ASSERT(IsSurfaceDescriptorValid(aDescriptor));
MOZ_ASSERT(aDescriptor.type() == SurfaceDescriptor::TShmem ||
aDescriptor.type() == SurfaceDescriptor::TMemoryImage);
if (aDescriptor.type() == SurfaceDescriptor::TShmem) {
Shmem shmem(aDescriptor.get_Shmem());
aSize = shmem.Size<uint8_t>();
return shmem.get<uint8_t>();
} else {
const MemoryImage& image = aDescriptor.get_MemoryImage();
aSize = std::numeric_limits<size_t>::max();
return reinterpret_cast<uint8_t*>(image.data());
}
}
TemporaryRef<gfx::DrawTarget>
GetDrawTargetForDescriptor(const SurfaceDescriptor& aDescriptor)
{
size_t size;
uint8_t* data = GetAddressFromDescriptor(aDescriptor, size);
ImageDataDeserializer image(data, size);
return image.GetAsDrawTarget(gfx::BackendType::CAIRO);
}
TemporaryRef<gfx::DataSourceSurface>
GetSurfaceForDescriptor(const SurfaceDescriptor& aDescriptor)
{
size_t size;
uint8_t* data = GetAddressFromDescriptor(aDescriptor, size);
ImageDataDeserializer image(data, size);
return image.GetAsSurface();
}
bool
ISurfaceAllocator::AllocSharedImageSurface(const gfx::IntSize& aSize,
gfxContentType aContent,

Просмотреть файл

@ -40,6 +40,9 @@ namespace mozilla {
namespace ipc {
class Shmem;
}
namespace gfx {
class DataSourceSurface;
}
namespace layers {
@ -68,6 +71,9 @@ mozilla::ipc::SharedMemory::SharedMemoryType OptimalShmemType();
bool IsSurfaceDescriptorValid(const SurfaceDescriptor& aSurface);
bool IsSurfaceDescriptorOwned(const SurfaceDescriptor& aDescriptor);
bool ReleaseOwnedSurfaceDescriptor(const SurfaceDescriptor& aDescriptor);
TemporaryRef<gfx::DrawTarget> GetDrawTargetForDescriptor(const SurfaceDescriptor& aDescriptor);
TemporaryRef<gfx::DataSourceSurface> GetSurfaceForDescriptor(const SurfaceDescriptor& aDescriptor);
/**
* An interface used to create and destroy surfaces that are shared with the
* Compositor process (using shmem, or gralloc, or other platform specific memory)

Просмотреть файл

@ -8,7 +8,6 @@
#include "ShadowLayers.h"
#include <set> // for _Rb_tree_const_iterator, etc
#include <vector> // for vector
#include "AutoOpenSurface.h" // for AutoOpenSurface, etc
#include "GeckoProfiler.h" // for PROFILER_LABEL
#include "ISurfaceAllocator.h" // for IsSurfaceDescriptorValid
#include "Layers.h" // for Layer
@ -781,78 +780,6 @@ ISurfaceAllocator::PlatformDestroySharedSurface(SurfaceDescriptor*)
#endif // !defined(MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS)
AutoOpenSurface::AutoOpenSurface(OpenMode aMode,
const SurfaceDescriptor& aDescriptor)
: mDescriptor(aDescriptor)
, mMode(aMode)
{
MOZ_ASSERT(IsSurfaceDescriptorValid(mDescriptor));
}
AutoOpenSurface::~AutoOpenSurface()
{
if (mSurface) {
mSurface = nullptr;
ShadowLayerForwarder::CloseDescriptor(mDescriptor);
}
}
gfxContentType
AutoOpenSurface::ContentType()
{
if (mSurface) {
return mSurface->GetContentType();
}
return ShadowLayerForwarder::GetDescriptorSurfaceContentType(
mDescriptor, mMode, getter_AddRefs(mSurface));
}
gfxImageFormat
AutoOpenSurface::ImageFormat()
{
if (mSurface) {
nsRefPtr<gfxImageSurface> img = mSurface->GetAsImageSurface();
if (img) {
gfxImageFormat format = img->Format();
NS_ASSERTION(format != gfxImageFormat::Unknown,
"ImageSurface RGB format should be known");
return format;
}
}
return ShadowLayerForwarder::GetDescriptorSurfaceImageFormat(
mDescriptor, mMode, getter_AddRefs(mSurface));
}
gfx::IntSize
AutoOpenSurface::Size()
{
if (mSurface) {
return mSurface->GetSize().ToIntSize();
}
return ShadowLayerForwarder::GetDescriptorSurfaceSize(
mDescriptor, mMode, getter_AddRefs(mSurface));
}
gfxASurface*
AutoOpenSurface::Get()
{
if (!mSurface) {
mSurface = ShadowLayerForwarder::OpenDescriptor(mMode, mDescriptor);
}
return mSurface.get();
}
gfxImageSurface*
AutoOpenSurface::GetAsImage()
{
if (!mSurfaceAsImage) {
mSurfaceAsImage = Get()->GetAsImageSurface();
}
return mSurfaceAsImage.get();
}
void
ShadowLayerForwarder::Connect(CompositableClient* aCompositable)
{

Просмотреть файл

@ -48,7 +48,6 @@ class PLayerTransactionParent;
class LayerTransactionChild;
class RefLayerComposite;
class ShadowableLayer;
class Shmem;
class ShmemTextureClient;
class SurfaceDescriptor;
class TextureClient;
@ -134,7 +133,6 @@ class Transaction;
class ShadowLayerForwarder : public CompositableForwarder
{
friend class AutoOpenSurface;
friend class ContentClientIncremental;
friend class ClientLayerManager;

Просмотреть файл

@ -17,7 +17,6 @@
#include "gfx2DGlue.h" // for ContentForFormat, etc
#include "gfxImageSurface.h" // for gfxImageSurface
#include "gfxReusableSurfaceWrapper.h" // for gfxReusableSurfaceWrapper
#include "ipc/AutoOpenSurface.h" // for AutoOpenSurface
#include "mozilla/gfx/2D.h" // for DataSourceSurface
#include "mozilla/gfx/BaseSize.h" // for BaseSize
#include "mozilla/layers/CompositorOGL.h" // for CompositorOGL