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
,
53 const TexUnpackBlobDesc
& mDesc
;
54 bool mNeedsExactUpload
= true;
56 static std::unique_ptr
<TexUnpackBlob
> Create(const TexUnpackBlobDesc
&);
59 explicit TexUnpackBlob(const TexUnpackBlobDesc
& desc
) : mDesc(desc
) {
60 MOZ_ASSERT_IF(!IsTarget3D(mDesc
.imageTarget
), mDesc
.size
.z
== 1);
64 virtual ~TexUnpackBlob() = default;
67 bool ConvertIfNeeded(const WebGLContext
*, const uint32_t rowLength
,
68 const uint32_t rowCount
, WebGLTexelFormat srcFormat
,
69 const uint8_t* const srcBegin
, const ptrdiff_t srcStride
,
70 WebGLTexelFormat dstFormat
, const ptrdiff_t dstStride
,
72 const uint8_t** const out_begin
,
73 UniqueBuffer
* const out_anchoredBuffer
) const;
76 virtual bool HasData() const { return true; }
78 virtual bool Validate(const WebGLContext
*, const webgl::PackingInfo
& pi
) = 0;
80 // Returns false when we've generated a WebGL error.
81 // Returns true but with a non-zero *out_error if we still need to generate a
83 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
84 WebGLTexture
* tex
, GLint level
,
85 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
86 GLint yOffset
, GLint zOffset
,
87 const webgl::PackingInfo
& pi
,
88 GLenum
* const out_error
) const = 0;
91 class TexUnpackBytes final
: public TexUnpackBlob
{
93 explicit TexUnpackBytes(const TexUnpackBlobDesc
& desc
) : TexUnpackBlob(desc
) {
94 MOZ_ASSERT(mDesc
.srcAlphaType
== gfxAlphaType::NonPremult
);
97 virtual bool HasData() const override
{
98 return mDesc
.pboOffset
|| mDesc
.cpuData
;
101 virtual bool Validate(const WebGLContext
*,
102 const webgl::PackingInfo
& pi
) override
;
103 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
104 WebGLTexture
* tex
, GLint level
,
105 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
106 GLint yOffset
, GLint zOffset
,
107 const webgl::PackingInfo
& pi
,
108 GLenum
* const out_error
) const override
;
111 class TexUnpackImage final
: public TexUnpackBlob
{
113 explicit TexUnpackImage(const TexUnpackBlobDesc
& desc
)
114 : TexUnpackBlob(desc
) {}
115 ~TexUnpackImage(); // Prevent needing to define layers::Image in the header.
117 virtual bool Validate(const WebGLContext
*,
118 const webgl::PackingInfo
& pi
) override
;
119 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
120 WebGLTexture
* tex
, GLint level
,
121 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
122 GLint yOffset
, GLint zOffset
,
123 const webgl::PackingInfo
& dstPI
,
124 GLenum
* const out_error
) const override
;
127 class TexUnpackSurface final
: public TexUnpackBlob
{
129 explicit TexUnpackSurface(const TexUnpackBlobDesc
& desc
)
130 : TexUnpackBlob(desc
) {}
133 virtual bool Validate(const WebGLContext
*,
134 const webgl::PackingInfo
& pi
) override
;
135 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
136 WebGLTexture
* tex
, GLint level
,
137 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
138 GLint yOffset
, GLint zOffset
,
139 const webgl::PackingInfo
& dstPI
,
140 GLenum
* const out_error
) const override
;
144 } // namespace mozilla
146 #endif // TEX_UNPACK_BLOB_H_