TexUnpackBlob.h (5077B)
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/. */ 5 6 #ifndef TEX_UNPACK_BLOB_H_ 7 #define TEX_UNPACK_BLOB_H_ 8 9 #include <memory> 10 11 #include "GLContextTypes.h" 12 #include "WebGLStrongTypes.h" 13 #include "WebGLTypes.h" 14 15 namespace mozilla { 16 17 class UniqueBuffer; 18 class WebGLContext; 19 class WebGLTexture; 20 21 namespace dom { 22 class Element; 23 class HTMLCanvasElement; 24 class HTMLVideoElement; 25 } // namespace dom 26 27 namespace gfx { 28 class DataSourceSurface; 29 } // namespace gfx 30 31 namespace layers { 32 class Image; 33 class ImageContainer; 34 class SurfaceDescriptor; 35 } // namespace layers 36 37 bool IsTarget3D(TexImageTarget target); 38 39 namespace webgl { 40 41 struct PackingInfo; 42 struct DriverUnpackInfo; 43 44 const char* BlitPreventReason(GLenum target, int32_t level, const ivec3& offset, 45 GLenum internalFormat, const webgl::PackingInfo&, 46 const TexUnpackBlobDesc&, 47 OptionalRenderableFormatBits, bool sameColorSpace, 48 bool allowConversion = false, 49 bool allowSRGB = false, bool allow3D = false); 50 51 class TexUnpackBlob { 52 public: 53 const TexUnpackBlobDesc& mDesc; 54 bool mNeedsExactUpload = true; 55 56 static std::unique_ptr<TexUnpackBlob> Create(const TexUnpackBlobDesc&); 57 58 protected: 59 explicit TexUnpackBlob(const TexUnpackBlobDesc& desc) : mDesc(desc) { 60 MOZ_ASSERT_IF(!IsTarget3D(mDesc.imageTarget), mDesc.size.z == 1); 61 } 62 63 public: 64 virtual ~TexUnpackBlob() = default; 65 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, 71 72 const uint8_t** const out_begin, 73 UniqueBuffer* const out_anchoredBuffer) const; 74 75 public: 76 virtual bool HasData() const { return true; } 77 78 virtual bool Validate(const WebGLContext*, const webgl::PackingInfo& pi) = 0; 79 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; 89 }; 90 91 class TexUnpackBytes final : public TexUnpackBlob { 92 public: 93 explicit TexUnpackBytes(const TexUnpackBlobDesc& desc) : TexUnpackBlob(desc) { 94 MOZ_ASSERT(mDesc.srcAlphaType == gfxAlphaType::NonPremult); 95 } 96 97 virtual bool HasData() const override { 98 return mDesc.pboOffset || mDesc.cpuData; 99 } 100 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; 109 }; 110 111 class TexUnpackSurface final : public TexUnpackBlob { 112 public: 113 explicit TexUnpackSurface(const TexUnpackBlobDesc& desc) 114 : TexUnpackBlob(desc) {} 115 ~TexUnpackSurface(); 116 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; 125 bool AllowBlitSd(WebGLContext* const webgl, const GLenum target, 126 const int32_t level, const ivec3& offset, 127 const GLenum internalFormat, const webgl::PackingInfo& pi, 128 bool allowConversion, bool allowSRGB, bool allow3D, 129 bool warn) const; 130 bool BlitSd(const layers::SurfaceDescriptor& sd, bool isSubImage, 131 bool needsRespec, WebGLTexture* tex, GLint level, 132 const webgl::DriverUnpackInfo* dui, GLint xOffset, GLint yOffset, 133 GLint zOffset, const webgl::PackingInfo& dstPI, 134 GLenum* const out_error, bool allowFallback = false) const; 135 }; 136 137 } // namespace webgl 138 } // namespace mozilla 139 140 #endif // TEX_UNPACK_BLOB_H_