Bug 1874684 - Part 4: Prefer const references instead of copying Instant values....
[gecko.git] / dom / canvas / TexUnpackBlob.h
blobdc850fe5d442f65e44c7c63384327f158447c88f
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"
14 #include <memory>
16 namespace mozilla {
18 class UniqueBuffer;
19 class WebGLContext;
20 class WebGLTexture;
22 namespace dom {
23 class Element;
24 class HTMLCanvasElement;
25 class HTMLVideoElement;
26 } // namespace dom
28 namespace gfx {
29 class DataSourceSurface;
30 } // namespace gfx
32 namespace layers {
33 class Image;
34 class ImageContainer;
35 } // namespace layers
37 bool IsTarget3D(TexImageTarget target);
39 namespace webgl {
41 struct PackingInfo;
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);
50 class TexUnpackBlob {
51 public:
52 const TexUnpackBlobDesc& mDesc;
53 bool mNeedsExactUpload = true;
55 static std::unique_ptr<TexUnpackBlob> Create(const TexUnpackBlobDesc&);
57 protected:
58 explicit TexUnpackBlob(const TexUnpackBlobDesc& desc) : mDesc(desc) {
59 MOZ_ASSERT_IF(!IsTarget3D(mDesc.imageTarget), mDesc.size.z == 1);
62 public:
63 virtual ~TexUnpackBlob() = default;
65 protected:
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;
74 public:
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
81 // WebGL error.
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 {
91 public:
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 {
111 public:
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 {
127 public:
128 explicit TexUnpackSurface(const TexUnpackBlobDesc& desc)
129 : TexUnpackBlob(desc) {}
130 ~TexUnpackSurface();
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;
142 } // namespace webgl
143 } // namespace mozilla
145 #endif // TEX_UNPACK_BLOB_H_