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 const webgl::PackingInfo
&,
46 const TexUnpackBlobDesc
&);
50 const TexUnpackBlobDesc
& mDesc
;
51 bool mNeedsExactUpload
= true;
53 static std::unique_ptr
<TexUnpackBlob
> Create(const TexUnpackBlobDesc
&);
56 explicit TexUnpackBlob(const TexUnpackBlobDesc
& desc
) : mDesc(desc
) {
57 MOZ_ASSERT_IF(!IsTarget3D(mDesc
.imageTarget
), mDesc
.size
.z
== 1);
61 virtual ~TexUnpackBlob() = default;
64 bool ConvertIfNeeded(const WebGLContext
*, const uint32_t rowLength
,
65 const uint32_t rowCount
, WebGLTexelFormat srcFormat
,
66 const uint8_t* const srcBegin
, const ptrdiff_t srcStride
,
67 WebGLTexelFormat dstFormat
, const ptrdiff_t dstStride
,
69 const uint8_t** const out_begin
,
70 UniqueBuffer
* const out_anchoredBuffer
) const;
73 virtual bool HasData() const { return true; }
75 virtual bool Validate(const WebGLContext
*, const webgl::PackingInfo
& pi
) = 0;
77 // Returns false when we've generated a WebGL error.
78 // Returns true but with a non-zero *out_error if we still need to generate a
80 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
81 WebGLTexture
* tex
, GLint level
,
82 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
83 GLint yOffset
, GLint zOffset
,
84 const webgl::PackingInfo
& pi
,
85 GLenum
* const out_error
) const = 0;
88 class TexUnpackBytes final
: public TexUnpackBlob
{
90 explicit TexUnpackBytes(const TexUnpackBlobDesc
& desc
) : TexUnpackBlob(desc
) {
91 MOZ_ASSERT(mDesc
.srcAlphaType
== gfxAlphaType::NonPremult
);
94 virtual bool HasData() const override
{
95 return mDesc
.pboOffset
|| mDesc
.cpuData
;
98 virtual bool Validate(const WebGLContext
*,
99 const webgl::PackingInfo
& pi
) override
;
100 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
101 WebGLTexture
* tex
, GLint level
,
102 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
103 GLint yOffset
, GLint zOffset
,
104 const webgl::PackingInfo
& pi
,
105 GLenum
* const out_error
) const override
;
108 class TexUnpackImage final
: public TexUnpackBlob
{
110 explicit TexUnpackImage(const TexUnpackBlobDesc
& desc
)
111 : TexUnpackBlob(desc
) {}
112 ~TexUnpackImage(); // Prevent needing to define layers::Image in the header.
114 virtual bool Validate(const WebGLContext
*,
115 const webgl::PackingInfo
& pi
) override
;
116 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
117 WebGLTexture
* tex
, GLint level
,
118 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
119 GLint yOffset
, GLint zOffset
,
120 const webgl::PackingInfo
& dstPI
,
121 GLenum
* const out_error
) const override
;
124 class TexUnpackSurface final
: public TexUnpackBlob
{
126 explicit TexUnpackSurface(const TexUnpackBlobDesc
& desc
)
127 : TexUnpackBlob(desc
) {}
130 virtual bool Validate(const WebGLContext
*,
131 const webgl::PackingInfo
& pi
) override
;
132 virtual bool TexOrSubImage(bool isSubImage
, bool needsRespec
,
133 WebGLTexture
* tex
, GLint level
,
134 const webgl::DriverUnpackInfo
* dui
, GLint xOffset
,
135 GLint yOffset
, GLint zOffset
,
136 const webgl::PackingInfo
& dstPI
,
137 GLenum
* const out_error
) const override
;
141 } // namespace mozilla
143 #endif // TEX_UNPACK_BLOB_H_