mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 897452 - Part 15 - Introduce a AtomicRefCountedWithFinalize class to factor our custom-refcounting needs - r=nical
This commit is contained in:
parent
fd6a5ca5ea
commit
ccf97a5a57
46
gfx/layers/AtomicRefCountedWithFinalize.h
Normal file
46
gfx/layers/AtomicRefCountedWithFinalize.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* -*- 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_ATOMICREFCOUNTEDWITHFINALIZE_H_
|
||||
#define MOZILLA_ATOMICREFCOUNTEDWITHFINALIZE_H_
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
template<typename T>
|
||||
class AtomicRefCountedWithFinalize
|
||||
{
|
||||
protected:
|
||||
AtomicRefCountedWithFinalize()
|
||||
: mRefCount(0)
|
||||
{}
|
||||
|
||||
~AtomicRefCountedWithFinalize() {}
|
||||
|
||||
public:
|
||||
void AddRef() {
|
||||
MOZ_ASSERT(mRefCount >= 0);
|
||||
++mRefCount;
|
||||
}
|
||||
|
||||
void Release() {
|
||||
MOZ_ASSERT(mRefCount > 0);
|
||||
if (0 == --mRefCount) {
|
||||
#ifdef DEBUG
|
||||
mRefCount = detail::DEAD;
|
||||
#endif
|
||||
static_cast<T*>(this)->Finalize();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Atomic<int> mRefCount;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -233,8 +233,7 @@ ShmemTextureClient::DropTextureData()
|
||||
}
|
||||
|
||||
TextureClient::TextureClient(TextureFlags aFlags)
|
||||
: mRefCount(0)
|
||||
, mActor(nullptr)
|
||||
: mActor(nullptr)
|
||||
, mFlags(aFlags)
|
||||
, mShared(false)
|
||||
, mValid(true)
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "nsAutoPtr.h" // for nsRefPtr
|
||||
#include "nsCOMPtr.h" // for already_AddRefed
|
||||
#include "nsISupportsImpl.h" // for TextureImage::AddRef, etc
|
||||
#include "mozilla/layers/AtomicRefCountedWithFinalize.h"
|
||||
|
||||
class gfxReusableSurfaceWrapper;
|
||||
class gfxASurface;
|
||||
@ -151,27 +152,12 @@ public:
|
||||
* several TextureClients.
|
||||
*/
|
||||
class TextureClient
|
||||
: public AtomicRefCountedWithFinalize<TextureClient>
|
||||
{
|
||||
public:
|
||||
TextureClient(TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT);
|
||||
virtual ~TextureClient();
|
||||
|
||||
void AddRef() {
|
||||
MOZ_ASSERT(mRefCount >= 0);
|
||||
++mRefCount;
|
||||
}
|
||||
|
||||
void Release() {
|
||||
MOZ_ASSERT(mRefCount > 0);
|
||||
if (0 == --mRefCount) {
|
||||
#ifdef DEBUG
|
||||
mRefCount = detail::DEAD;
|
||||
#endif
|
||||
Finalize();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
virtual TextureClientSurface* AsTextureClientSurface() { return nullptr; }
|
||||
virtual TextureClientDrawTarget* AsTextureClientDrawTarget() { return nullptr; }
|
||||
virtual TextureClientYCbCr* AsTextureClientYCbCr() { return nullptr; }
|
||||
@ -274,8 +260,6 @@ public:
|
||||
void ForceRemove();
|
||||
|
||||
private:
|
||||
Atomic<int> mRefCount;
|
||||
|
||||
/**
|
||||
* Called once, just before the destructor.
|
||||
*
|
||||
@ -284,6 +268,8 @@ private:
|
||||
*/
|
||||
void Finalize();
|
||||
|
||||
friend class AtomicRefCountedWithFinalize<TextureClient>;
|
||||
|
||||
protected:
|
||||
void AddFlags(TextureFlags aFlags)
|
||||
{
|
||||
|
@ -212,8 +212,7 @@ TextureHost::SetCompositableBackendSpecificData(CompositableBackendSpecificData*
|
||||
|
||||
|
||||
TextureHost::TextureHost(TextureFlags aFlags)
|
||||
: mRefCount(0)
|
||||
, mFlags(aFlags)
|
||||
: mFlags(aFlags)
|
||||
{}
|
||||
|
||||
TextureHost::~TextureHost()
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "nsRegion.h" // for nsIntRegion
|
||||
#include "nsTraceRefcnt.h" // for MOZ_COUNT_CTOR, etc
|
||||
#include "nscore.h" // for nsACString
|
||||
#include "mozilla/layers/AtomicRefCountedWithFinalize.h"
|
||||
|
||||
class gfxImageSurface;
|
||||
class gfxReusableSurfaceWrapper;
|
||||
@ -259,9 +260,8 @@ private:
|
||||
*
|
||||
*/
|
||||
class TextureHost
|
||||
: public AtomicRefCountedWithFinalize<TextureHost>
|
||||
{
|
||||
Atomic<int> mRefCount;
|
||||
|
||||
/**
|
||||
* Called once, just before the destructor.
|
||||
*
|
||||
@ -270,27 +270,13 @@ class TextureHost
|
||||
*/
|
||||
void Finalize();
|
||||
|
||||
friend class AtomicRefCountedWithFinalize<TextureHost>;
|
||||
|
||||
public:
|
||||
TextureHost(TextureFlags aFlags);
|
||||
|
||||
virtual ~TextureHost();
|
||||
|
||||
void AddRef() {
|
||||
MOZ_ASSERT(mRefCount >= 0);
|
||||
++mRefCount;
|
||||
}
|
||||
|
||||
void Release() {
|
||||
MOZ_ASSERT(mRefCount > 0);
|
||||
if (0 == --mRefCount) {
|
||||
#ifdef DEBUG
|
||||
mRefCount = detail::DEAD;
|
||||
#endif
|
||||
Finalize();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method.
|
||||
*/
|
||||
|
@ -98,6 +98,7 @@ EXPORTS.gfxipc += [
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.layers += [
|
||||
'AtomicRefCountedWithFinalize.h',
|
||||
'basic/BasicCompositor.h',
|
||||
'basic/MacIOSurfaceTextureHostBasic.h',
|
||||
'basic/TextureHostBasic.h',
|
||||
|
Loading…
Reference in New Issue
Block a user