2015-11-25 07:15:29 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
namespace webgl {
|
|
|
|
|
|
|
|
struct PackingInfo;
|
|
|
|
struct DriverUnpackInfo;
|
|
|
|
|
|
|
|
class TexUnpackBlob
|
|
|
|
{
|
|
|
|
public:
|
2016-06-22 20:28:11 +03:00
|
|
|
const uint32_t mAlignment;
|
|
|
|
const uint32_t mRowLength;
|
|
|
|
const uint32_t mImageHeight;
|
|
|
|
const uint32_t mSkipPixels;
|
|
|
|
const uint32_t mSkipRows;
|
|
|
|
const uint32_t mSkipImages;
|
|
|
|
const uint32_t mWidth;
|
|
|
|
const uint32_t mHeight;
|
|
|
|
const uint32_t mDepth;
|
2016-12-14 01:51:06 +03:00
|
|
|
|
2017-04-12 12:55:23 +03:00
|
|
|
const gfxAlphaType mSrcAlphaType;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-22 06:03:16 +03:00
|
|
|
bool mNeedsExactUpload;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
protected:
|
2016-07-12 08:51:19 +03:00
|
|
|
TexUnpackBlob(const WebGLContext* webgl, TexImageTarget target, uint32_t rowLength,
|
2017-04-12 12:55:23 +03:00
|
|
|
uint32_t width, uint32_t height, uint32_t depth,
|
|
|
|
gfxAlphaType srcAlphaType);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
public:
|
2016-06-22 20:28:11 +03:00
|
|
|
virtual ~TexUnpackBlob() { }
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-12 08:51:19 +03:00
|
|
|
protected:
|
2018-07-27 07:46:33 +03:00
|
|
|
bool ConvertIfNeeded(WebGLContext* webgl,
|
2016-12-14 01:51:06 +03:00
|
|
|
const uint32_t rowLength, const uint32_t rowCount,
|
2016-07-22 06:03:16 +03:00
|
|
|
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,
|
|
|
|
|
|
|
|
const uint8_t** const out_begin,
|
2016-07-12 08:51:19 +03:00
|
|
|
UniqueBuffer* const out_anchoredBuffer) const;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-12 08:51:19 +03:00
|
|
|
public:
|
|
|
|
virtual bool HasData() const { return true; }
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
virtual bool Validate(WebGLContext* webgl, const webgl::PackingInfo& pi) = 0;
|
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,
|
2016-07-12 08:51:19 +03:00
|
|
|
WebGLTexture* tex, TexImageTarget target, 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:
|
2016-07-22 05:20:21 +03:00
|
|
|
const bool mIsClientData;
|
2016-07-22 06:03:16 +03:00
|
|
|
const uint8_t* const mPtr;
|
2016-10-21 04:03:40 +03:00
|
|
|
const size_t mAvailBytes;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-12 08:51:19 +03:00
|
|
|
TexUnpackBytes(const WebGLContext* webgl, TexImageTarget target, uint32_t width,
|
2016-10-21 04:03:40 +03:00
|
|
|
uint32_t height, uint32_t depth, bool isClientData, const uint8_t* ptr,
|
|
|
|
size_t availBytes);
|
2016-07-12 08:51:19 +03:00
|
|
|
|
2016-07-22 05:20:21 +03:00
|
|
|
virtual bool HasData() const override { return !mIsClientData || bool(mPtr); }
|
2016-06-22 20:28:11 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
virtual bool Validate(WebGLContext* webgl,
|
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,
|
2016-07-12 08:51:19 +03:00
|
|
|
WebGLTexture* tex, TexImageTarget target, 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:
|
|
|
|
const RefPtr<layers::Image> mImage;
|
|
|
|
|
2016-07-12 08:51:19 +03:00
|
|
|
TexUnpackImage(const WebGLContext* webgl, TexImageTarget target, uint32_t width,
|
|
|
|
uint32_t height, uint32_t depth, layers::Image* image,
|
2017-04-12 12:55:23 +03:00
|
|
|
gfxAlphaType srcAlphaType);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-22 09:25:41 +03:00
|
|
|
~TexUnpackImage(); // Prevent needing to define layers::Image in the header.
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
virtual bool Validate(WebGLContext* webgl,
|
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,
|
2016-07-12 08:51:19 +03:00
|
|
|
WebGLTexture* tex, TexImageTarget target, 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:
|
2016-07-12 08:51:19 +03:00
|
|
|
const RefPtr<gfx::DataSourceSurface> mSurf;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-12 08:51:19 +03:00
|
|
|
TexUnpackSurface(const WebGLContext* webgl, TexImageTarget target, uint32_t width,
|
|
|
|
uint32_t height, uint32_t depth, gfx::DataSourceSurface* surf,
|
2017-04-12 12:55:23 +03:00
|
|
|
gfxAlphaType srcAlphaType);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
virtual bool Validate(WebGLContext* webgl,
|
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,
|
2016-07-22 05:20:21 +03:00
|
|
|
WebGLTexture* tex, TexImageTarget target, 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_
|