| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WebGLImageConversion_h | 5 #ifndef WebGLImageConversion_h |
| 6 #define WebGLImageConversion_h | 6 #define WebGLImageConversion_h |
| 7 | 7 |
| 8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
| 9 #include "platform/graphics/Image.h" | 9 #include "platform/graphics/Image.h" |
| 10 #include "third_party/khronos/GLES2/gl2.h" | 10 #include "third_party/khronos/GLES2/gl2.h" |
| 11 #include "third_party/khronos/GLES2/gl2ext.h" | 11 #include "third_party/khronos/GLES2/gl2ext.h" |
| 12 #include "third_party/khronos/GLES3/gl3.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "wtf/RefPtr.h" | 14 #include "wtf/RefPtr.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 class Image; | 17 class Image; |
| 17 class IntSize; | 18 class IntSize; |
| 18 | 19 |
| 19 // Helper functions for texture uploading and pixel readback. | 20 // Helper functions for texture uploading and pixel readback. |
| 20 class PLATFORM_EXPORT WebGLImageConversion { | 21 class PLATFORM_EXPORT WebGLImageConversion { |
| 21 public: | 22 public: |
| 22 // Attempt to enumerate all possible native image formats to | 23 // Attempt to enumerate all possible native image formats to |
| 23 // reduce the amount of temporary allocations during texture | 24 // reduce the amount of temporary allocations during texture |
| 24 // uploading. This enum must be public because it is accessed | 25 // uploading. This enum must be public because it is accessed |
| 25 // by non-member functions. | 26 // by non-member functions. |
| 27 // "_S" postfix indicates signed type. |
| 26 enum DataFormat { | 28 enum DataFormat { |
| 27 DataFormatRGBA8 = 0, | 29 DataFormatRGBA8 = 0, |
| 30 DataFormatRGBA8_S, |
| 31 DataFormatRGBA16, |
| 32 DataFormatRGBA16_S, |
| 33 DataFormatRGBA32, |
| 34 DataFormatRGBA32_S, |
| 28 DataFormatRGBA16F, | 35 DataFormatRGBA16F, |
| 29 DataFormatRGBA32F, | 36 DataFormatRGBA32F, |
| 37 DataFormatRGBA2_10_10_10, |
| 30 DataFormatRGB8, | 38 DataFormatRGB8, |
| 39 DataFormatRGB8_S, |
| 40 DataFormatRGB16, |
| 41 DataFormatRGB16_S, |
| 42 DataFormatRGB32, |
| 43 DataFormatRGB32_S, |
| 31 DataFormatRGB16F, | 44 DataFormatRGB16F, |
| 32 DataFormatRGB32F, | 45 DataFormatRGB32F, |
| 33 DataFormatBGR8, | 46 DataFormatBGR8, |
| 34 DataFormatBGRA8, | 47 DataFormatBGRA8, |
| 35 DataFormatARGB8, | 48 DataFormatARGB8, |
| 36 DataFormatABGR8, | 49 DataFormatABGR8, |
| 37 DataFormatRGBA5551, | 50 DataFormatRGBA5551, |
| 38 DataFormatRGBA4444, | 51 DataFormatRGBA4444, |
| 39 DataFormatRGB565, | 52 DataFormatRGB565, |
| 53 DataFormatRGB10F11F11F, |
| 54 DataFormatRG8, |
| 55 DataFormatRG8_S, |
| 56 DataFormatRG16, |
| 57 DataFormatRG16_S, |
| 58 DataFormatRG32, |
| 59 DataFormatRG32_S, |
| 60 DataFormatRG16F, |
| 61 DataFormatRG32F, |
| 40 DataFormatR8, | 62 DataFormatR8, |
| 63 DataFormatR8_S, |
| 64 DataFormatR16, |
| 65 DataFormatR16_S, |
| 66 DataFormatR32, |
| 67 DataFormatR32_S, |
| 41 DataFormatR16F, | 68 DataFormatR16F, |
| 42 DataFormatR32F, | 69 DataFormatR32F, |
| 43 DataFormatRA8, | 70 DataFormatRA8, |
| 44 DataFormatRA16F, | 71 DataFormatRA16F, |
| 45 DataFormatRA32F, | 72 DataFormatRA32F, |
| 46 DataFormatAR8, | 73 DataFormatAR8, |
| 47 DataFormatA8, | 74 DataFormatA8, |
| 48 DataFormatA16F, | 75 DataFormatA16F, |
| 49 DataFormatA32F, | 76 DataFormatA32F, |
| 77 DataFormatD16, |
| 78 DataFormatD32, |
| 79 DataFormatD32F, |
| 80 DataFormatDS24_8, |
| 50 DataFormatNumFormats | 81 DataFormatNumFormats |
| 51 }; | 82 }; |
| 52 | 83 |
| 53 enum ChannelBits { | 84 enum ChannelBits { |
| 54 ChannelRed = 1, | 85 ChannelRed = 1, |
| 55 ChannelGreen = 2, | 86 ChannelGreen = 2, |
| 56 ChannelBlue = 4, | 87 ChannelBlue = 4, |
| 57 ChannelAlpha = 8, | 88 ChannelAlpha = 8, |
| 58 ChannelDepth = 16, | 89 ChannelDepth = 16, |
| 59 ChannelStencil = 32, | 90 ChannelStencil = 32, |
| 91 ChannelRG = ChannelRed | ChannelGreen, |
| 60 ChannelRGB = ChannelRed | ChannelGreen | ChannelBlue, | 92 ChannelRGB = ChannelRed | ChannelGreen | ChannelBlue, |
| 61 ChannelRGBA = ChannelRGB | ChannelAlpha, | 93 ChannelRGBA = ChannelRGB | ChannelAlpha, |
| 94 ChannelDepthStencil = ChannelDepth | ChannelStencil, |
| 62 }; | 95 }; |
| 63 | 96 |
| 64 // Possible alpha operations that may need to occur during | 97 // Possible alpha operations that may need to occur during |
| 65 // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must | 98 // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must |
| 66 // be removed. | 99 // be removed. |
| 67 enum AlphaOp { | 100 enum AlphaOp { |
| 68 AlphaDoNothing = 0, | 101 AlphaDoNothing = 0, |
| 69 AlphaDoPremultiply = 1, | 102 AlphaDoPremultiply = 1, |
| 70 AlphaDoUnmultiply = 2 | 103 AlphaDoUnmultiply = 2 |
| 71 }; | 104 }; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 static GLenum computeImageSizeInBytes(GLenum format, GLenum type, GLsizei wi
dth, GLsizei height, GLint alignment, unsigned* imageSizeInBytes, unsigned* padd
ingInBytes); | 155 static GLenum computeImageSizeInBytes(GLenum format, GLenum type, GLsizei wi
dth, GLsizei height, GLint alignment, unsigned* imageSizeInBytes, unsigned* padd
ingInBytes); |
| 123 | 156 |
| 124 // Check if the format is one of the formats from the ImageData or DOM eleme
nts. | 157 // Check if the format is one of the formats from the ImageData or DOM eleme
nts. |
| 125 // The formats from ImageData is always RGBA8. | 158 // The formats from ImageData is always RGBA8. |
| 126 // The formats from DOM elements vary with Graphics ports. It can only be RG
BA8 or BGRA8. | 159 // The formats from DOM elements vary with Graphics ports. It can only be RG
BA8 or BGRA8. |
| 127 static ALWAYS_INLINE bool srcFormatComeFromDOMElementOrImageData(DataFormat
SrcFormat) | 160 static ALWAYS_INLINE bool srcFormatComeFromDOMElementOrImageData(DataFormat
SrcFormat) |
| 128 { | 161 { |
| 129 return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatRGBA8; | 162 return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatRGBA8; |
| 130 } | 163 } |
| 131 | 164 |
| 132 static unsigned getClearBitsByFormat(GLenum); | 165 // The input can be either format or internalformat. |
| 133 static unsigned getChannelBitsByFormat(GLenum); | 166 static unsigned getChannelBitsByFormat(GLenum); |
| 134 | 167 |
| 135 // The Following functions are implemented in GraphicsContext3DImagePacking.
cpp | 168 // The Following functions are implemented in GraphicsContext3DImagePacking.
cpp |
| 136 | 169 |
| 137 // Packs the contents of the given Image which is passed in |pixels| into th
e passed Vector | 170 // Packs the contents of the given Image which is passed in |pixels| into th
e passed Vector |
| 138 // according to the given format and type, and obeying the flipY and AlphaOp
flags. | 171 // according to the given format and type, and obeying the flipY and AlphaOp
flags. |
| 139 // Returns true upon success. | 172 // Returns true upon success. |
| 140 static bool packImageData(Image*, const void* pixels, GLenum format, GLenum
type, bool flipY, AlphaOp, DataFormat sourceFormat, unsigned width, unsigned hei
ght, unsigned sourceUnpackAlignment, Vector<uint8_t>& data); | 173 static bool packImageData(Image*, const void* pixels, GLenum format, GLenum
type, bool flipY, AlphaOp, DataFormat sourceFormat, unsigned width, unsigned hei
ght, unsigned sourceUnpackAlignment, Vector<uint8_t>& data); |
| 141 | 174 |
| 142 // Extracts the contents of the given ImageData into the passed Vector, | 175 // Extracts the contents of the given ImageData into the passed Vector, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 160 // A sourceUnpackAlignment of zero indicates that the source | 193 // A sourceUnpackAlignment of zero indicates that the source |
| 161 // data is tightly packed. Non-zero values may take a slow path. | 194 // data is tightly packed. Non-zero values may take a slow path. |
| 162 // Destination data will have no gaps between rows. | 195 // Destination data will have no gaps between rows. |
| 163 // Implemented in GraphicsContext3DImagePacking.cpp | 196 // Implemented in GraphicsContext3DImagePacking.cpp |
| 164 static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataForma
t, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned des
tinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool f
lipY); | 197 static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataForma
t, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned des
tinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool f
lipY); |
| 165 }; | 198 }; |
| 166 | 199 |
| 167 } // namespace blink | 200 } // namespace blink |
| 168 | 201 |
| 169 #endif // WebGLImageConversion_h | 202 #endif // WebGLImageConversion_h |
| OLD | NEW |