Bug 1728955: part 2) Add more logging to Windows-specific clipboard code. r=masayuki
[gecko.git] / image / SourceSurfaceBlobImage.h
blob7690e47ede156c042e708a21b8daec0f561044e4
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_SOURCESURFACEBLOBIMAGE_H_
8 #define MOZILLA_IMAGE_SOURCESURFACEBLOBIMAGE_H_
10 #include "mozilla/Maybe.h"
11 #include "mozilla/SVGImageContext.h"
12 #include "mozilla/gfx/2D.h"
13 #include "mozilla/layers/WebRenderLayerManager.h"
14 #include "ImageRegion.h"
16 #include <vector>
18 namespace mozilla {
19 namespace image {
21 class BlobImageKeyData final {
22 public:
23 BlobImageKeyData(layers::WebRenderLayerManager* aManager,
24 const wr::BlobImageKey& aBlobKey,
25 std::vector<RefPtr<gfx::ScaledFont>>&& aScaledFonts,
26 std::vector<RefPtr<gfx::SourceSurface>>&& aExternalSurfaces)
27 : mManager(aManager),
28 mBlobKey(aBlobKey),
29 mScaledFonts(std::move(aScaledFonts)),
30 mExternalSurfaces(std::move(aExternalSurfaces)),
31 mDirty(false) {}
33 BlobImageKeyData(BlobImageKeyData&& aOther) noexcept
34 : mManager(std::move(aOther.mManager)),
35 mBlobKey(aOther.mBlobKey),
36 mScaledFonts(std::move(aOther.mScaledFonts)),
37 mExternalSurfaces(std::move(aOther.mExternalSurfaces)),
38 mDirty(aOther.mDirty) {}
40 BlobImageKeyData& operator=(BlobImageKeyData&& aOther) noexcept {
41 mManager = std::move(aOther.mManager);
42 mBlobKey = aOther.mBlobKey;
43 mScaledFonts = std::move(aOther.mScaledFonts);
44 mExternalSurfaces = std::move(aOther.mExternalSurfaces);
45 mDirty = aOther.mDirty;
46 return *this;
49 BlobImageKeyData(const BlobImageKeyData&) = delete;
50 BlobImageKeyData& operator=(const BlobImageKeyData&) = delete;
52 RefPtr<layers::WebRenderLayerManager> mManager;
53 wr::BlobImageKey mBlobKey;
54 std::vector<RefPtr<gfx::ScaledFont>> mScaledFonts;
55 std::vector<RefPtr<gfx::SourceSurface>> mExternalSurfaces;
56 bool mDirty;
59 } // namespace image
60 } // namespace mozilla
62 MOZ_DECLARE_RELOCATE_USING_MOVE_CONSTRUCTOR(mozilla::image::BlobImageKeyData);
64 namespace mozilla {
65 namespace wr {
66 class IpcResourceUpdateQueue;
67 } // namespace wr
69 namespace image {
70 class SVGDocumentWrapper;
72 /**
73 * This class is used to wrap blob recordings stored in ImageContainers, used
74 * by SVG images. Unlike rasterized images stored in SourceSurfaceSharedData,
75 * each SourceSurfaceBlobImage can only be used by one WebRenderLayerManager
76 * because the recording is tied to a particular instance.
78 class SourceSurfaceBlobImage final : public gfx::SourceSurface {
79 public:
80 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceBlobImage, override)
82 SourceSurfaceBlobImage(SVGDocumentWrapper* aSVGDocumentWrapper,
83 const Maybe<SVGImageContext>& aSVGContext,
84 const Maybe<ImageIntRegion>& aRegion,
85 const gfx::IntSize& aSize, uint32_t aWhichFrame,
86 uint32_t aImageFlags);
88 Maybe<wr::BlobImageKey> UpdateKey(layers::WebRenderLayerManager* aManager,
89 wr::IpcResourceUpdateQueue& aResources);
91 void MarkDirty();
93 gfx::SurfaceType GetType() const override {
94 return gfx::SurfaceType::BLOB_IMAGE;
96 gfx::IntSize GetSize() const override { return mSize; }
97 gfx::SurfaceFormat GetFormat() const override {
98 return gfx::SurfaceFormat::OS_RGBA;
100 already_AddRefed<gfx::DataSourceSurface> GetDataSurface() override {
101 return nullptr;
104 void SizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
105 SizeOfInfo& aInfo) const override {
106 aInfo.AddType(gfx::SurfaceType::BLOB_IMAGE);
107 aInfo.mHeapBytes += mKeys.ShallowSizeOfExcludingThis(aMallocSizeOf);
110 private:
111 ~SourceSurfaceBlobImage() override;
113 Maybe<BlobImageKeyData> RecordDrawing(layers::WebRenderLayerManager* aManager,
114 wr::IpcResourceUpdateQueue& aResources,
115 Maybe<wr::BlobImageKey> aBlobKey);
117 static void DestroyKeys(const AutoTArray<BlobImageKeyData, 1>& aKeys);
119 AutoTArray<BlobImageKeyData, 1> mKeys;
121 RefPtr<image::SVGDocumentWrapper> mSVGDocumentWrapper;
122 Maybe<SVGImageContext> mSVGContext;
123 Maybe<ImageIntRegion> mRegion;
124 gfx::IntSize mSize;
125 uint32_t mWhichFrame;
126 uint32_t mImageFlags;
129 } // namespace image
130 } // namespace mozilla
132 #endif /* MOZILLA_IMAGE_SOURCESURFACEBLOBIMAGE_H_ */