Backed out 3 changesets (bug 1892041) for causing SM failures in test262. CLOSED...
[gecko.git] / image / BlobSurfaceProvider.h
blob8222450b39c3dd99b4e4164f7d8bd2ce7c6d830d
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_IMAGE_BLOBSURFACEPROVIDER_H_
8 #define MOZILLA_IMAGE_BLOBSURFACEPROVIDER_H_
10 #include "mozilla/Maybe.h"
11 #include "mozilla/SVGImageContext.h"
12 #include "mozilla/gfx/2D.h"
13 #include "mozilla/gfx/DrawEventRecorder.h"
14 #include "mozilla/layers/WebRenderLayerManager.h"
15 #include "ImageRegion.h"
16 #include "ISurfaceProvider.h"
18 #include <vector>
20 namespace mozilla {
21 namespace image {
23 class BlobImageKeyData final {
24 public:
25 BlobImageKeyData(
26 layers::WebRenderLayerManager* aManager, const wr::BlobImageKey& aBlobKey,
27 std::vector<RefPtr<gfx::ScaledFont>>&& aScaledFonts,
28 gfx::DrawEventRecorderPrivate::ExternalSurfacesHolder&& aExternalSurfaces)
29 : mManager(aManager),
30 mBlobKey(aBlobKey),
31 mScaledFonts(std::move(aScaledFonts)),
32 mExternalSurfaces(std::move(aExternalSurfaces)),
33 mDirty(false) {}
35 BlobImageKeyData(BlobImageKeyData&& aOther) noexcept
36 : mManager(std::move(aOther.mManager)),
37 mBlobKey(aOther.mBlobKey),
38 mScaledFonts(std::move(aOther.mScaledFonts)),
39 mExternalSurfaces(std::move(aOther.mExternalSurfaces)),
40 mDirty(aOther.mDirty) {}
42 BlobImageKeyData& operator=(BlobImageKeyData&& aOther) noexcept {
43 mManager = std::move(aOther.mManager);
44 mBlobKey = aOther.mBlobKey;
45 mScaledFonts = std::move(aOther.mScaledFonts);
46 mExternalSurfaces = std::move(aOther.mExternalSurfaces);
47 mDirty = aOther.mDirty;
48 return *this;
51 BlobImageKeyData(const BlobImageKeyData&) = delete;
52 BlobImageKeyData& operator=(const BlobImageKeyData&) = delete;
54 RefPtr<layers::WebRenderLayerManager> mManager;
55 wr::BlobImageKey mBlobKey;
56 std::vector<RefPtr<gfx::ScaledFont>> mScaledFonts;
57 gfx::DrawEventRecorderPrivate::ExternalSurfacesHolder mExternalSurfaces;
58 bool mDirty;
61 } // namespace image
62 } // namespace mozilla
64 MOZ_DECLARE_RELOCATE_USING_MOVE_CONSTRUCTOR(mozilla::image::BlobImageKeyData);
66 namespace mozilla {
67 namespace wr {
68 class IpcResourceUpdateQueue;
69 } // namespace wr
71 namespace image {
72 class SVGDocumentWrapper;
74 /**
75 * An ISurfaceProvider that manages blob recordings of SVG images. Unlike the
76 * rasterized ISurfaceProviders, it only provides a recording which may be
77 * replayed in the compositor process by WebRender. It may be invalidated
78 * directly in order to reuse the resource ids and underlying buffers when the
79 * SVG image has changed (e.g. it is animated).
81 class BlobSurfaceProvider final : public ISurfaceProvider {
82 public:
83 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BlobSurfaceProvider, override)
85 BlobSurfaceProvider(ImageKey aImageKey, const SurfaceKey& aSurfaceKey,
86 SVGDocumentWrapper* aSVGDocumentWrapper,
87 uint32_t aImageFlags);
89 bool IsFinished() const override { return true; }
91 size_t LogicalSizeInBytes() const override {
92 const gfx::IntSize& size = GetSurfaceKey().Size();
93 return size.width * size.height * sizeof(uint32_t);
96 nsresult UpdateKey(layers::RenderRootStateManager* aManager,
97 wr::IpcResourceUpdateQueue& aResources,
98 wr::ImageKey& aKey) override;
100 void InvalidateRecording() override;
102 void AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
103 const AddSizeOfCb& aCallback) override {
104 AddSizeOfCbData metadata;
105 metadata.mFinished = true;
106 metadata.mHeapBytes += mKeys.ShallowSizeOfExcludingThis(aMallocSizeOf);
108 gfx::SourceSurface::SizeOfInfo info;
109 info.AddType(gfx::SurfaceType::BLOB_IMAGE);
110 metadata.Accumulate(info);
112 aCallback(metadata);
115 protected:
116 DrawableFrameRef DrawableRef(size_t aFrame) override {
117 MOZ_ASSERT_UNREACHABLE("BlobSurfaceProvider::DrawableRef not supported!");
118 return DrawableFrameRef();
120 bool IsLocked() const override { return true; }
121 void SetLocked(bool) override {}
123 private:
124 ~BlobSurfaceProvider() override;
126 Maybe<BlobImageKeyData> RecordDrawing(layers::WebRenderLayerManager* aManager,
127 wr::IpcResourceUpdateQueue& aResources,
128 Maybe<wr::BlobImageKey> aBlobKey);
130 static void DestroyKeys(const AutoTArray<BlobImageKeyData, 1>& aKeys);
132 AutoTArray<BlobImageKeyData, 1> mKeys;
134 RefPtr<image::SVGDocumentWrapper> mSVGDocumentWrapper;
135 uint32_t mImageFlags;
138 } // namespace image
139 } // namespace mozilla
141 #endif /* MOZILLA_IMAGE_BLOBSURFACEPROVIDER_H_ */