Bug 1858921 - Part 6: Remove unused default template arguments r=sfink
[gecko.git] / dom / canvas / TexUnpackBlob.h
blob8d4c472b9a5b30b828e6203ea12cf381d5907fcf
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 const webgl::PackingInfo&,
46 const TexUnpackBlobDesc&);
48 class TexUnpackBlob {
49 public:
50 const TexUnpackBlobDesc& mDesc;
51 bool mNeedsExactUpload = true;
53 static std::unique_ptr<TexUnpackBlob> Create(const TexUnpackBlobDesc&);
55 protected:
56 explicit TexUnpackBlob(const TexUnpackBlobDesc& desc) : mDesc(desc) {
57 MOZ_ASSERT_IF(!IsTarget3D(mDesc.imageTarget), mDesc.size.z == 1);
60 public:
61 virtual ~TexUnpackBlob() = default;
63 protected:
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;
72 public:
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
79 // WebGL error.
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 {
89 public:
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 {
109 public:
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 {
125 public:
126 explicit TexUnpackSurface(const TexUnpackBlobDesc& desc)
127 : TexUnpackBlob(desc) {}
128 ~TexUnpackSurface();
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;
140 } // namespace webgl
141 } // namespace mozilla
143 #endif // TEX_UNPACK_BLOB_H_