Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / canvas / TexUnpackBlob.h
blobfeb868cb5edce44dbc79413e29314aa038b13745
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,
49 bool sameColorSpace);
51 class TexUnpackBlob {
52 public:
53 const TexUnpackBlobDesc& mDesc;
54 bool mNeedsExactUpload = true;
56 static std::unique_ptr<TexUnpackBlob> Create(const TexUnpackBlobDesc&);
58 protected:
59 explicit TexUnpackBlob(const TexUnpackBlobDesc& desc) : mDesc(desc) {
60 MOZ_ASSERT_IF(!IsTarget3D(mDesc.imageTarget), mDesc.size.z == 1);
63 public:
64 virtual ~TexUnpackBlob() = default;
66 protected:
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;
75 public:
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
82 // WebGL error.
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 {
92 public:
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 {
112 public:
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 {
128 public:
129 explicit TexUnpackSurface(const TexUnpackBlobDesc& desc)
130 : TexUnpackBlob(desc) {}
131 ~TexUnpackSurface();
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;
143 } // namespace webgl
144 } // namespace mozilla
146 #endif // TEX_UNPACK_BLOB_H_