| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #ifndef GraphicsContext3D_h | |
| 27 #define GraphicsContext3D_h | |
| 28 | |
| 29 #include "core/platform/graphics/Extensions3D.h" | |
| 30 #include "core/platform/graphics/Image.h" | |
| 31 #include "platform/geometry/IntRect.h" | |
| 32 #include "platform/graphics/GraphicsTypes3D.h" | |
| 33 #include "platform/weborigin/KURL.h" | |
| 34 #include "third_party/skia/include/core/SkBitmap.h" | |
| 35 #include "wtf/HashMap.h" | |
| 36 #include "wtf/HashSet.h" | |
| 37 #include "wtf/ListHashSet.h" | |
| 38 #include "wtf/Noncopyable.h" | |
| 39 #include "wtf/OwnPtr.h" | |
| 40 #include "wtf/PassOwnPtr.h" | |
| 41 #include "wtf/RefCounted.h" | |
| 42 #include "wtf/text/WTFString.h" | |
| 43 | |
| 44 // FIXME: Find a better way to avoid the name confliction for NO_ERROR. | |
| 45 #if OS(WIN) | |
| 46 #undef NO_ERROR | |
| 47 #endif | |
| 48 | |
| 49 class GrContext; | |
| 50 | |
| 51 namespace blink { | |
| 52 class WebGraphicsContext3D; | |
| 53 class WebGraphicsContext3DProvider; | |
| 54 } | |
| 55 | |
| 56 namespace WebCore { | |
| 57 class DrawingBuffer; | |
| 58 class Extensions3D; | |
| 59 class GraphicsContext3DContextLostCallbackAdapter; | |
| 60 class GraphicsContext3DErrorMessageCallbackAdapter; | |
| 61 class Image; | |
| 62 class ImageBuffer; | |
| 63 class IntRect; | |
| 64 class IntSize; | |
| 65 | |
| 66 struct ActiveInfo { | |
| 67 String name; | |
| 68 GC3Denum type; | |
| 69 GC3Dint size; | |
| 70 }; | |
| 71 | |
| 72 class GraphicsContext3D : public RefCounted<GraphicsContext3D> { | |
| 73 public: | |
| 74 enum { | |
| 75 DEPTH_BUFFER_BIT = 0x00000100, | |
| 76 STENCIL_BUFFER_BIT = 0x00000400, | |
| 77 COLOR_BUFFER_BIT = 0x00004000, | |
| 78 POINTS = 0x0000, | |
| 79 LINES = 0x0001, | |
| 80 LINE_LOOP = 0x0002, | |
| 81 LINE_STRIP = 0x0003, | |
| 82 TRIANGLES = 0x0004, | |
| 83 TRIANGLE_STRIP = 0x0005, | |
| 84 TRIANGLE_FAN = 0x0006, | |
| 85 ZERO = 0, | |
| 86 ONE = 1, | |
| 87 SRC_COLOR = 0x0300, | |
| 88 ONE_MINUS_SRC_COLOR = 0x0301, | |
| 89 SRC_ALPHA = 0x0302, | |
| 90 ONE_MINUS_SRC_ALPHA = 0x0303, | |
| 91 DST_ALPHA = 0x0304, | |
| 92 ONE_MINUS_DST_ALPHA = 0x0305, | |
| 93 DST_COLOR = 0x0306, | |
| 94 ONE_MINUS_DST_COLOR = 0x0307, | |
| 95 SRC_ALPHA_SATURATE = 0x0308, | |
| 96 FUNC_ADD = 0x8006, | |
| 97 BLEND_EQUATION = 0x8009, | |
| 98 BLEND_EQUATION_RGB = 0x8009, | |
| 99 BLEND_EQUATION_ALPHA = 0x883D, | |
| 100 FUNC_SUBTRACT = 0x800A, | |
| 101 FUNC_REVERSE_SUBTRACT = 0x800B, | |
| 102 BLEND_DST_RGB = 0x80C8, | |
| 103 BLEND_SRC_RGB = 0x80C9, | |
| 104 BLEND_DST_ALPHA = 0x80CA, | |
| 105 BLEND_SRC_ALPHA = 0x80CB, | |
| 106 CONSTANT_COLOR = 0x8001, | |
| 107 ONE_MINUS_CONSTANT_COLOR = 0x8002, | |
| 108 CONSTANT_ALPHA = 0x8003, | |
| 109 ONE_MINUS_CONSTANT_ALPHA = 0x8004, | |
| 110 BLEND_COLOR = 0x8005, | |
| 111 ARRAY_BUFFER = 0x8892, | |
| 112 ELEMENT_ARRAY_BUFFER = 0x8893, | |
| 113 ARRAY_BUFFER_BINDING = 0x8894, | |
| 114 ELEMENT_ARRAY_BUFFER_BINDING = 0x8895, | |
| 115 STREAM_DRAW = 0x88E0, | |
| 116 STATIC_DRAW = 0x88E4, | |
| 117 DYNAMIC_DRAW = 0x88E8, | |
| 118 BUFFER_SIZE = 0x8764, | |
| 119 BUFFER_USAGE = 0x8765, | |
| 120 CURRENT_VERTEX_ATTRIB = 0x8626, | |
| 121 FRONT = 0x0404, | |
| 122 BACK = 0x0405, | |
| 123 FRONT_AND_BACK = 0x0408, | |
| 124 TEXTURE_2D = 0x0DE1, | |
| 125 CULL_FACE = 0x0B44, | |
| 126 BLEND = 0x0BE2, | |
| 127 DITHER = 0x0BD0, | |
| 128 STENCIL_TEST = 0x0B90, | |
| 129 DEPTH_TEST = 0x0B71, | |
| 130 SCISSOR_TEST = 0x0C11, | |
| 131 POLYGON_OFFSET_FILL = 0x8037, | |
| 132 SAMPLE_ALPHA_TO_COVERAGE = 0x809E, | |
| 133 SAMPLE_COVERAGE = 0x80A0, | |
| 134 NO_ERROR = 0, | |
| 135 INVALID_ENUM = 0x0500, | |
| 136 INVALID_VALUE = 0x0501, | |
| 137 INVALID_OPERATION = 0x0502, | |
| 138 OUT_OF_MEMORY = 0x0505, | |
| 139 CW = 0x0900, | |
| 140 CCW = 0x0901, | |
| 141 LINE_WIDTH = 0x0B21, | |
| 142 ALIASED_POINT_SIZE_RANGE = 0x846D, | |
| 143 ALIASED_LINE_WIDTH_RANGE = 0x846E, | |
| 144 CULL_FACE_MODE = 0x0B45, | |
| 145 FRONT_FACE = 0x0B46, | |
| 146 DEPTH_RANGE = 0x0B70, | |
| 147 DEPTH_WRITEMASK = 0x0B72, | |
| 148 DEPTH_CLEAR_VALUE = 0x0B73, | |
| 149 DEPTH_FUNC = 0x0B74, | |
| 150 STENCIL_CLEAR_VALUE = 0x0B91, | |
| 151 STENCIL_FUNC = 0x0B92, | |
| 152 STENCIL_FAIL = 0x0B94, | |
| 153 STENCIL_PASS_DEPTH_FAIL = 0x0B95, | |
| 154 STENCIL_PASS_DEPTH_PASS = 0x0B96, | |
| 155 STENCIL_REF = 0x0B97, | |
| 156 STENCIL_VALUE_MASK = 0x0B93, | |
| 157 STENCIL_WRITEMASK = 0x0B98, | |
| 158 STENCIL_BACK_FUNC = 0x8800, | |
| 159 STENCIL_BACK_FAIL = 0x8801, | |
| 160 STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802, | |
| 161 STENCIL_BACK_PASS_DEPTH_PASS = 0x8803, | |
| 162 STENCIL_BACK_REF = 0x8CA3, | |
| 163 STENCIL_BACK_VALUE_MASK = 0x8CA4, | |
| 164 STENCIL_BACK_WRITEMASK = 0x8CA5, | |
| 165 VIEWPORT = 0x0BA2, | |
| 166 SCISSOR_BOX = 0x0C10, | |
| 167 COLOR_CLEAR_VALUE = 0x0C22, | |
| 168 COLOR_WRITEMASK = 0x0C23, | |
| 169 UNPACK_ALIGNMENT = 0x0CF5, | |
| 170 PACK_ALIGNMENT = 0x0D05, | |
| 171 MAX_TEXTURE_SIZE = 0x0D33, | |
| 172 MAX_VIEWPORT_DIMS = 0x0D3A, | |
| 173 SUBPIXEL_BITS = 0x0D50, | |
| 174 RED_BITS = 0x0D52, | |
| 175 GREEN_BITS = 0x0D53, | |
| 176 BLUE_BITS = 0x0D54, | |
| 177 ALPHA_BITS = 0x0D55, | |
| 178 DEPTH_BITS = 0x0D56, | |
| 179 STENCIL_BITS = 0x0D57, | |
| 180 POLYGON_OFFSET_UNITS = 0x2A00, | |
| 181 POLYGON_OFFSET_FACTOR = 0x8038, | |
| 182 TEXTURE_BINDING_2D = 0x8069, | |
| 183 SAMPLE_BUFFERS = 0x80A8, | |
| 184 SAMPLES = 0x80A9, | |
| 185 SAMPLE_COVERAGE_VALUE = 0x80AA, | |
| 186 SAMPLE_COVERAGE_INVERT = 0x80AB, | |
| 187 NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2, | |
| 188 COMPRESSED_TEXTURE_FORMATS = 0x86A3, | |
| 189 DONT_CARE = 0x1100, | |
| 190 FASTEST = 0x1101, | |
| 191 NICEST = 0x1102, | |
| 192 GENERATE_MIPMAP_HINT = 0x8192, | |
| 193 BYTE = 0x1400, | |
| 194 UNSIGNED_BYTE = 0x1401, | |
| 195 SHORT = 0x1402, | |
| 196 UNSIGNED_SHORT = 0x1403, | |
| 197 INT = 0x1404, | |
| 198 UNSIGNED_INT = 0x1405, | |
| 199 FLOAT = 0x1406, | |
| 200 HALF_FLOAT_OES = 0x8D61, | |
| 201 FIXED = 0x140C, | |
| 202 DEPTH_COMPONENT = 0x1902, | |
| 203 ALPHA = 0x1906, | |
| 204 RGB = 0x1907, | |
| 205 RGBA = 0x1908, | |
| 206 BGRA = 0x80E1, | |
| 207 LUMINANCE = 0x1909, | |
| 208 LUMINANCE_ALPHA = 0x190A, | |
| 209 UNSIGNED_SHORT_4_4_4_4 = 0x8033, | |
| 210 UNSIGNED_SHORT_5_5_5_1 = 0x8034, | |
| 211 UNSIGNED_SHORT_5_6_5 = 0x8363, | |
| 212 FRAGMENT_SHADER = 0x8B30, | |
| 213 VERTEX_SHADER = 0x8B31, | |
| 214 MAX_VERTEX_ATTRIBS = 0x8869, | |
| 215 MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB, | |
| 216 MAX_VARYING_VECTORS = 0x8DFC, | |
| 217 MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D, | |
| 218 MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C, | |
| 219 MAX_TEXTURE_IMAGE_UNITS = 0x8872, | |
| 220 MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD, | |
| 221 SHADER_TYPE = 0x8B4F, | |
| 222 DELETE_STATUS = 0x8B80, | |
| 223 LINK_STATUS = 0x8B82, | |
| 224 VALIDATE_STATUS = 0x8B83, | |
| 225 ATTACHED_SHADERS = 0x8B85, | |
| 226 ACTIVE_UNIFORMS = 0x8B86, | |
| 227 ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87, | |
| 228 ACTIVE_ATTRIBUTES = 0x8B89, | |
| 229 ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A, | |
| 230 SHADING_LANGUAGE_VERSION = 0x8B8C, | |
| 231 CURRENT_PROGRAM = 0x8B8D, | |
| 232 NEVER = 0x0200, | |
| 233 LESS = 0x0201, | |
| 234 EQUAL = 0x0202, | |
| 235 LEQUAL = 0x0203, | |
| 236 GREATER = 0x0204, | |
| 237 NOTEQUAL = 0x0205, | |
| 238 GEQUAL = 0x0206, | |
| 239 ALWAYS = 0x0207, | |
| 240 KEEP = 0x1E00, | |
| 241 REPLACE = 0x1E01, | |
| 242 INCR = 0x1E02, | |
| 243 DECR = 0x1E03, | |
| 244 INVERT = 0x150A, | |
| 245 INCR_WRAP = 0x8507, | |
| 246 DECR_WRAP = 0x8508, | |
| 247 VENDOR = 0x1F00, | |
| 248 RENDERER = 0x1F01, | |
| 249 VERSION = 0x1F02, | |
| 250 EXTENSIONS = 0x1F03, | |
| 251 NEAREST = 0x2600, | |
| 252 LINEAR = 0x2601, | |
| 253 NEAREST_MIPMAP_NEAREST = 0x2700, | |
| 254 LINEAR_MIPMAP_NEAREST = 0x2701, | |
| 255 NEAREST_MIPMAP_LINEAR = 0x2702, | |
| 256 LINEAR_MIPMAP_LINEAR = 0x2703, | |
| 257 TEXTURE_MAG_FILTER = 0x2800, | |
| 258 TEXTURE_MIN_FILTER = 0x2801, | |
| 259 TEXTURE_WRAP_S = 0x2802, | |
| 260 TEXTURE_WRAP_T = 0x2803, | |
| 261 TEXTURE = 0x1702, | |
| 262 TEXTURE_CUBE_MAP = 0x8513, | |
| 263 TEXTURE_BINDING_CUBE_MAP = 0x8514, | |
| 264 TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515, | |
| 265 TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516, | |
| 266 TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517, | |
| 267 TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518, | |
| 268 TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519, | |
| 269 TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A, | |
| 270 MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C, | |
| 271 TEXTURE0 = 0x84C0, | |
| 272 TEXTURE1 = 0x84C1, | |
| 273 TEXTURE2 = 0x84C2, | |
| 274 TEXTURE3 = 0x84C3, | |
| 275 TEXTURE4 = 0x84C4, | |
| 276 TEXTURE5 = 0x84C5, | |
| 277 TEXTURE6 = 0x84C6, | |
| 278 TEXTURE7 = 0x84C7, | |
| 279 TEXTURE8 = 0x84C8, | |
| 280 TEXTURE9 = 0x84C9, | |
| 281 TEXTURE10 = 0x84CA, | |
| 282 TEXTURE11 = 0x84CB, | |
| 283 TEXTURE12 = 0x84CC, | |
| 284 TEXTURE13 = 0x84CD, | |
| 285 TEXTURE14 = 0x84CE, | |
| 286 TEXTURE15 = 0x84CF, | |
| 287 TEXTURE16 = 0x84D0, | |
| 288 TEXTURE17 = 0x84D1, | |
| 289 TEXTURE18 = 0x84D2, | |
| 290 TEXTURE19 = 0x84D3, | |
| 291 TEXTURE20 = 0x84D4, | |
| 292 TEXTURE21 = 0x84D5, | |
| 293 TEXTURE22 = 0x84D6, | |
| 294 TEXTURE23 = 0x84D7, | |
| 295 TEXTURE24 = 0x84D8, | |
| 296 TEXTURE25 = 0x84D9, | |
| 297 TEXTURE26 = 0x84DA, | |
| 298 TEXTURE27 = 0x84DB, | |
| 299 TEXTURE28 = 0x84DC, | |
| 300 TEXTURE29 = 0x84DD, | |
| 301 TEXTURE30 = 0x84DE, | |
| 302 TEXTURE31 = 0x84DF, | |
| 303 ACTIVE_TEXTURE = 0x84E0, | |
| 304 REPEAT = 0x2901, | |
| 305 CLAMP_TO_EDGE = 0x812F, | |
| 306 MIRRORED_REPEAT = 0x8370, | |
| 307 FLOAT_VEC2 = 0x8B50, | |
| 308 FLOAT_VEC3 = 0x8B51, | |
| 309 FLOAT_VEC4 = 0x8B52, | |
| 310 INT_VEC2 = 0x8B53, | |
| 311 INT_VEC3 = 0x8B54, | |
| 312 INT_VEC4 = 0x8B55, | |
| 313 BOOL = 0x8B56, | |
| 314 BOOL_VEC2 = 0x8B57, | |
| 315 BOOL_VEC3 = 0x8B58, | |
| 316 BOOL_VEC4 = 0x8B59, | |
| 317 FLOAT_MAT2 = 0x8B5A, | |
| 318 FLOAT_MAT3 = 0x8B5B, | |
| 319 FLOAT_MAT4 = 0x8B5C, | |
| 320 SAMPLER_2D = 0x8B5E, | |
| 321 SAMPLER_CUBE = 0x8B60, | |
| 322 VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622, | |
| 323 VERTEX_ATTRIB_ARRAY_SIZE = 0x8623, | |
| 324 VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624, | |
| 325 VERTEX_ATTRIB_ARRAY_TYPE = 0x8625, | |
| 326 VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A, | |
| 327 VERTEX_ATTRIB_ARRAY_POINTER = 0x8645, | |
| 328 VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F, | |
| 329 COMPILE_STATUS = 0x8B81, | |
| 330 INFO_LOG_LENGTH = 0x8B84, | |
| 331 SHADER_SOURCE_LENGTH = 0x8B88, | |
| 332 SHADER_COMPILER = 0x8DFA, | |
| 333 SHADER_BINARY_FORMATS = 0x8DF8, | |
| 334 NUM_SHADER_BINARY_FORMATS = 0x8DF9, | |
| 335 LOW_FLOAT = 0x8DF0, | |
| 336 MEDIUM_FLOAT = 0x8DF1, | |
| 337 HIGH_FLOAT = 0x8DF2, | |
| 338 LOW_INT = 0x8DF3, | |
| 339 MEDIUM_INT = 0x8DF4, | |
| 340 HIGH_INT = 0x8DF5, | |
| 341 FRAMEBUFFER = 0x8D40, | |
| 342 RENDERBUFFER = 0x8D41, | |
| 343 RGBA4 = 0x8056, | |
| 344 RGB5_A1 = 0x8057, | |
| 345 RGB565 = 0x8D62, | |
| 346 DEPTH_COMPONENT16 = 0x81A5, | |
| 347 STENCIL_INDEX = 0x1901, | |
| 348 STENCIL_INDEX8 = 0x8D48, | |
| 349 DEPTH_STENCIL = 0x84F9, | |
| 350 UNSIGNED_INT_24_8 = 0x84FA, | |
| 351 DEPTH24_STENCIL8 = 0x88F0, | |
| 352 RENDERBUFFER_WIDTH = 0x8D42, | |
| 353 RENDERBUFFER_HEIGHT = 0x8D43, | |
| 354 RENDERBUFFER_INTERNAL_FORMAT = 0x8D44, | |
| 355 RENDERBUFFER_RED_SIZE = 0x8D50, | |
| 356 RENDERBUFFER_GREEN_SIZE = 0x8D51, | |
| 357 RENDERBUFFER_BLUE_SIZE = 0x8D52, | |
| 358 RENDERBUFFER_ALPHA_SIZE = 0x8D53, | |
| 359 RENDERBUFFER_DEPTH_SIZE = 0x8D54, | |
| 360 RENDERBUFFER_STENCIL_SIZE = 0x8D55, | |
| 361 FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0, | |
| 362 FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1, | |
| 363 FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2, | |
| 364 FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3, | |
| 365 COLOR_ATTACHMENT0 = 0x8CE0, | |
| 366 DEPTH_ATTACHMENT = 0x8D00, | |
| 367 STENCIL_ATTACHMENT = 0x8D20, | |
| 368 DEPTH_STENCIL_ATTACHMENT = 0x821A, | |
| 369 NONE = 0, | |
| 370 FRAMEBUFFER_COMPLETE = 0x8CD5, | |
| 371 FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6, | |
| 372 FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7, | |
| 373 FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9, | |
| 374 FRAMEBUFFER_UNSUPPORTED = 0x8CDD, | |
| 375 FRAMEBUFFER_BINDING = 0x8CA6, | |
| 376 RENDERBUFFER_BINDING = 0x8CA7, | |
| 377 MAX_RENDERBUFFER_SIZE = 0x84E8, | |
| 378 INVALID_FRAMEBUFFER_OPERATION = 0x0506, | |
| 379 | |
| 380 // WebGL-specific enums | |
| 381 UNPACK_FLIP_Y_WEBGL = 0x9240, | |
| 382 UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241, | |
| 383 CONTEXT_LOST_WEBGL = 0x9242, | |
| 384 UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243, | |
| 385 BROWSER_DEFAULT_WEBGL = 0x9244 | |
| 386 }; | |
| 387 | |
| 388 // Context creation attributes. | |
| 389 struct Attributes { | |
| 390 Attributes() | |
| 391 : alpha(true) | |
| 392 , depth(true) | |
| 393 , stencil(false) | |
| 394 , antialias(true) | |
| 395 , premultipliedAlpha(true) | |
| 396 , preserveDrawingBuffer(false) | |
| 397 , noExtensions(false) | |
| 398 , shareResources(true) | |
| 399 , preferDiscreteGPU(false) | |
| 400 , failIfMajorPerformanceCaveat(false) | |
| 401 { | |
| 402 } | |
| 403 | |
| 404 bool alpha; | |
| 405 bool depth; | |
| 406 bool stencil; | |
| 407 bool antialias; | |
| 408 bool premultipliedAlpha; | |
| 409 bool preserveDrawingBuffer; | |
| 410 bool noExtensions; | |
| 411 bool shareResources; | |
| 412 bool preferDiscreteGPU; | |
| 413 bool failIfMajorPerformanceCaveat; | |
| 414 KURL topDocumentURL; | |
| 415 }; | |
| 416 | |
| 417 class ContextLostCallback { | |
| 418 public: | |
| 419 virtual void onContextLost() = 0; | |
| 420 virtual ~ContextLostCallback() {} | |
| 421 }; | |
| 422 | |
| 423 class ErrorMessageCallback { | |
| 424 public: | |
| 425 virtual void onErrorMessage(const String& message, GC3Dint id) = 0; | |
| 426 virtual ~ErrorMessageCallback() { } | |
| 427 }; | |
| 428 | |
| 429 void setContextLostCallback(PassOwnPtr<ContextLostCallback>); | |
| 430 void setErrorMessageCallback(PassOwnPtr<ErrorMessageCallback>); | |
| 431 | |
| 432 static PassRefPtr<GraphicsContext3D> create(Attributes); | |
| 433 | |
| 434 // Callers must make the context current before using it AND check that the
context was created successfully | |
| 435 // via ContextLost before using the context in any way. Once made current on
a thread, the context cannot | |
| 436 // be used on any other thread. | |
| 437 static PassRefPtr<GraphicsContext3D> createGraphicsContextFromWebContext(Pas
sOwnPtr<blink::WebGraphicsContext3D>, bool preserveDrawingBuffer = false); | |
| 438 static PassRefPtr<GraphicsContext3D> createGraphicsContextFromProvider(PassO
wnPtr<blink::WebGraphicsContext3DProvider>, bool preserveDrawingBuffer = false); | |
| 439 | |
| 440 ~GraphicsContext3D(); | |
| 441 | |
| 442 GrContext* grContext(); | |
| 443 blink::WebGraphicsContext3D* webContext() const { return m_impl; } | |
| 444 | |
| 445 bool makeContextCurrent(); | |
| 446 | |
| 447 uint32_t lastFlushID(); | |
| 448 | |
| 449 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0. | |
| 450 // Return true if no GL error is synthesized. | |
| 451 // By default, alignment is 4, the OpenGL default setting. | |
| 452 bool texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum interna
lformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3
Denum type, GC3Dint alignment = 4); | |
| 453 | |
| 454 //---------------------------------------------------------------------- | |
| 455 // Helpers for texture uploading and pixel readback. | |
| 456 // | |
| 457 | |
| 458 // Computes the components per pixel and bytes per component | |
| 459 // for the given format and type combination. Returns false if | |
| 460 // either was an invalid enum. | |
| 461 static bool computeFormatAndTypeParameters(GC3Denum format, | |
| 462 GC3Denum type, | |
| 463 unsigned int* componentsPerPixel, | |
| 464 unsigned int* bytesPerComponent); | |
| 465 | |
| 466 // Computes the image size in bytes. If paddingInBytes is not null, padding | |
| 467 // is also calculated in return. Returns NO_ERROR if succeed, otherwise | |
| 468 // return the suggested GL error indicating the cause of the failure: | |
| 469 // INVALID_VALUE if width/height is negative or overflow happens. | |
| 470 // INVALID_ENUM if format/type is illegal. | |
| 471 static GC3Denum computeImageSizeInBytes(GC3Denum format, | |
| 472 GC3Denum type, | |
| 473 GC3Dsizei width, | |
| 474 GC3Dsizei height, | |
| 475 GC3Dint alignment, | |
| 476 unsigned int* imageSizeInBytes, | |
| 477 unsigned int* paddingInBytes); | |
| 478 | |
| 479 // Attempt to enumerate all possible native image formats to | |
| 480 // reduce the amount of temporary allocations during texture | |
| 481 // uploading. This enum must be public because it is accessed | |
| 482 // by non-member functions. | |
| 483 enum DataFormat { | |
| 484 DataFormatRGBA8 = 0, | |
| 485 DataFormatRGBA16F, | |
| 486 DataFormatRGBA32F, | |
| 487 DataFormatRGB8, | |
| 488 DataFormatRGB16F, | |
| 489 DataFormatRGB32F, | |
| 490 DataFormatBGR8, | |
| 491 DataFormatBGRA8, | |
| 492 DataFormatARGB8, | |
| 493 DataFormatABGR8, | |
| 494 DataFormatRGBA5551, | |
| 495 DataFormatRGBA4444, | |
| 496 DataFormatRGB565, | |
| 497 DataFormatR8, | |
| 498 DataFormatR16F, | |
| 499 DataFormatR32F, | |
| 500 DataFormatRA8, | |
| 501 DataFormatRA16F, | |
| 502 DataFormatRA32F, | |
| 503 DataFormatAR8, | |
| 504 DataFormatA8, | |
| 505 DataFormatA16F, | |
| 506 DataFormatA32F, | |
| 507 DataFormatNumFormats | |
| 508 }; | |
| 509 | |
| 510 // Check if the format is one of the formats from the ImageData or DOM eleme
nts. | |
| 511 // The formats from ImageData is always RGBA8. | |
| 512 // The formats from DOM elements vary with Graphics ports. It can only be RG
BA8 or BGRA8. | |
| 513 static ALWAYS_INLINE bool srcFormatComeFromDOMElementOrImageData(DataFormat
SrcFormat) | |
| 514 { | |
| 515 return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatRGBA8; | |
| 516 } | |
| 517 | |
| 518 //---------------------------------------------------------------------- | |
| 519 // Entry points for WebGL. | |
| 520 // | |
| 521 | |
| 522 void activeTexture(GC3Denum texture); | |
| 523 void attachShader(Platform3DObject program, Platform3DObject shader); | |
| 524 void bindAttribLocation(Platform3DObject, GC3Duint index, const String& name
); | |
| 525 void bindBuffer(GC3Denum target, Platform3DObject); | |
| 526 void bindFramebuffer(GC3Denum target, Platform3DObject); | |
| 527 void bindRenderbuffer(GC3Denum target, Platform3DObject); | |
| 528 void bindTexture(GC3Denum target, Platform3DObject); | |
| 529 void blendColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclamp
f alpha); | |
| 530 void blendEquation(GC3Denum mode); | |
| 531 void blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha); | |
| 532 void blendFunc(GC3Denum sfactor, GC3Denum dfactor); | |
| 533 void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha,
GC3Denum dstAlpha); | |
| 534 | |
| 535 void bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage); | |
| 536 void bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Den
um usage); | |
| 537 void bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, co
nst void* data); | |
| 538 | |
| 539 GC3Denum checkFramebufferStatus(GC3Denum target); | |
| 540 void clear(GC3Dbitfield mask); | |
| 541 void clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclamp
f alpha); | |
| 542 void clearDepth(GC3Dclampf depth); | |
| 543 void clearStencil(GC3Dint s); | |
| 544 void colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboo
lean alpha); | |
| 545 void compileShader(Platform3DObject); | |
| 546 | |
| 547 void compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalf
ormat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Dsizei imageSize, c
onst void* data); | |
| 548 void compressedTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset
, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Dsizei
imageSize, const void* data); | |
| 549 void copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,
GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border); | |
| 550 void copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3D
int yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); | |
| 551 void cullFace(GC3Denum mode); | |
| 552 void depthFunc(GC3Denum func); | |
| 553 void depthMask(GC3Dboolean flag); | |
| 554 void depthRange(GC3Dclampf zNear, GC3Dclampf zFar); | |
| 555 void detachShader(Platform3DObject, Platform3DObject); | |
| 556 void disable(GC3Denum cap); | |
| 557 void disableVertexAttribArray(GC3Duint index); | |
| 558 void drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count); | |
| 559 void drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr
offset); | |
| 560 | |
| 561 void enable(GC3Denum cap); | |
| 562 void enableVertexAttribArray(GC3Duint index); | |
| 563 void finish(); | |
| 564 void flush(); | |
| 565 void framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum
renderbuffertarget, Platform3DObject); | |
| 566 void framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum tex
target, Platform3DObject, GC3Dint level); | |
| 567 void frontFace(GC3Denum mode); | |
| 568 void generateMipmap(GC3Denum target); | |
| 569 | |
| 570 bool getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo&); | |
| 571 bool getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo&)
; | |
| 572 void getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsi
zei* count, Platform3DObject* shaders); | |
| 573 GC3Dint getAttribLocation(Platform3DObject, const String& name); | |
| 574 void getBooleanv(GC3Denum pname, GC3Dboolean* value); | |
| 575 void getBufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value); | |
| 576 Attributes getContextAttributes(); | |
| 577 GC3Denum getError(); | |
| 578 void getFloatv(GC3Denum pname, GC3Dfloat* value); | |
| 579 void getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachmen
t, GC3Denum pname, GC3Dint* value); | |
| 580 void getIntegerv(GC3Denum pname, GC3Dint* value); | |
| 581 void getProgramiv(Platform3DObject program, GC3Denum pname, GC3Dint* value); | |
| 582 String getProgramInfoLog(Platform3DObject); | |
| 583 void getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* va
lue); | |
| 584 void getShaderiv(Platform3DObject, GC3Denum pname, GC3Dint* value); | |
| 585 String getShaderInfoLog(Platform3DObject); | |
| 586 void getShaderPrecisionFormat(GC3Denum shaderType, GC3Denum precisionType, G
C3Dint* range, GC3Dint* precision); | |
| 587 String getShaderSource(Platform3DObject); | |
| 588 String getString(GC3Denum name); | |
| 589 void getTexParameterfv(GC3Denum target, GC3Denum pname, GC3Dfloat* value); | |
| 590 void getTexParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value); | |
| 591 void getUniformfv(Platform3DObject program, GC3Dint location, GC3Dfloat* val
ue); | |
| 592 void getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value
); | |
| 593 GC3Dint getUniformLocation(Platform3DObject, const String& name); | |
| 594 void getVertexAttribfv(GC3Duint index, GC3Denum pname, GC3Dfloat* value); | |
| 595 void getVertexAttribiv(GC3Duint index, GC3Denum pname, GC3Dint* value); | |
| 596 GC3Dsizeiptr getVertexAttribOffset(GC3Duint index, GC3Denum pname); | |
| 597 | |
| 598 void hint(GC3Denum target, GC3Denum mode); | |
| 599 GC3Dboolean isBuffer(Platform3DObject); | |
| 600 GC3Dboolean isEnabled(GC3Denum cap); | |
| 601 GC3Dboolean isFramebuffer(Platform3DObject); | |
| 602 GC3Dboolean isProgram(Platform3DObject); | |
| 603 GC3Dboolean isRenderbuffer(Platform3DObject); | |
| 604 GC3Dboolean isShader(Platform3DObject); | |
| 605 GC3Dboolean isTexture(Platform3DObject); | |
| 606 void lineWidth(GC3Dfloat); | |
| 607 void linkProgram(Platform3DObject); | |
| 608 void pixelStorei(GC3Denum pname, GC3Dint param); | |
| 609 void polygonOffset(GC3Dfloat factor, GC3Dfloat units); | |
| 610 | |
| 611 void readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3
Denum format, GC3Denum type, void* data); | |
| 612 | |
| 613 void releaseShaderCompiler(); | |
| 614 | |
| 615 void renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei
width, GC3Dsizei height); | |
| 616 void sampleCoverage(GC3Dclampf value, GC3Dboolean invert); | |
| 617 void scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); | |
| 618 void shaderSource(Platform3DObject, const String& string); | |
| 619 void stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask); | |
| 620 void stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint
mask); | |
| 621 void stencilMask(GC3Duint mask); | |
| 622 void stencilMaskSeparate(GC3Denum face, GC3Duint mask); | |
| 623 void stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denum zpass); | |
| 624 void stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zfail, GC3Denu
m zpass); | |
| 625 | |
| 626 void texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3
Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type,
const void* pixels); | |
| 627 void texParameterf(GC3Denum target, GC3Denum pname, GC3Dfloat param); | |
| 628 void texParameteri(GC3Denum target, GC3Denum pname, GC3Dint param); | |
| 629 void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint
yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, cons
t void* pixels); | |
| 630 | |
| 631 void uniform1f(GC3Dint location, GC3Dfloat x); | |
| 632 void uniform1fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v); | |
| 633 void uniform1i(GC3Dint location, GC3Dint x); | |
| 634 void uniform1iv(GC3Dint location, GC3Dsizei, GC3Dint* v); | |
| 635 void uniform2f(GC3Dint location, GC3Dfloat x, GC3Dfloat y); | |
| 636 void uniform2fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v); | |
| 637 void uniform2i(GC3Dint location, GC3Dint x, GC3Dint y); | |
| 638 void uniform2iv(GC3Dint location, GC3Dsizei, GC3Dint* v); | |
| 639 void uniform3f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z); | |
| 640 void uniform3fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v); | |
| 641 void uniform3i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z); | |
| 642 void uniform3iv(GC3Dint location, GC3Dsizei, GC3Dint* v); | |
| 643 void uniform4f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3D
float w); | |
| 644 void uniform4fv(GC3Dint location, GC3Dsizei, GC3Dfloat* v); | |
| 645 void uniform4i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w)
; | |
| 646 void uniform4iv(GC3Dint location, GC3Dsizei, GC3Dint* v); | |
| 647 void uniformMatrix2fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC
3Dfloat* value); | |
| 648 void uniformMatrix3fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC
3Dfloat* value); | |
| 649 void uniformMatrix4fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, GC
3Dfloat* value); | |
| 650 | |
| 651 void useProgram(Platform3DObject); | |
| 652 void validateProgram(Platform3DObject); | |
| 653 | |
| 654 void vertexAttrib1f(GC3Duint index, GC3Dfloat x); | |
| 655 void vertexAttrib1fv(GC3Duint index, GC3Dfloat* values); | |
| 656 void vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y); | |
| 657 void vertexAttrib2fv(GC3Duint index, GC3Dfloat* values); | |
| 658 void vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z); | |
| 659 void vertexAttrib3fv(GC3Duint index, GC3Dfloat* values); | |
| 660 void vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, G
C3Dfloat w); | |
| 661 void vertexAttrib4fv(GC3Duint index, GC3Dfloat* values); | |
| 662 void vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dbo
olean normalized, | |
| 663 GC3Dsizei stride, GC3Dintptr offset); | |
| 664 | |
| 665 void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); | |
| 666 | |
| 667 void markContextChanged(); | |
| 668 void markLayerComposited(); | |
| 669 bool layerComposited() const; | |
| 670 | |
| 671 void paintRenderingResultsToCanvas(ImageBuffer*, DrawingBuffer*); | |
| 672 PassRefPtr<Uint8ClampedArray> paintRenderingResultsToImageData(DrawingBuffer
*, int&, int&); | |
| 673 | |
| 674 // Support for buffer creation and deletion | |
| 675 Platform3DObject createBuffer(); | |
| 676 Platform3DObject createFramebuffer(); | |
| 677 Platform3DObject createProgram(); | |
| 678 Platform3DObject createRenderbuffer(); | |
| 679 Platform3DObject createShader(GC3Denum); | |
| 680 Platform3DObject createTexture(); | |
| 681 | |
| 682 void deleteBuffer(Platform3DObject); | |
| 683 void deleteFramebuffer(Platform3DObject); | |
| 684 void deleteProgram(Platform3DObject); | |
| 685 void deleteRenderbuffer(Platform3DObject); | |
| 686 void deleteShader(Platform3DObject); | |
| 687 void deleteTexture(Platform3DObject); | |
| 688 | |
| 689 // Synthesizes an OpenGL error which will be returned from a | |
| 690 // later call to getError. This is used to emulate OpenGL ES | |
| 691 // 2.0 behavior on the desktop and to enforce additional error | |
| 692 // checking mandated by WebGL. | |
| 693 // | |
| 694 // Per the behavior of glGetError, this stores at most one | |
| 695 // instance of any given error, and returns them from calls to | |
| 696 // getError in the order they were added. | |
| 697 void synthesizeGLError(GC3Denum error); | |
| 698 | |
| 699 // Support for extensions. Returns a non-null object, though not | |
| 700 // all methods it contains may necessarily be supported on the | |
| 701 // current hardware. Must call Extensions3D::supports() to | |
| 702 // determine this. | |
| 703 Extensions3D* extensions(); | |
| 704 | |
| 705 static unsigned getClearBitsByFormat(GC3Denum); | |
| 706 | |
| 707 enum ChannelBits { | |
| 708 ChannelRed = 1, | |
| 709 ChannelGreen = 2, | |
| 710 ChannelBlue = 4, | |
| 711 ChannelAlpha = 8, | |
| 712 ChannelDepth = 16, | |
| 713 ChannelStencil = 32, | |
| 714 ChannelRGB = ChannelRed | ChannelGreen | ChannelBlue, | |
| 715 ChannelRGBA = ChannelRGB | ChannelAlpha, | |
| 716 }; | |
| 717 | |
| 718 static unsigned getChannelBitsByFormat(GC3Denum); | |
| 719 | |
| 720 // Possible alpha operations that may need to occur during | |
| 721 // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must | |
| 722 // be removed. | |
| 723 enum AlphaOp { | |
| 724 AlphaDoNothing = 0, | |
| 725 AlphaDoPremultiply = 1, | |
| 726 AlphaDoUnmultiply = 2 | |
| 727 }; | |
| 728 | |
| 729 enum ImageHtmlDomSource { | |
| 730 HtmlDomImage = 0, | |
| 731 HtmlDomCanvas = 1, | |
| 732 HtmlDomVideo = 2, | |
| 733 HtmlDomNone = 3 | |
| 734 }; | |
| 735 | |
| 736 class ImageExtractor { | |
| 737 public: | |
| 738 ImageExtractor(Image*, ImageHtmlDomSource, bool premultiplyAlpha, bool i
gnoreGammaAndColorProfile); | |
| 739 | |
| 740 ~ImageExtractor(); | |
| 741 | |
| 742 bool extractSucceeded() { return m_extractSucceeded; } | |
| 743 const void* imagePixelData() { return m_imagePixelData; } | |
| 744 unsigned imageWidth() { return m_imageWidth; } | |
| 745 unsigned imageHeight() { return m_imageHeight; } | |
| 746 DataFormat imageSourceFormat() { return m_imageSourceFormat; } | |
| 747 AlphaOp imageAlphaOp() { return m_alphaOp; } | |
| 748 unsigned imageSourceUnpackAlignment() { return m_imageSourceUnpackAlignm
ent; } | |
| 749 ImageHtmlDomSource imageHtmlDomSource() { return m_imageHtmlDomSource; } | |
| 750 private: | |
| 751 // Extract the image and keeps track of its status, such as width, heigh
t, Source Alignment, format and AlphaOp etc. | |
| 752 // This needs to lock the resources or relevant data if needed and retur
n true upon success | |
| 753 bool extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile
); | |
| 754 | |
| 755 RefPtr<NativeImageSkia> m_nativeImage; | |
| 756 RefPtr<NativeImageSkia> m_skiaImage; | |
| 757 Image* m_image; | |
| 758 ImageHtmlDomSource m_imageHtmlDomSource; | |
| 759 bool m_extractSucceeded; | |
| 760 const void* m_imagePixelData; | |
| 761 unsigned m_imageWidth; | |
| 762 unsigned m_imageHeight; | |
| 763 DataFormat m_imageSourceFormat; | |
| 764 AlphaOp m_alphaOp; | |
| 765 unsigned m_imageSourceUnpackAlignment; | |
| 766 }; | |
| 767 | |
| 768 // The Following functions are implemented in GraphicsContext3DImagePacking.
cpp | |
| 769 | |
| 770 // Packs the contents of the given Image which is passed in |pixels| into th
e passed Vector | |
| 771 // according to the given format and type, and obeying the flipY and AlphaOp
flags. | |
| 772 // Returns true upon success. | |
| 773 static bool packImageData(Image*, const void* pixels, GC3Denum format, GC3De
num type, bool flipY, AlphaOp, DataFormat sourceFormat, unsigned width, unsigned
height, unsigned sourceUnpackAlignment, Vector<uint8_t>& data); | |
| 774 | |
| 775 // Extracts the contents of the given ImageData into the passed Vector, | |
| 776 // packing the pixel data according to the given format and type, | |
| 777 // and obeying the flipY and premultiplyAlpha flags. Returns true | |
| 778 // upon success. | |
| 779 static bool extractImageData(const uint8_t*, const IntSize&, GC3Denum format
, GC3Denum type, bool flipY, bool premultiplyAlpha, Vector<uint8_t>& data); | |
| 780 | |
| 781 // Helper function which extracts the user-supplied texture | |
| 782 // data, applying the flipY and premultiplyAlpha parameters. | |
| 783 // If the data is not tightly packed according to the passed | |
| 784 // unpackAlignment, the output data will be tightly packed. | |
| 785 // Returns true if successful, false if any error occurred. | |
| 786 static bool extractTextureData(unsigned width, unsigned height, GC3Denum for
mat, GC3Denum type, unsigned unpackAlignment, bool flipY, bool premultiplyAlpha,
const void* pixels, Vector<uint8_t>& data); | |
| 787 | |
| 788 // End GraphicsContext3DImagePacking.cpp functions | |
| 789 | |
| 790 // This is the order of bytes to use when doing a readback. | |
| 791 enum ReadbackOrder { | |
| 792 ReadbackRGBA, | |
| 793 ReadbackSkia | |
| 794 }; | |
| 795 | |
| 796 // Helper function which does a readback from the currently-bound | |
| 797 // framebuffer into a buffer of a certain size with 4-byte pixels. | |
| 798 void readBackFramebuffer(unsigned char* pixels, int width, int height, Readb
ackOrder, AlphaOp); | |
| 799 | |
| 800 private: | |
| 801 friend class Extensions3D; | |
| 802 | |
| 803 GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3D>, bool preserveDraw
ingBuffer); | |
| 804 GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3DProvider>, bool pres
erveDrawingBuffer); | |
| 805 | |
| 806 // Helper for packImageData/extractImageData/extractTextureData which implem
ent packing of pixel | |
| 807 // data into the specified OpenGL destination format and type. | |
| 808 // A sourceUnpackAlignment of zero indicates that the source | |
| 809 // data is tightly packed. Non-zero values may take a slow path. | |
| 810 // Destination data will have no gaps between rows. | |
| 811 // Implemented in GraphicsContext3DImagePacking.cpp | |
| 812 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); | |
| 813 | |
| 814 void paintFramebufferToCanvas(int framebuffer, int width, int height, bool p
remultiplyAlpha, ImageBuffer*); | |
| 815 // Helper function to flip a bitmap vertically. | |
| 816 void flipVertically(uint8_t* data, int width, int height); | |
| 817 | |
| 818 // Extensions3D support. | |
| 819 bool supportsExtension(const String& name); | |
| 820 bool ensureExtensionEnabled(const String& name); | |
| 821 bool isExtensionEnabled(const String& name); | |
| 822 | |
| 823 void initializeExtensions(); | |
| 824 | |
| 825 bool preserveDrawingBuffer() const { return m_preserveDrawingBuffer; } | |
| 826 | |
| 827 OwnPtr<blink::WebGraphicsContext3DProvider> m_provider; | |
| 828 blink::WebGraphicsContext3D* m_impl; | |
| 829 OwnPtr<GraphicsContext3DContextLostCallbackAdapter> m_contextLostCallbackAda
pter; | |
| 830 OwnPtr<GraphicsContext3DErrorMessageCallbackAdapter> m_errorMessageCallbackA
dapter; | |
| 831 OwnPtr<blink::WebGraphicsContext3D> m_ownedWebContext; | |
| 832 OwnPtr<Extensions3D> m_extensions; | |
| 833 bool m_initializedAvailableExtensions; | |
| 834 HashSet<String> m_enabledExtensions; | |
| 835 HashSet<String> m_requestableExtensions; | |
| 836 bool m_layerComposited; | |
| 837 bool m_preserveDrawingBuffer; | |
| 838 int m_packAlignment; | |
| 839 | |
| 840 enum ResourceSafety { | |
| 841 ResourceSafetyUnknown, | |
| 842 ResourceSafe, | |
| 843 ResourceUnsafe | |
| 844 }; | |
| 845 ResourceSafety m_resourceSafety; | |
| 846 | |
| 847 // If the width and height of the Canvas's backing store don't | |
| 848 // match those that we were given in the most recent call to | |
| 849 // reshape(), then we need an intermediate bitmap to read back the | |
| 850 // frame buffer into. This seems to happen when CSS styles are | |
| 851 // used to resize the Canvas. | |
| 852 SkBitmap m_resizingBitmap; | |
| 853 | |
| 854 GrContext* m_grContext; | |
| 855 | |
| 856 // Used to flip a bitmap vertically. | |
| 857 Vector<uint8_t> m_scanline; | |
| 858 }; | |
| 859 | |
| 860 } // namespace WebCore | |
| 861 | |
| 862 #endif // GraphicsContext3D_h | |
| OLD | NEW |