2022-02-11 19:49:55 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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_SOURCESURFACEWEBGL_H_
|
|
|
|
#define MOZILLA_GFX_SOURCESURFACEWEBGL_H_
|
|
|
|
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/WeakPtr.h"
|
|
|
|
|
2022-02-11 19:49:56 +00:00
|
|
|
namespace mozilla::gfx {
|
2022-02-11 19:49:55 +00:00
|
|
|
|
|
|
|
class DrawTargetWebgl;
|
2023-12-18 18:10:46 +00:00
|
|
|
class SharedContextWebgl;
|
2022-02-11 19:49:55 +00:00
|
|
|
class TextureHandle;
|
|
|
|
|
|
|
|
// SourceSurfaceWebgl holds WebGL resources that can be used to efficiently
|
|
|
|
// copy snapshot data between multiple DrawTargetWebgls. It also takes care
|
|
|
|
// of copy-on-write behavior when the owner target is modified or destructs.
|
|
|
|
class SourceSurfaceWebgl : public DataSourceSurface {
|
|
|
|
public:
|
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceWebgl, override)
|
|
|
|
|
2022-07-26 01:28:48 +00:00
|
|
|
explicit SourceSurfaceWebgl(DrawTargetWebgl* aDT);
|
2022-02-11 19:49:55 +00:00
|
|
|
virtual ~SourceSurfaceWebgl();
|
|
|
|
|
|
|
|
SurfaceType GetType() const override { return SurfaceType::WEBGL; }
|
|
|
|
IntSize GetSize() const override { return mSize; }
|
|
|
|
SurfaceFormat GetFormat() const override { return mFormat; }
|
|
|
|
|
|
|
|
uint8_t* GetData() override;
|
|
|
|
int32_t Stride() override;
|
|
|
|
|
|
|
|
bool Map(MapType aType, MappedSurface* aMappedSurface) override;
|
|
|
|
void Unmap() override;
|
|
|
|
|
2022-02-11 19:49:56 +00:00
|
|
|
bool HasReadData() const { return !!mData; }
|
|
|
|
|
2022-12-07 21:06:32 +00:00
|
|
|
already_AddRefed<SourceSurface> ExtractSubrect(const IntRect& aRect) override;
|
|
|
|
|
2022-02-11 19:49:55 +00:00
|
|
|
private:
|
|
|
|
friend class DrawTargetWebgl;
|
2023-12-18 18:10:46 +00:00
|
|
|
friend class SharedContextWebgl;
|
2022-02-11 19:49:55 +00:00
|
|
|
|
2024-02-01 11:03:59 +00:00
|
|
|
explicit SourceSurfaceWebgl(const RefPtr<SharedContextWebgl>& aSharedContext);
|
|
|
|
|
2022-02-11 19:49:55 +00:00
|
|
|
bool EnsureData();
|
|
|
|
|
2022-06-02 15:27:00 +00:00
|
|
|
void DrawTargetWillChange(bool aNeedHandle);
|
2022-02-11 19:49:55 +00:00
|
|
|
|
|
|
|
void GiveTexture(RefPtr<TextureHandle> aHandle);
|
|
|
|
|
2024-02-01 11:03:59 +00:00
|
|
|
void SetHandle(TextureHandle* aHandle);
|
|
|
|
|
2023-12-18 18:10:46 +00:00
|
|
|
void OnUnlinkTexture(SharedContextWebgl* aContext);
|
2022-02-11 19:49:55 +00:00
|
|
|
|
|
|
|
DrawTargetWebgl* GetTarget() const { return mDT.get(); }
|
|
|
|
|
|
|
|
SurfaceFormat mFormat = SurfaceFormat::UNKNOWN;
|
|
|
|
IntSize mSize;
|
|
|
|
// Any data that has been read back from the WebGL context for mapping.
|
|
|
|
RefPtr<DataSourceSurface> mData;
|
|
|
|
// The draw target that currently owns the texture for this surface.
|
|
|
|
WeakPtr<DrawTargetWebgl> mDT;
|
|
|
|
// The actual shared context that any WebGL resources belong to.
|
2023-12-18 18:10:46 +00:00
|
|
|
WeakPtr<SharedContextWebgl> mSharedContext;
|
2022-02-11 19:49:55 +00:00
|
|
|
// If this snapshot has been copied into a cached texture handle.
|
|
|
|
RefPtr<TextureHandle> mHandle;
|
|
|
|
};
|
|
|
|
|
2022-02-11 19:49:56 +00:00
|
|
|
} // namespace mozilla::gfx
|
2022-02-11 19:49:55 +00:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_SOURCESURFACEWEBGL_H_ */
|