blob: 5c5f063093ed905d9a05eb382cb8243ed517c622 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/webgpu/gpu_canvas_context.h"
#include "third_party/blink/renderer/bindings/modules/v8/rendering_context.h"
namespace blink {
GPUCanvasContext::Factory::Factory() {}
GPUCanvasContext::Factory::~Factory() {}
CanvasRenderingContext* GPUCanvasContext::Factory::Create(
CanvasRenderingContextHost* host,
const CanvasContextCreationAttributesCore& attrs) {
return MakeGarbageCollected<GPUCanvasContext>(host, attrs);
}
CanvasRenderingContext::ContextType GPUCanvasContext::Factory::GetContextType()
const {
return CanvasRenderingContext::kContextGPUPresent;
}
GPUCanvasContext::GPUCanvasContext(
CanvasRenderingContextHost* host,
const CanvasContextCreationAttributesCore& attrs)
: CanvasRenderingContext(host, attrs) {}
GPUCanvasContext::~GPUCanvasContext() {}
void GPUCanvasContext::Trace(blink::Visitor* visitor) {
visitor->Trace(swapchain_);
CanvasRenderingContext::Trace(visitor);
}
const IntSize& GPUCanvasContext::CanvasSize() const {
return Host()->Size();
}
// CanvasRenderingContext implementation
CanvasRenderingContext::ContextType GPUCanvasContext::GetContextType() const {
return CanvasRenderingContext::kContextGPUPresent;
}
void GPUCanvasContext::SetCanvasGetContextResult(RenderingContext& result) {
result.SetGPUCanvasContext(this);
}
void GPUCanvasContext::Stop() {
if (swapchain_) {
swapchain_->Neuter();
swapchain_ = nullptr;
}
stopped_ = true;
}
cc::Layer* GPUCanvasContext::CcLayer() const {
if (swapchain_) {
return swapchain_->CcLayer();
}
return nullptr;
}
// gpu_canvas_context.idl
GPUSwapChain* GPUCanvasContext::configureSwapChain(
const GPUSwapChainDescriptor* descriptor) {
// TODO(cwallez@chromium.org): This should probably throw an exception,
// implement the exception when the WebGPU group decided what it should be.
if (stopped_) {
return nullptr;
}
if (swapchain_) {
// Tell any previous swapchain that it will no longer be used and can
// destroy all its resources (and produce errors when used).
swapchain_->Neuter();
}
swapchain_ = GPUSwapChain::Create(this, descriptor);
return swapchain_;
}
} // namespace blink
|