2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-11-25 07:15:29 +03:00
|
|
|
/* 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"
|
2016-07-22 09:25:41 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-11-25 07:15:29 +03:00
|
|
|
#include "WebGLStrongTypes.h"
|
2016-07-12 08:51:19 +03:00
|
|
|
#include "WebGLTypes.h"
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2020-11-23 19:21:38 +03:00
|
|
|
#include <memory>
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
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
|
|
|
|
|
2020-07-22 01:57:01 +03:00
|
|
|
bool IsTarget3D(TexImageTarget target);
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
namespace webgl {
|
|
|
|
|
|
|
|
struct PackingInfo;
|
|
|
|
struct DriverUnpackInfo;
|
|
|
|
|
2021-01-14 04:23:06 +03:00
|
|
|
Maybe<std::string> BlitPreventReason(int32_t level, const ivec3& offset,
|
|
|
|
const webgl::PackingInfo&,
|
|
|
|
const TexUnpackBlobDesc&);
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
class TexUnpackBlob {
|
|
|
|
public:
|
2020-07-22 01:57:01 +03:00
|
|
|
const TexUnpackBlobDesc& mDesc;
|
|
|
|
bool mNeedsExactUpload = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-07-22 01:57:01 +03:00
|
|
|
static std::unique_ptr<TexUnpackBlob> Create(const TexUnpackBlobDesc&);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
protected:
|
2020-07-22 01:57:01 +03:00
|
|
|
explicit TexUnpackBlob(const TexUnpackBlobDesc& desc) : mDesc(desc) {
|
|
|
|
MOZ_ASSERT_IF(!IsTarget3D(mDesc.imageTarget), mDesc.size.z == 1);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
public:
|
2020-02-19 00:08:00 +03:00
|
|
|
virtual ~TexUnpackBlob() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
protected:
|
2020-07-22 01:57:01 +03:00
|
|
|
bool ConvertIfNeeded(const WebGLContext*, const uint32_t rowLength,
|
2016-07-22 06:03:16 +03:00
|
|
|
const uint32_t rowCount, WebGLTexelFormat srcFormat,
|
2016-12-14 01:51:06 +03:00
|
|
|
const uint8_t* const srcBegin, const ptrdiff_t srcStride,
|
|
|
|
WebGLTexelFormat dstFormat, const ptrdiff_t dstStride,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-14 01:51:06 +03:00
|
|
|
const uint8_t** const out_begin,
|
2016-07-12 08:51:19 +03:00
|
|
|
UniqueBuffer* const out_anchoredBuffer) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-12 08:51:19 +03:00
|
|
|
public:
|
|
|
|
virtual bool HasData() const { return true; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-07-22 01:57:01 +03:00
|
|
|
virtual bool Validate(const WebGLContext*, const webgl::PackingInfo& pi) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-11-16 04:52:41 +03:00
|
|
|
// 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.
|
2018-07-27 07:46:33 +03:00
|
|
|
virtual bool TexOrSubImage(bool isSubImage, bool needsRespec,
|
2020-07-22 01:57:01 +03:00
|
|
|
WebGLTexture* tex, GLint level,
|
|
|
|
const webgl::DriverUnpackInfo* dui, GLint xOffset,
|
|
|
|
GLint yOffset, GLint zOffset,
|
2017-06-15 22:29:00 +03:00
|
|
|
const webgl::PackingInfo& pi,
|
|
|
|
GLenum* const out_error) const = 0;
|
2015-11-25 07:15:29 +03:00
|
|
|
};
|
|
|
|
|
2016-07-12 08:51:19 +03:00
|
|
|
class TexUnpackBytes final : public TexUnpackBlob {
|
2015-11-25 07:15:29 +03:00
|
|
|
public:
|
2020-07-22 01:57:01 +03:00
|
|
|
explicit TexUnpackBytes(const TexUnpackBlobDesc& desc) : TexUnpackBlob(desc) {
|
|
|
|
MOZ_ASSERT(mDesc.srcAlphaType == gfxAlphaType::NonPremult);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-07-22 01:57:01 +03:00
|
|
|
virtual bool HasData() const override {
|
|
|
|
return mDesc.pboOffset || mDesc.cpuData;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-07-22 01:57:01 +03:00
|
|
|
virtual bool Validate(const WebGLContext*,
|
2016-10-21 04:03:40 +03:00
|
|
|
const webgl::PackingInfo& pi) override;
|
2018-07-27 07:46:33 +03:00
|
|
|
virtual bool TexOrSubImage(bool isSubImage, bool needsRespec,
|
2020-07-22 01:57:01 +03:00
|
|
|
WebGLTexture* tex, GLint level,
|
|
|
|
const webgl::DriverUnpackInfo* dui, GLint xOffset,
|
|
|
|
GLint yOffset, GLint zOffset,
|
2017-06-15 22:29:00 +03:00
|
|
|
const webgl::PackingInfo& pi,
|
|
|
|
GLenum* const out_error) const override;
|
2015-11-25 07:15:29 +03:00
|
|
|
};
|
|
|
|
|
2016-07-12 08:51:19 +03:00
|
|
|
class TexUnpackImage final : public TexUnpackBlob {
|
2015-11-25 07:15:29 +03:00
|
|
|
public:
|
2020-07-22 01:57:01 +03:00
|
|
|
explicit TexUnpackImage(const TexUnpackBlobDesc& desc)
|
|
|
|
: TexUnpackBlob(desc) {}
|
2016-07-22 09:25:41 +03:00
|
|
|
~TexUnpackImage(); // Prevent needing to define layers::Image in the header.
|
|
|
|
|
2020-07-22 01:57:01 +03:00
|
|
|
virtual bool Validate(const WebGLContext*,
|
2016-10-21 04:03:40 +03:00
|
|
|
const webgl::PackingInfo& pi) override;
|
2018-07-27 07:46:33 +03:00
|
|
|
virtual bool TexOrSubImage(bool isSubImage, bool needsRespec,
|
2020-07-22 01:57:01 +03:00
|
|
|
WebGLTexture* tex, GLint level,
|
|
|
|
const webgl::DriverUnpackInfo* dui, GLint xOffset,
|
|
|
|
GLint yOffset, GLint zOffset,
|
2017-06-15 22:29:00 +03:00
|
|
|
const webgl::PackingInfo& dstPI,
|
|
|
|
GLenum* const out_error) const override;
|
2015-11-25 07:15:29 +03:00
|
|
|
};
|
|
|
|
|
2016-07-12 08:51:19 +03:00
|
|
|
class TexUnpackSurface final : public TexUnpackBlob {
|
2015-11-25 07:15:29 +03:00
|
|
|
public:
|
2020-07-22 01:57:01 +03:00
|
|
|
explicit TexUnpackSurface(const TexUnpackBlobDesc& desc)
|
|
|
|
: TexUnpackBlob(desc) {}
|
|
|
|
~TexUnpackSurface();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-07-22 01:57:01 +03:00
|
|
|
virtual bool Validate(const WebGLContext*,
|
2016-10-21 04:03:40 +03:00
|
|
|
const webgl::PackingInfo& pi) override;
|
2018-07-27 07:46:33 +03:00
|
|
|
virtual bool TexOrSubImage(bool isSubImage, bool needsRespec,
|
2020-07-22 01:57:01 +03:00
|
|
|
WebGLTexture* tex, GLint level,
|
|
|
|
const webgl::DriverUnpackInfo* dui, GLint xOffset,
|
|
|
|
GLint yOffset, GLint zOffset,
|
2017-06-15 22:29:00 +03:00
|
|
|
const webgl::PackingInfo& dstPI,
|
|
|
|
GLenum* const out_error) const override;
|
2015-11-25 07:15:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace webgl
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // TEX_UNPACK_BLOB_H_
|