1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef TEX_UNPACK_BLOB_H_
7 #define TEX_UNPACK_BLOB_H_
9 #include "GLContextTypes.h"
10 #include "mozilla/RefPtr.h"
11 #include "WebGLStrongTypes.h"
12 #include "WebGLTypes.h"
24 class HTMLCanvasElement
;
25 class HTMLVideoElement
;
29 class DataSourceSurface
;
37 bool IsTarget3D(TexImageTarget target
);
42 struct DriverUnpackInfo
;
44 Maybe
<std::string
> BlitPreventReason(int32_t level
, const ivec3
& offset
,
45 GLenum internalFormat
,
46 const webgl::PackingInfo
&,
47 const TexUnpackBlobDesc
&,
48 OptionalRenderableFormatBits
);
52 const TexUnpackBlobDesc
& mDesc
;
53 bool mNeedsExactUpload
= true;
55 static std::unique_ptr
<TexUnpackBlob
> Create(const TexUnpackBlobDesc
&);
58 explicit TexUnpackBlob(const TexUnpackBlobDesc
& desc
) : mDesc(desc
) {
59 MOZ_ASSERT_IF(!IsTarget3D(mDesc
.imageTarget
), mDesc
.size
.z
== 1);
63 virtual ~TexUnpackBlob() = default;
66 bool ConvertIfNeeded(const WebGLContext
*, const uint32_t rowLength
,
67 const uint32_t rowCount
, WebGLTexelFormat srcFormat
,
68 const uint8_t* const srcBegin
, const ptrdiff_t srcStride
,
69 WebGLTexelFormat dstFormat
, const ptrdiff_t dstStride
,
71 const uint8_t** const out_begin
,
72 UniqueBuffer
* const out_anchoredBuffer
) const;
75 virtual bool HasData() const { return true; }
77 virtual bool Validate(const WebGLContext
*, const webgl::PackingInfo
& pi
) = 0;
79 // Returns false when we've generated a WebGL error.
80 // Returns true but with a non-zero *out_error if we still need to generate a
82 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
83 WebGLTexture
* tex
, GLint level
,
84 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
85 GLint yOffset
, GLint zOffset
,
86 const webgl::PackingInfo
& pi
,
87 GLenum
* const out_error
) const = 0;
90 class TexUnpackBytes final
: public TexUnpackBlob
{
92 explicit TexUnpackBytes(const TexUnpackBlobDesc
& desc
) : TexUnpackBlob(desc
) {
93 MOZ_ASSERT(mDesc
.srcAlphaType
== gfxAlphaType::NonPremult
);
96 virtual bool HasData() const override
{
97 return mDesc
.pboOffset
|| mDesc
.cpuData
;
100 virtual bool Validate(const WebGLContext
*,
101 const webgl::PackingInfo
& pi
) override
;
102 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
103 WebGLTexture
* tex
, GLint level
,
104 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
105 GLint yOffset
, GLint zOffset
,
106 const webgl::PackingInfo
& pi
,
107 GLenum
* const out_error
) const override
;
110 class TexUnpackImage final
: public TexUnpackBlob
{
112 explicit TexUnpackImage(const TexUnpackBlobDesc
& desc
)
113 : TexUnpackBlob(desc
) {}
114 ~TexUnpackImage(); // Prevent needing to define layers::Image in the header.
116 virtual bool Validate(const WebGLContext
*,
117 const webgl::PackingInfo
& pi
) override
;
118 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
119 WebGLTexture
* tex
, GLint level
,
120 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
121 GLint yOffset
, GLint zOffset
,
122 const webgl::PackingInfo
& dstPI
,
123 GLenum
* const out_error
) const override
;
126 class TexUnpackSurface final
: public TexUnpackBlob
{
128 explicit TexUnpackSurface(const TexUnpackBlobDesc
& desc
)
129 : TexUnpackBlob(desc
) {}
132 virtual bool Validate(const WebGLContext
*,
133 const webgl::PackingInfo
& pi
) override
;
134 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
135 WebGLTexture
* tex
, GLint level
,
136 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
137 GLint yOffset
, GLint zOffset
,
138 const webgl::PackingInfo
& dstPI
,
139 GLenum
* const out_error
) const override
;
143 } // namespace mozilla
145 #endif // TEX_UNPACK_BLOB_H_