This utilizes SurfaceDescriptorCanvasSurface to send canvas recording SourceSurfaces over the process gap, so that we don't need to query data from the canvas recording, which would incur multiple syncs and and inter-process copies. This does have to bypass some restrictions in BlitPreventReason, since many use-cases expect WebGL to automatically do (un)premultiply conversions when sending Canvas2D content to WebGL. TexUnpackBlobDesc needs to be modified so that instead of just allowing dataSurf to be stored, it can take normal sourceSurfs, which is a superset, so that recording surfaces (which are not data surfaces) can be traded around with the SurfaceDescriptorCanvasSurface and keep them alive with ref-counting as appropriate. Overall, this relies on the fact that Accelerated Canvas2D and WebGL are running from the same CanvasRender thread when AC2D is in use. In this case, by the time WebGL executes the command to use the SurfaceDescriptorCanvasSurface, the AC2D command queue has already been processed to produce the surface in question, so that no blocking is required. Differential Revision: https://phabricator.services.mozilla.com/D235263
148 lines
5.1 KiB
C++
148 lines
5.1 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef TEX_UNPACK_BLOB_H_
|
|
#define TEX_UNPACK_BLOB_H_
|
|
|
|
#include "GLContextTypes.h"
|
|
#include "mozilla/RefPtr.h"
|
|
#include "WebGLStrongTypes.h"
|
|
#include "WebGLTypes.h"
|
|
|
|
#include <memory>
|
|
|
|
namespace mozilla {
|
|
|
|
class UniqueBuffer;
|
|
class WebGLContext;
|
|
class WebGLTexture;
|
|
|
|
namespace dom {
|
|
class Element;
|
|
class HTMLCanvasElement;
|
|
class HTMLVideoElement;
|
|
} // namespace dom
|
|
|
|
namespace gfx {
|
|
class DataSourceSurface;
|
|
} // namespace gfx
|
|
|
|
namespace layers {
|
|
class Image;
|
|
class ImageContainer;
|
|
} // namespace layers
|
|
|
|
bool IsTarget3D(TexImageTarget target);
|
|
|
|
namespace webgl {
|
|
|
|
struct PackingInfo;
|
|
struct DriverUnpackInfo;
|
|
|
|
Maybe<std::string> BlitPreventReason(int32_t level, const ivec3& offset,
|
|
GLenum internalFormat,
|
|
const webgl::PackingInfo&,
|
|
const TexUnpackBlobDesc&,
|
|
OptionalRenderableFormatBits,
|
|
bool sameColorSpace,
|
|
bool allowConversion = false);
|
|
|
|
class TexUnpackBlob {
|
|
public:
|
|
const TexUnpackBlobDesc& mDesc;
|
|
bool mNeedsExactUpload = true;
|
|
|
|
static std::unique_ptr<TexUnpackBlob> Create(const TexUnpackBlobDesc&);
|
|
|
|
protected:
|
|
explicit TexUnpackBlob(const TexUnpackBlobDesc& desc) : mDesc(desc) {
|
|
MOZ_ASSERT_IF(!IsTarget3D(mDesc.imageTarget), mDesc.size.z == 1);
|
|
}
|
|
|
|
public:
|
|
virtual ~TexUnpackBlob() = default;
|
|
|
|
protected:
|
|
bool ConvertIfNeeded(const WebGLContext*, const uint32_t rowLength,
|
|
const uint32_t rowCount, WebGLTexelFormat srcFormat,
|
|
const uint8_t* const srcBegin, const ptrdiff_t srcStride,
|
|
WebGLTexelFormat dstFormat, const ptrdiff_t dstStride,
|
|
|
|
const uint8_t** const out_begin,
|
|
UniqueBuffer* const out_anchoredBuffer) const;
|
|
|
|
public:
|
|
virtual bool HasData() const { return true; }
|
|
|
|
virtual bool Validate(const WebGLContext*, const webgl::PackingInfo& pi) = 0;
|
|
|
|
// Returns false when we've generated a WebGL error.
|
|
// Returns true but with a non-zero *out_error if we still need to generate a
|
|
// WebGL error.
|
|
virtual bool TexOrSubImage(bool isSubImage, bool needsRespec,
|
|
WebGLTexture* tex, GLint level,
|
|
const webgl::DriverUnpackInfo* dui, GLint xOffset,
|
|
GLint yOffset, GLint zOffset,
|
|
const webgl::PackingInfo& pi,
|
|
GLenum* const out_error) const = 0;
|
|
};
|
|
|
|
class TexUnpackBytes final : public TexUnpackBlob {
|
|
public:
|
|
explicit TexUnpackBytes(const TexUnpackBlobDesc& desc) : TexUnpackBlob(desc) {
|
|
MOZ_ASSERT(mDesc.srcAlphaType == gfxAlphaType::NonPremult);
|
|
}
|
|
|
|
virtual bool HasData() const override {
|
|
return mDesc.pboOffset || mDesc.cpuData;
|
|
}
|
|
|
|
virtual bool Validate(const WebGLContext*,
|
|
const webgl::PackingInfo& pi) override;
|
|
virtual bool TexOrSubImage(bool isSubImage, bool needsRespec,
|
|
WebGLTexture* tex, GLint level,
|
|
const webgl::DriverUnpackInfo* dui, GLint xOffset,
|
|
GLint yOffset, GLint zOffset,
|
|
const webgl::PackingInfo& pi,
|
|
GLenum* const out_error) const override;
|
|
};
|
|
|
|
class TexUnpackImage final : public TexUnpackBlob {
|
|
public:
|
|
explicit TexUnpackImage(const TexUnpackBlobDesc& desc)
|
|
: TexUnpackBlob(desc) {}
|
|
~TexUnpackImage(); // Prevent needing to define layers::Image in the header.
|
|
|
|
virtual bool Validate(const WebGLContext*,
|
|
const webgl::PackingInfo& pi) override;
|
|
virtual bool TexOrSubImage(bool isSubImage, bool needsRespec,
|
|
WebGLTexture* tex, GLint level,
|
|
const webgl::DriverUnpackInfo* dui, GLint xOffset,
|
|
GLint yOffset, GLint zOffset,
|
|
const webgl::PackingInfo& dstPI,
|
|
GLenum* const out_error) const override;
|
|
};
|
|
|
|
class TexUnpackSurface final : public TexUnpackBlob {
|
|
public:
|
|
explicit TexUnpackSurface(const TexUnpackBlobDesc& desc)
|
|
: TexUnpackBlob(desc) {}
|
|
~TexUnpackSurface();
|
|
|
|
virtual bool Validate(const WebGLContext*,
|
|
const webgl::PackingInfo& pi) override;
|
|
virtual bool TexOrSubImage(bool isSubImage, bool needsRespec,
|
|
WebGLTexture* tex, GLint level,
|
|
const webgl::DriverUnpackInfo* dui, GLint xOffset,
|
|
GLint yOffset, GLint zOffset,
|
|
const webgl::PackingInfo& dstPI,
|
|
GLenum* const out_error) const override;
|
|
};
|
|
|
|
} // namespace webgl
|
|
} // namespace mozilla
|
|
|
|
#endif // TEX_UNPACK_BLOB_H_
|