Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / canvas / SourceSurfaceWebgl.h
blob098f11c41953e6d89e902269f290022e4cb1af44
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef MOZILLA_GFX_SOURCESURFACEWEBGL_H_
8 #define MOZILLA_GFX_SOURCESURFACEWEBGL_H_
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/WeakPtr.h"
13 namespace mozilla::gfx {
15 class DrawTargetWebgl;
16 class SharedContextWebgl;
17 class TextureHandle;
19 // SourceSurfaceWebgl holds WebGL resources that can be used to efficiently
20 // copy snapshot data between multiple DrawTargetWebgls. It also takes care
21 // of copy-on-write behavior when the owner target is modified or destructs.
22 class SourceSurfaceWebgl : public DataSourceSurface {
23 public:
24 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceWebgl, override)
26 explicit SourceSurfaceWebgl(DrawTargetWebgl* aDT);
27 virtual ~SourceSurfaceWebgl();
29 SurfaceType GetType() const override { return SurfaceType::WEBGL; }
30 IntSize GetSize() const override { return mSize; }
31 SurfaceFormat GetFormat() const override { return mFormat; }
33 uint8_t* GetData() override;
34 int32_t Stride() override;
36 bool Map(MapType aType, MappedSurface* aMappedSurface) override;
37 void Unmap() override;
39 bool HasReadData() const { return !!mData; }
41 already_AddRefed<SourceSurface> ExtractSubrect(const IntRect& aRect) override;
43 private:
44 friend class DrawTargetWebgl;
45 friend class SharedContextWebgl;
47 explicit SourceSurfaceWebgl(const RefPtr<SharedContextWebgl>& aSharedContext);
49 bool EnsureData();
51 void DrawTargetWillChange(bool aNeedHandle);
53 void GiveTexture(RefPtr<TextureHandle> aHandle);
55 void SetHandle(TextureHandle* aHandle);
57 void OnUnlinkTexture(SharedContextWebgl* aContext);
59 DrawTargetWebgl* GetTarget() const { return mDT.get(); }
61 SurfaceFormat mFormat = SurfaceFormat::UNKNOWN;
62 IntSize mSize;
63 // Any data that has been read back from the WebGL context for mapping.
64 RefPtr<DataSourceSurface> mData;
65 // The draw target that currently owns the texture for this surface.
66 WeakPtr<DrawTargetWebgl> mDT;
67 // The actual shared context that any WebGL resources belong to.
68 WeakPtr<SharedContextWebgl> mSharedContext;
69 // If this snapshot has been copied into a cached texture handle.
70 RefPtr<TextureHandle> mHandle;
73 } // namespace mozilla::gfx
75 #endif /* MOZILLA_GFX_SOURCESURFACEWEBGL_H_ */