Skip to content

Commit fa20ed6

Browse files
Detached OffscreenCanvas should not transfer ImageBuffer
https://bugs.webkit.org/show_bug.cgi?id=275144 rdar://129270155 Reviewed by Simon Fraser. The buffer cannot contain anything, as only the context-less OffscreenCanvases can be detached. * Source/WebCore/bindings/js/SerializedScriptValue.cpp: (WebCore::SerializedScriptValue::computeMemoryCost const): * Source/WebCore/html/OffscreenCanvas.cpp: (WebCore::DetachedOffscreenCanvas::DetachedOffscreenCanvas): (WebCore::OffscreenCanvas::create): (WebCore::OffscreenCanvas::detach): (WebCore::DetachedOffscreenCanvas::takeImageBuffer): Deleted. (WebCore::OffscreenCanvas::takeImageBuffer const): Deleted. * Source/WebCore/html/OffscreenCanvas.h: (WebCore::DetachedOffscreenCanvas::originClean const): (WebCore::DetachedOffscreenCanvas::memoryCost const): Deleted. Canonical link: https://commits.webkit.org/279775@main
1 parent d637301 commit fa20ed6

File tree

3 files changed

+4
-44
lines changed

3 files changed

+4
-44
lines changed

Source/WebCore/bindings/js/SerializedScriptValue.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5873,12 +5873,6 @@ size_t SerializedScriptValue::computeMemoryCost() const
58735873
cost += detachedImageBitmap->memoryCost();
58745874
}
58755875

5876-
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
5877-
for (auto& canvas : m_internals.detachedOffscreenCanvases) {
5878-
if (canvas)
5879-
cost += canvas->memoryCost();
5880-
}
5881-
#endif
58825876
#if ENABLE(WEB_RTC)
58835877
for (auto& channel : m_internals.detachedRTCDataChannels) {
58845878
if (channel)

Source/WebCore/html/OffscreenCanvas.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,15 @@ class OffscreenCanvasPlaceholderData : public ThreadSafeRefCounted<OffscreenCanv
9393
RefPtr<ImageBufferPipe::Source> m_pipeSource;
9494
};
9595

96-
DetachedOffscreenCanvas::DetachedOffscreenCanvas(std::unique_ptr<SerializedImageBuffer> buffer, const IntSize& size, bool originClean, RefPtr<OffscreenCanvasPlaceholderData> placeholderData)
97-
: m_buffer(WTFMove(buffer))
98-
, m_placeholderData(WTFMove(placeholderData))
96+
DetachedOffscreenCanvas::DetachedOffscreenCanvas(const IntSize& size, bool originClean, RefPtr<OffscreenCanvasPlaceholderData> placeholderData)
97+
: m_placeholderData(WTFMove(placeholderData))
9998
, m_size(size)
10099
, m_originClean(originClean)
101100
{
102101
}
103102

104103
DetachedOffscreenCanvas::~DetachedOffscreenCanvas() = default;
105104

106-
RefPtr<ImageBuffer> DetachedOffscreenCanvas::takeImageBuffer(ScriptExecutionContext& context)
107-
{
108-
if (!m_buffer)
109-
return nullptr;
110-
return SerializedImageBuffer::sinkIntoImageBuffer(WTFMove(m_buffer), context.graphicsClient());
111-
}
112-
113105
RefPtr<OffscreenCanvasPlaceholderData> DetachedOffscreenCanvas::takePlaceholderData()
114106
{
115107
return WTFMove(m_placeholderData);
@@ -138,7 +130,6 @@ Ref<OffscreenCanvas> OffscreenCanvas::create(ScriptExecutionContext& scriptExecu
138130
Ref<OffscreenCanvas> OffscreenCanvas::create(ScriptExecutionContext& scriptExecutionContext, std::unique_ptr<DetachedOffscreenCanvas>&& detachedCanvas)
139131
{
140132
Ref<OffscreenCanvas> clone = adoptRef(*new OffscreenCanvas(scriptExecutionContext, detachedCanvas->size(), detachedCanvas->takePlaceholderData()));
141-
clone->setImageBuffer(detachedCanvas->takeImageBuffer(scriptExecutionContext));
142133
if (!detachedCanvas->originClean())
143134
clone->setOriginTainted();
144135
clone->suspendIfNeeded();
@@ -473,7 +464,7 @@ std::unique_ptr<DetachedOffscreenCanvas> OffscreenCanvas::detach()
473464

474465
m_detached = true;
475466

476-
auto detached = makeUnique<DetachedOffscreenCanvas>(takeImageBuffer(), size(), originClean(), WTFMove(m_placeholderData));
467+
auto detached = makeUnique<DetachedOffscreenCanvas>(size(), originClean(), WTFMove(m_placeholderData));
477468
setSize(IntSize(0, 0));
478469
return detached;
479470
}
@@ -535,20 +526,6 @@ void OffscreenCanvas::setImageBufferAndMarkDirty(RefPtr<ImageBuffer>&& buffer)
535526
CanvasBase::didDraw(FloatRect(FloatPoint(), size()));
536527
}
537528

538-
std::unique_ptr<SerializedImageBuffer> OffscreenCanvas::takeImageBuffer() const
539-
{
540-
ASSERT(m_detached);
541-
542-
if (size().isEmpty())
543-
return nullptr;
544-
545-
clearCopiedImage();
546-
RefPtr<ImageBuffer> buffer = setImageBuffer(nullptr);
547-
if (!buffer)
548-
return nullptr;
549-
return ImageBuffer::sinkIntoSerializedImageBuffer(WTFMove(buffer));
550-
}
551-
552529
void OffscreenCanvas::reset()
553530
{
554531
resetGraphicsContextState();

Source/WebCore/html/OffscreenCanvas.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,13 @@ class DetachedOffscreenCanvas {
8282
friend class OffscreenCanvas;
8383

8484
public:
85-
DetachedOffscreenCanvas(std::unique_ptr<SerializedImageBuffer>, const IntSize&, bool originClean, RefPtr<OffscreenCanvasPlaceholderData>);
85+
DetachedOffscreenCanvas(const IntSize&, bool originClean, RefPtr<OffscreenCanvasPlaceholderData>);
8686
WEBCORE_EXPORT ~DetachedOffscreenCanvas();
87-
88-
RefPtr<ImageBuffer> takeImageBuffer(ScriptExecutionContext&);
8987
const IntSize& size() const { return m_size; }
9088
bool originClean() const { return m_originClean; }
91-
size_t memoryCost() const
92-
{
93-
auto* buffer = m_buffer.get();
94-
if (buffer)
95-
return buffer->memoryCost();
96-
return 0;
97-
}
9889
RefPtr<OffscreenCanvasPlaceholderData> takePlaceholderData();
9990

10091
private:
101-
std::unique_ptr<SerializedImageBuffer> m_buffer;
10292
RefPtr<OffscreenCanvasPlaceholderData> m_placeholderData;
10393
IntSize m_size;
10494
bool m_originClean;
@@ -181,7 +171,6 @@ class OffscreenCanvas final : public ActiveDOMObject, public RefCounted<Offscree
181171
void setSize(const IntSize&) final;
182172

183173
void createImageBuffer() const final;
184-
std::unique_ptr<SerializedImageBuffer> takeImageBuffer() const;
185174

186175
void reset();
187176
void scheduleCommitToPlaceholderCanvas();

0 commit comments

Comments
 (0)