wasm的 surface.makeSurface js中:
CanvasKit.Surface.prototype.makeSurface = function(imageInfo) {
CanvasKit.setCurrentContext(this._context);
var s = this._makeSurface(imageInfo);
s._context = this._context;
return s;
};
c++中
.function("_makeSurface", optional_override([](SkSurface& self, SimpleImageInfo sii)->sk_sp<SkSurface> {
return self.makeSurface(toSkImageInfo(sii));
}), allow_raw_pointers())
SkImageInfo toSkImageInfo(const SimpleImageInfo& sii) {
return SkImageInfo::Make(sii.width, sii.height, sii.colorType, sii.alphaType,
sii.colorSpace ? sii.colorSpace : SkColorSpace::MakeSRGB());
}
实现类中:
sk_sp<SkSurface> SkSurface::makeSurface(const SkImageInfo& info) {
return asSB(this)->onNewSurface(info);
}
最终到gpu中:
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrRecordingContext* rContext,
const SkSurfaceCharacterization& c,
SkBudgeted budgeted) {
if (!rContext || !c.isValid()) {
return nullptr;
}
if (c.usesGLFBO0()) {
// If we are making the surface we will never use FBO0.
return nullptr;
}
if (c.vulkanSecondaryCBCompatible()) {
return nullptr;
}
auto device = rContext->priv().createDevice(budgeted, c.imageInfo(), SkBackingFit::kExact,
c.sampleCount(), GrMipmapped(c.isMipMapped()),
c.isProtected(), c.origin(), c.surfaceProps(),
skgpu::BaseDevice::InitContents::kClear);
if (!device) {
return nullptr;
}
sk_sp<SkSurface> result = sk_make_sp<SkSurface_Gpu>(std::move(device));
#ifdef SK_DEBUG
if (result) {
SkASSERT(result->isCompatible(c));
}
#endif
return result;
}