OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
4 * Copyright (C) 2010 Mozilla Corporation. All rights reserved. | 4 * Copyright (C) 2010 Mozilla Corporation. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "config.h" | 28 #include "config.h" |
29 | 29 |
30 #if USE(3D_GRAPHICS) | 30 #if USE(3D_GRAPHICS) |
31 | 31 |
32 #include "GraphicsContext3D.h" | 32 #include "GraphicsContext3D.h" |
33 #include "GraphicsContext3DNEON.h" | 33 #include "GraphicsContext3DNEON.h" |
34 | 34 |
35 #include "CheckedInt.h" | 35 #include "CheckedInt.h" |
36 #include "DrawingBuffer.h" | 36 #include "DrawingBuffer.h" |
37 #include "Extensions3D.h" | 37 #include "Extensions3D.h" |
| 38 #include "GraphicsContext3DPrivate.h" |
38 #include "Image.h" | 39 #include "Image.h" |
| 40 #include "ImageBuffer.h" |
39 #include "ImageData.h" | 41 #include "ImageData.h" |
40 #include "ImageObserver.h" | 42 #include "ImageObserver.h" |
| 43 #include "SkTypes.h" |
41 | 44 |
| 45 #include <public/Platform.h> |
| 46 #include <public/WebGraphicsContext3D.h> |
42 #include <wtf/ArrayBufferView.h> | 47 #include <wtf/ArrayBufferView.h> |
43 #include <wtf/OwnArrayPtr.h> | 48 #include <wtf/OwnArrayPtr.h> |
44 #include <wtf/PassOwnArrayPtr.h> | 49 #include <wtf/PassOwnArrayPtr.h> |
| 50 #include <wtf/text/CString.h> |
| 51 #include <wtf/text/WTFString.h> |
45 | 52 |
46 namespace WebCore { | 53 namespace WebCore { |
47 | 54 |
48 namespace { | 55 namespace { |
49 | 56 |
50 GraphicsContext3D::DataFormat getDataFormat(GC3Denum destinationFormat, GC3Denum
destinationType) | 57 GraphicsContext3D::DataFormat getDataFormat(GC3Denum destinationFormat, GC3Denum
destinationType) |
51 { | 58 { |
52 GraphicsContext3D::DataFormat dstFormat = GraphicsContext3D::DataFormatRGBA8
; | 59 GraphicsContext3D::DataFormat dstFormat = GraphicsContext3D::DataFormatRGBA8
; |
53 switch (destinationType) { | 60 switch (destinationType) { |
54 case GraphicsContext3D::UNSIGNED_BYTE: | 61 case GraphicsContext3D::UNSIGNED_BYTE: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 default: | 108 default: |
102 ASSERT_NOT_REACHED(); | 109 ASSERT_NOT_REACHED(); |
103 } | 110 } |
104 break; | 111 break; |
105 default: | 112 default: |
106 ASSERT_NOT_REACHED(); | 113 ASSERT_NOT_REACHED(); |
107 } | 114 } |
108 return dstFormat; | 115 return dstFormat; |
109 } | 116 } |
110 | 117 |
| 118 void getDrawingParameters(DrawingBuffer* drawingBuffer, WebKit::WebGraphicsConte
xt3D* graphicsContext3D, |
| 119 Platform3DObject* frameBufferId, int* width, int* heig
ht) |
| 120 { |
| 121 if (drawingBuffer) { |
| 122 *frameBufferId = drawingBuffer->framebuffer(); |
| 123 *width = drawingBuffer->size().width(); |
| 124 *height = drawingBuffer->size().height(); |
| 125 } else { |
| 126 *frameBufferId = 0; |
| 127 *width = graphicsContext3D->width(); |
| 128 *height = graphicsContext3D->height(); |
| 129 } |
| 130 } |
| 131 |
111 } // anonymous namespace | 132 } // anonymous namespace |
112 | 133 |
| 134 // Macros to assist in delegating from GraphicsContext3D to |
| 135 // WebGraphicsContext3D. |
| 136 |
| 137 #define DELEGATE_TO_WEBCONTEXT(name) \ |
| 138 void GraphicsContext3D::name() \ |
| 139 { \ |
| 140 m_private->webContext()->name(); \ |
| 141 } |
| 142 |
| 143 #define DELEGATE_TO_WEBCONTEXT_R(name, rt) \ |
| 144 rt GraphicsContext3D::name() \ |
| 145 { \ |
| 146 return m_private->webContext()->name(); \ |
| 147 } |
| 148 |
| 149 #define DELEGATE_TO_WEBCONTEXT_1(name, t1) \ |
| 150 void GraphicsContext3D::name(t1 a1) \ |
| 151 { \ |
| 152 m_private->webContext()->name(a1); \ |
| 153 } |
| 154 |
| 155 #define DELEGATE_TO_WEBCONTEXT_1R(name, t1, rt) \ |
| 156 rt GraphicsContext3D::name(t1 a1) \ |
| 157 { \ |
| 158 return m_private->webContext()->name(a1); \ |
| 159 } |
| 160 |
| 161 #define DELEGATE_TO_WEBCONTEXT_2(name, t1, t2) \ |
| 162 void GraphicsContext3D::name(t1 a1, t2 a2) \ |
| 163 { \ |
| 164 m_private->webContext()->name(a1, a2); \ |
| 165 } |
| 166 |
| 167 #define DELEGATE_TO_WEBCONTEXT_2R(name, t1, t2, rt) \ |
| 168 rt GraphicsContext3D::name(t1 a1, t2 a2) \ |
| 169 { \ |
| 170 return m_private->webContext()->name(a1, a2); \ |
| 171 } |
| 172 |
| 173 #define DELEGATE_TO_WEBCONTEXT_3(name, t1, t2, t3) \ |
| 174 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \ |
| 175 { \ |
| 176 m_private->webContext()->name(a1, a2, a3); \ |
| 177 } |
| 178 |
| 179 #define DELEGATE_TO_WEBCONTEXT_3R(name, t1, t2, t3, rt) \ |
| 180 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \ |
| 181 { \ |
| 182 return m_private->webContext()->name(a1, a2, a3); \ |
| 183 } |
| 184 |
| 185 #define DELEGATE_TO_WEBCONTEXT_4(name, t1, t2, t3, t4) \ |
| 186 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \ |
| 187 { \ |
| 188 m_private->webContext()->name(a1, a2, a3, a4); \ |
| 189 } |
| 190 |
| 191 #define DELEGATE_TO_WEBCONTEXT_4R(name, t1, t2, t3, t4, rt) \ |
| 192 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \ |
| 193 { \ |
| 194 return m_private->webContext()->name(a1, a2, a3, a4); \ |
| 195 } |
| 196 |
| 197 #define DELEGATE_TO_WEBCONTEXT_5(name, t1, t2, t3, t4, t5) \ |
| 198 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) \ |
| 199 { \ |
| 200 m_private->webContext()->name(a1, a2, a3, a4, a5); \ |
| 201 } |
| 202 |
| 203 #define DELEGATE_TO_WEBCONTEXT_6(name, t1, t2, t3, t4, t5, t6) \ |
| 204 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \ |
| 205 { \ |
| 206 m_private->webContext()->name(a1, a2, a3, a4, a5, a6); \ |
| 207 } |
| 208 |
| 209 #define DELEGATE_TO_WEBCONTEXT_6R(name, t1, t2, t3, t4, t5, t6, rt) \ |
| 210 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \ |
| 211 { \ |
| 212 return m_private->webContext()->name(a1, a2, a3, a4, a5, a6); \ |
| 213 } |
| 214 |
| 215 #define DELEGATE_TO_WEBCONTEXT_7(name, t1, t2, t3, t4, t5, t6, t7) \ |
| 216 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \ |
| 217 { \ |
| 218 m_private->webContext()->name(a1, a2, a3, a4, a5, a6, a7); \ |
| 219 } |
| 220 |
| 221 #define DELEGATE_TO_WEBCONTEXT_7R(name, t1, t2, t3, t4, t5, t6, t7, rt) \ |
| 222 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \ |
| 223 { \ |
| 224 return m_private->webContext()->name(a1, a2, a3, a4, a5, a6, a7); \ |
| 225 } |
| 226 |
| 227 #define DELEGATE_TO_WEBCONTEXT_8(name, t1, t2, t3, t4, t5, t6, t7, t8) \ |
| 228 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8
a8) \ |
| 229 { \ |
| 230 m_private->webContext()->name(a1, a2, a3, a4, a5, a6, a7, a8); \ |
| 231 } |
| 232 |
| 233 #define DELEGATE_TO_WEBCONTEXT_9(name, t1, t2, t3, t4, t5, t6, t7, t8, t9) \ |
| 234 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8
a8, t9 a9) \ |
| 235 { \ |
| 236 m_private->webContext()->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ |
| 237 } |
| 238 |
| 239 #define DELEGATE_TO_WEBCONTEXT_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt)
\ |
| 240 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a
8, t9 a9) \ |
| 241 { \ |
| 242 return m_private->webContext()->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ |
| 243 } |
| 244 |
| 245 GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes, HostWindow*,
GraphicsContext3D::RenderStyle) |
| 246 { |
| 247 } |
| 248 |
| 249 GraphicsContext3D::~GraphicsContext3D() |
| 250 { |
| 251 m_private->setContextLostCallback(nullptr); |
| 252 m_private->setErrorMessageCallback(nullptr); |
| 253 } |
| 254 |
| 255 void GraphicsContext3D::setContextLostCallback(PassOwnPtr<GraphicsContext3D::Con
textLostCallback> callback) |
| 256 { |
| 257 m_private->setContextLostCallback(callback); |
| 258 } |
| 259 |
| 260 void GraphicsContext3D::setErrorMessageCallback(PassOwnPtr<GraphicsContext3D::Er
rorMessageCallback> callback) |
| 261 { |
| 262 m_private->setErrorMessageCallback(callback); |
| 263 } |
| 264 |
| 265 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attri
butes attrs, HostWindow*, GraphicsContext3D::RenderStyle renderStyle) |
| 266 { |
| 267 ASSERT(renderStyle != GraphicsContext3D::RenderDirectlyToHostWindow); |
| 268 |
| 269 WebKit::WebGraphicsContext3D::Attributes webAttributes; |
| 270 webAttributes.alpha = attrs.alpha; |
| 271 webAttributes.depth = attrs.depth; |
| 272 webAttributes.stencil = attrs.stencil; |
| 273 webAttributes.antialias = attrs.antialias; |
| 274 webAttributes.premultipliedAlpha = attrs.premultipliedAlpha; |
| 275 webAttributes.noExtensions = attrs.noExtensions; |
| 276 webAttributes.shareResources = attrs.shareResources; |
| 277 webAttributes.preferDiscreteGPU = attrs.preferDiscreteGPU; |
| 278 webAttributes.topDocumentURL = attrs.topDocumentURL.string(); |
| 279 |
| 280 OwnPtr<WebKit::WebGraphicsContext3D> webContext = adoptPtr(WebKit::Platform:
:current()->createOffscreenGraphicsContext3D(webAttributes)); |
| 281 if (!webContext) |
| 282 return 0; |
| 283 |
| 284 return GraphicsContext3DPrivate::createGraphicsContextFromWebContext(webCont
ext.release(), attrs.preserveDrawingBuffer); |
| 285 } |
| 286 |
| 287 PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D() const |
| 288 { |
| 289 return m_private->webContext(); |
| 290 } |
| 291 |
| 292 Platform3DObject GraphicsContext3D::platformTexture() const |
| 293 { |
| 294 return m_private->webContext()->getPlatformTextureId(); |
| 295 } |
| 296 |
| 297 GrContext* GraphicsContext3D::grContext() |
| 298 { |
| 299 return m_private->grContext(); |
| 300 } |
| 301 |
| 302 PlatformLayer* GraphicsContext3D::platformLayer() const |
| 303 { |
| 304 return 0; |
| 305 } |
| 306 |
| 307 DELEGATE_TO_WEBCONTEXT_R(makeContextCurrent, bool) |
| 308 DELEGATE_TO_WEBCONTEXT(prepareTexture) |
| 309 |
| 310 bool GraphicsContext3D::isGLES2Compliant() const |
| 311 { |
| 312 return m_private->webContext()->isGLES2Compliant(); |
| 313 } |
| 314 |
| 315 bool GraphicsContext3D::isResourceSafe() |
| 316 { |
| 317 return m_private->isResourceSafe(); |
| 318 } |
| 319 |
| 320 DELEGATE_TO_WEBCONTEXT_1(activeTexture, GC3Denum) |
| 321 DELEGATE_TO_WEBCONTEXT_2(attachShader, Platform3DObject, Platform3DObject) |
| 322 |
| 323 void GraphicsContext3D::bindAttribLocation(Platform3DObject program, GC3Duint in
dex, const String& name) |
| 324 { |
| 325 m_private->webContext()->bindAttribLocation(program, index, name.utf8().data
()); |
| 326 } |
| 327 |
| 328 DELEGATE_TO_WEBCONTEXT_2(bindBuffer, GC3Denum, Platform3DObject) |
| 329 DELEGATE_TO_WEBCONTEXT_2(bindFramebuffer, GC3Denum, Platform3DObject) |
| 330 DELEGATE_TO_WEBCONTEXT_2(bindRenderbuffer, GC3Denum, Platform3DObject) |
| 331 DELEGATE_TO_WEBCONTEXT_2(bindTexture, GC3Denum, Platform3DObject) |
| 332 DELEGATE_TO_WEBCONTEXT_4(blendColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dcla
mpf) |
| 333 DELEGATE_TO_WEBCONTEXT_1(blendEquation, GC3Denum) |
| 334 DELEGATE_TO_WEBCONTEXT_2(blendEquationSeparate, GC3Denum, GC3Denum) |
| 335 DELEGATE_TO_WEBCONTEXT_2(blendFunc, GC3Denum, GC3Denum) |
| 336 DELEGATE_TO_WEBCONTEXT_4(blendFuncSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Den
um) |
| 337 |
| 338 void GraphicsContext3D::bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum
usage) |
| 339 { |
| 340 bufferData(target, size, 0, usage); |
| 341 } |
| 342 |
| 343 DELEGATE_TO_WEBCONTEXT_4(bufferData, GC3Denum, GC3Dsizeiptr, const void*, GC3Den
um) |
| 344 DELEGATE_TO_WEBCONTEXT_4(bufferSubData, GC3Denum, GC3Dintptr, GC3Dsizeiptr, cons
t void*) |
| 345 |
| 346 DELEGATE_TO_WEBCONTEXT_1R(checkFramebufferStatus, GC3Denum, GC3Denum) |
| 347 DELEGATE_TO_WEBCONTEXT_1(clear, GC3Dbitfield) |
| 348 DELEGATE_TO_WEBCONTEXT_4(clearColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dcla
mpf) |
| 349 DELEGATE_TO_WEBCONTEXT_1(clearDepth, GC3Dclampf) |
| 350 DELEGATE_TO_WEBCONTEXT_1(clearStencil, GC3Dint) |
| 351 DELEGATE_TO_WEBCONTEXT_4(colorMask, GC3Dboolean, GC3Dboolean, GC3Dboolean, GC3Db
oolean) |
| 352 DELEGATE_TO_WEBCONTEXT_1(compileShader, Platform3DObject) |
| 353 |
| 354 DELEGATE_TO_WEBCONTEXT_8(compressedTexImage2D, GC3Denum, GC3Dint, GC3Denum, GC3D
int, GC3Dint, GC3Dsizei, GC3Dsizei, const void*) |
| 355 DELEGATE_TO_WEBCONTEXT_9(compressedTexSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC
3Dint, GC3Dint, GC3Dint, GC3Denum, GC3Dsizei, const void*) |
| 356 DELEGATE_TO_WEBCONTEXT_8(copyTexImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dint, G
C3Dint, GC3Dsizei, GC3Dsizei, GC3Dint) |
| 357 DELEGATE_TO_WEBCONTEXT_8(copyTexSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint,
GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei) |
| 358 DELEGATE_TO_WEBCONTEXT_1(cullFace, GC3Denum) |
| 359 DELEGATE_TO_WEBCONTEXT_1(depthFunc, GC3Denum) |
| 360 DELEGATE_TO_WEBCONTEXT_1(depthMask, GC3Dboolean) |
| 361 DELEGATE_TO_WEBCONTEXT_2(depthRange, GC3Dclampf, GC3Dclampf) |
| 362 DELEGATE_TO_WEBCONTEXT_2(detachShader, Platform3DObject, Platform3DObject) |
| 363 DELEGATE_TO_WEBCONTEXT_1(disable, GC3Denum) |
| 364 DELEGATE_TO_WEBCONTEXT_1(disableVertexAttribArray, GC3Duint) |
| 365 DELEGATE_TO_WEBCONTEXT_3(drawArrays, GC3Denum, GC3Dint, GC3Dsizei) |
| 366 DELEGATE_TO_WEBCONTEXT_4(drawElements, GC3Denum, GC3Dsizei, GC3Denum, GC3Dintptr
) |
| 367 |
| 368 DELEGATE_TO_WEBCONTEXT_1(enable, GC3Denum) |
| 369 DELEGATE_TO_WEBCONTEXT_1(enableVertexAttribArray, GC3Duint) |
| 370 DELEGATE_TO_WEBCONTEXT(finish) |
| 371 DELEGATE_TO_WEBCONTEXT(flush) |
| 372 DELEGATE_TO_WEBCONTEXT_4(framebufferRenderbuffer, GC3Denum, GC3Denum, GC3Denum,
Platform3DObject) |
| 373 DELEGATE_TO_WEBCONTEXT_5(framebufferTexture2D, GC3Denum, GC3Denum, GC3Denum, Pla
tform3DObject, GC3Dint) |
| 374 DELEGATE_TO_WEBCONTEXT_1(frontFace, GC3Denum) |
| 375 DELEGATE_TO_WEBCONTEXT_1(generateMipmap, GC3Denum) |
| 376 |
| 377 bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, GC3Duint index
, ActiveInfo& info) |
| 378 { |
| 379 WebKit::WebGraphicsContext3D::ActiveInfo webInfo; |
| 380 if (!m_private->webContext()->getActiveAttrib(program, index, webInfo)) |
| 381 return false; |
| 382 info.name = webInfo.name; |
| 383 info.type = webInfo.type; |
| 384 info.size = webInfo.size; |
| 385 return true; |
| 386 } |
| 387 |
| 388 bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint inde
x, ActiveInfo& info) |
| 389 { |
| 390 WebKit::WebGraphicsContext3D::ActiveInfo webInfo; |
| 391 if (!m_private->webContext()->getActiveUniform(program, index, webInfo)) |
| 392 return false; |
| 393 info.name = webInfo.name; |
| 394 info.type = webInfo.type; |
| 395 info.size = webInfo.size; |
| 396 return true; |
| 397 } |
| 398 |
| 399 DELEGATE_TO_WEBCONTEXT_4(getAttachedShaders, Platform3DObject, GC3Dsizei, GC3Dsi
zei*, Platform3DObject*) |
| 400 |
| 401 GC3Dint GraphicsContext3D::getAttribLocation(Platform3DObject program, const Str
ing& name) |
| 402 { |
| 403 return m_private->webContext()->getAttribLocation(program, name.utf8().data(
)); |
| 404 } |
| 405 |
| 406 DELEGATE_TO_WEBCONTEXT_2(getBooleanv, GC3Denum, GC3Dboolean*) |
| 407 DELEGATE_TO_WEBCONTEXT_3(getBufferParameteriv, GC3Denum, GC3Denum, GC3Dint*) |
| 408 |
| 409 GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes() |
| 410 { |
| 411 WebKit::WebGraphicsContext3D::Attributes webAttributes = m_private->webConte
xt()->getContextAttributes(); |
| 412 GraphicsContext3D::Attributes attributes; |
| 413 attributes.alpha = webAttributes.alpha; |
| 414 attributes.depth = webAttributes.depth; |
| 415 attributes.stencil = webAttributes.stencil; |
| 416 attributes.antialias = webAttributes.antialias; |
| 417 attributes.premultipliedAlpha = webAttributes.premultipliedAlpha; |
| 418 attributes.preserveDrawingBuffer = m_private->preserveDrawingBuffer(); |
| 419 attributes.preferDiscreteGPU = webAttributes.preferDiscreteGPU; |
| 420 return attributes; |
| 421 } |
| 422 |
| 423 DELEGATE_TO_WEBCONTEXT_R(getError, GC3Denum) |
| 424 DELEGATE_TO_WEBCONTEXT_2(getFloatv, GC3Denum, GC3Dfloat*) |
| 425 DELEGATE_TO_WEBCONTEXT_4(getFramebufferAttachmentParameteriv, GC3Denum, GC3Denum
, GC3Denum, GC3Dint*) |
| 426 DELEGATE_TO_WEBCONTEXT_2(getIntegerv, GC3Denum, GC3Dint*) |
| 427 DELEGATE_TO_WEBCONTEXT_3(getProgramiv, Platform3DObject, GC3Denum, GC3Dint*) |
| 428 DELEGATE_TO_WEBCONTEXT_1R(getProgramInfoLog, Platform3DObject, String) |
| 429 DELEGATE_TO_WEBCONTEXT_3(getRenderbufferParameteriv, GC3Denum, GC3Denum, GC3Dint
*) |
| 430 DELEGATE_TO_WEBCONTEXT_3(getShaderiv, Platform3DObject, GC3Denum, GC3Dint*) |
| 431 DELEGATE_TO_WEBCONTEXT_1R(getShaderInfoLog, Platform3DObject, String) |
| 432 DELEGATE_TO_WEBCONTEXT_4(getShaderPrecisionFormat, GC3Denum, GC3Denum, GC3Dint*,
GC3Dint*) |
| 433 DELEGATE_TO_WEBCONTEXT_1R(getShaderSource, Platform3DObject, String) |
| 434 DELEGATE_TO_WEBCONTEXT_1R(getString, GC3Denum, String) |
| 435 DELEGATE_TO_WEBCONTEXT_3(getTexParameterfv, GC3Denum, GC3Denum, GC3Dfloat*) |
| 436 DELEGATE_TO_WEBCONTEXT_3(getTexParameteriv, GC3Denum, GC3Denum, GC3Dint*) |
| 437 DELEGATE_TO_WEBCONTEXT_3(getUniformfv, Platform3DObject, GC3Dint, GC3Dfloat*) |
| 438 DELEGATE_TO_WEBCONTEXT_3(getUniformiv, Platform3DObject, GC3Dint, GC3Dint*) |
| 439 |
| 440 GC3Dint GraphicsContext3D::getUniformLocation(Platform3DObject program, const St
ring& name) |
| 441 { |
| 442 return m_private->webContext()->getUniformLocation(program, name.utf8().data
()); |
| 443 } |
| 444 |
| 445 DELEGATE_TO_WEBCONTEXT_3(getVertexAttribfv, GC3Duint, GC3Denum, GC3Dfloat*) |
| 446 DELEGATE_TO_WEBCONTEXT_3(getVertexAttribiv, GC3Duint, GC3Denum, GC3Dint*) |
| 447 DELEGATE_TO_WEBCONTEXT_2R(getVertexAttribOffset, GC3Duint, GC3Denum, GC3Dsizeipt
r) |
| 448 |
| 449 DELEGATE_TO_WEBCONTEXT_2(hint, GC3Denum, GC3Denum) |
| 450 DELEGATE_TO_WEBCONTEXT_1R(isBuffer, Platform3DObject, GC3Dboolean) |
| 451 DELEGATE_TO_WEBCONTEXT_1R(isEnabled, GC3Denum, GC3Dboolean) |
| 452 DELEGATE_TO_WEBCONTEXT_1R(isFramebuffer, Platform3DObject, GC3Dboolean) |
| 453 DELEGATE_TO_WEBCONTEXT_1R(isProgram, Platform3DObject, GC3Dboolean) |
| 454 DELEGATE_TO_WEBCONTEXT_1R(isRenderbuffer, Platform3DObject, GC3Dboolean) |
| 455 DELEGATE_TO_WEBCONTEXT_1R(isShader, Platform3DObject, GC3Dboolean) |
| 456 DELEGATE_TO_WEBCONTEXT_1R(isTexture, Platform3DObject, GC3Dboolean) |
| 457 DELEGATE_TO_WEBCONTEXT_1(lineWidth, GC3Dfloat) |
| 458 DELEGATE_TO_WEBCONTEXT_1(linkProgram, Platform3DObject) |
| 459 DELEGATE_TO_WEBCONTEXT_2(pixelStorei, GC3Denum, GC3Dint) |
| 460 DELEGATE_TO_WEBCONTEXT_2(polygonOffset, GC3Dfloat, GC3Dfloat) |
| 461 |
| 462 DELEGATE_TO_WEBCONTEXT_7(readPixels, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3
Denum, GC3Denum, void*) |
| 463 |
| 464 DELEGATE_TO_WEBCONTEXT(releaseShaderCompiler) |
| 465 DELEGATE_TO_WEBCONTEXT_4(renderbufferStorage, GC3Denum, GC3Denum, GC3Dsizei, GC3
Dsizei) |
| 466 DELEGATE_TO_WEBCONTEXT_2(sampleCoverage, GC3Dclampf, GC3Dboolean) |
| 467 DELEGATE_TO_WEBCONTEXT_4(scissor, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei) |
| 468 |
| 469 void GraphicsContext3D::shaderSource(Platform3DObject shader, const String& stri
ng) |
| 470 { |
| 471 m_private->webContext()->shaderSource(shader, string.utf8().data()); |
| 472 } |
| 473 |
| 474 DELEGATE_TO_WEBCONTEXT_3(stencilFunc, GC3Denum, GC3Dint, GC3Duint) |
| 475 DELEGATE_TO_WEBCONTEXT_4(stencilFuncSeparate, GC3Denum, GC3Denum, GC3Dint, GC3Du
int) |
| 476 DELEGATE_TO_WEBCONTEXT_1(stencilMask, GC3Duint) |
| 477 DELEGATE_TO_WEBCONTEXT_2(stencilMaskSeparate, GC3Denum, GC3Duint) |
| 478 DELEGATE_TO_WEBCONTEXT_3(stencilOp, GC3Denum, GC3Denum, GC3Denum) |
| 479 DELEGATE_TO_WEBCONTEXT_4(stencilOpSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Den
um) |
| 480 |
| 481 DELEGATE_TO_WEBCONTEXT_9(texImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dsizei, GC3
Dsizei, GC3Dint, GC3Denum, GC3Denum, const void*) |
| 482 DELEGATE_TO_WEBCONTEXT_3(texParameterf, GC3Denum, GC3Denum, GC3Dfloat) |
| 483 DELEGATE_TO_WEBCONTEXT_3(texParameteri, GC3Denum, GC3Denum, GC3Dint) |
| 484 DELEGATE_TO_WEBCONTEXT_9(texSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3
Dsizei, GC3Dsizei, GC3Denum, GC3Denum, const void*) |
| 485 |
| 486 DELEGATE_TO_WEBCONTEXT_2(uniform1f, GC3Dint, GC3Dfloat) |
| 487 DELEGATE_TO_WEBCONTEXT_3(uniform1fv, GC3Dint, GC3Dsizei, GC3Dfloat*) |
| 488 DELEGATE_TO_WEBCONTEXT_2(uniform1i, GC3Dint, GC3Dint) |
| 489 DELEGATE_TO_WEBCONTEXT_3(uniform1iv, GC3Dint, GC3Dsizei, GC3Dint*) |
| 490 DELEGATE_TO_WEBCONTEXT_3(uniform2f, GC3Dint, GC3Dfloat, GC3Dfloat) |
| 491 DELEGATE_TO_WEBCONTEXT_3(uniform2fv, GC3Dint, GC3Dsizei, GC3Dfloat*) |
| 492 DELEGATE_TO_WEBCONTEXT_3(uniform2i, GC3Dint, GC3Dint, GC3Dint) |
| 493 DELEGATE_TO_WEBCONTEXT_3(uniform2iv, GC3Dint, GC3Dsizei, GC3Dint*) |
| 494 DELEGATE_TO_WEBCONTEXT_4(uniform3f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat) |
| 495 DELEGATE_TO_WEBCONTEXT_3(uniform3fv, GC3Dint, GC3Dsizei, GC3Dfloat*) |
| 496 DELEGATE_TO_WEBCONTEXT_4(uniform3i, GC3Dint, GC3Dint, GC3Dint, GC3Dint) |
| 497 DELEGATE_TO_WEBCONTEXT_3(uniform3iv, GC3Dint, GC3Dsizei, GC3Dint*) |
| 498 DELEGATE_TO_WEBCONTEXT_5(uniform4f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC
3Dfloat) |
| 499 DELEGATE_TO_WEBCONTEXT_3(uniform4fv, GC3Dint, GC3Dsizei, GC3Dfloat*) |
| 500 DELEGATE_TO_WEBCONTEXT_5(uniform4i, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint) |
| 501 DELEGATE_TO_WEBCONTEXT_3(uniform4iv, GC3Dint, GC3Dsizei, GC3Dint*) |
| 502 DELEGATE_TO_WEBCONTEXT_4(uniformMatrix2fv, GC3Dint, GC3Dsizei, GC3Dboolean, GC3D
float*) |
| 503 DELEGATE_TO_WEBCONTEXT_4(uniformMatrix3fv, GC3Dint, GC3Dsizei, GC3Dboolean, GC3D
float*) |
| 504 DELEGATE_TO_WEBCONTEXT_4(uniformMatrix4fv, GC3Dint, GC3Dsizei, GC3Dboolean, GC3D
float*) |
| 505 |
| 506 DELEGATE_TO_WEBCONTEXT_1(useProgram, Platform3DObject) |
| 507 DELEGATE_TO_WEBCONTEXT_1(validateProgram, Platform3DObject) |
| 508 |
| 509 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib1f, GC3Duint, GC3Dfloat) |
| 510 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib1fv, GC3Duint, GC3Dfloat*) |
| 511 DELEGATE_TO_WEBCONTEXT_3(vertexAttrib2f, GC3Duint, GC3Dfloat, GC3Dfloat) |
| 512 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib2fv, GC3Duint, GC3Dfloat*) |
| 513 DELEGATE_TO_WEBCONTEXT_4(vertexAttrib3f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dflo
at) |
| 514 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib3fv, GC3Duint, GC3Dfloat*) |
| 515 DELEGATE_TO_WEBCONTEXT_5(vertexAttrib4f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dflo
at, GC3Dfloat) |
| 516 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib4fv, GC3Duint, GC3Dfloat*) |
| 517 DELEGATE_TO_WEBCONTEXT_6(vertexAttribPointer, GC3Duint, GC3Dint, GC3Denum, GC3Db
oolean, GC3Dsizei, GC3Dintptr) |
| 518 |
| 519 DELEGATE_TO_WEBCONTEXT_4(viewport, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei) |
| 520 |
| 521 void GraphicsContext3D::reshape(int width, int height) |
| 522 { |
| 523 if (width == m_private->webContext()->width() && height == m_private->webCon
text()->height()) |
| 524 return; |
| 525 |
| 526 m_private->webContext()->reshape(width, height); |
| 527 } |
| 528 |
| 529 void GraphicsContext3D::markContextChanged() |
| 530 { |
| 531 m_private->markContextChanged(); |
| 532 } |
| 533 |
| 534 bool GraphicsContext3D::layerComposited() const |
| 535 { |
| 536 return m_private->layerComposited(); |
| 537 } |
| 538 |
| 539 void GraphicsContext3D::markLayerComposited() |
| 540 { |
| 541 m_private->markLayerComposited(); |
| 542 } |
| 543 |
| 544 void GraphicsContext3D::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer,
DrawingBuffer* drawingBuffer) |
| 545 { |
| 546 Platform3DObject framebufferId; |
| 547 int width, height; |
| 548 getDrawingParameters(drawingBuffer, m_private->webContext(), &framebufferId,
&width, &height); |
| 549 m_private->paintFramebufferToCanvas(framebufferId, width, height, !getContex
tAttributes().premultipliedAlpha, imageBuffer); |
| 550 } |
| 551 |
| 552 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(Drawin
gBuffer* drawingBuffer) |
| 553 { |
| 554 if (getContextAttributes().premultipliedAlpha) |
| 555 return 0; |
| 556 |
| 557 Platform3DObject framebufferId; |
| 558 int width, height; |
| 559 getDrawingParameters(drawingBuffer, m_private->webContext(), &framebufferId,
&width, &height); |
| 560 |
| 561 RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height)); |
| 562 unsigned char* pixels = imageData->data()->data(); |
| 563 size_t bufferSize = 4 * width * height; |
| 564 |
| 565 m_private->webContext()->readBackFramebuffer(pixels, bufferSize, framebuffer
Id, width, height); |
| 566 |
| 567 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT |
| 568 // If the implementation swapped the red and blue channels, un-swap them. |
| 569 for (size_t i = 0; i < bufferSize; i += 4) |
| 570 std::swap(pixels[i], pixels[i + 2]); |
| 571 #endif |
| 572 |
| 573 return imageData.release(); |
| 574 } |
| 575 |
| 576 bool GraphicsContext3D::paintCompositedResultsToCanvas(ImageBuffer*) |
| 577 { |
| 578 return false; |
| 579 } |
| 580 |
| 581 DELEGATE_TO_WEBCONTEXT_R(createBuffer, Platform3DObject) |
| 582 DELEGATE_TO_WEBCONTEXT_R(createFramebuffer, Platform3DObject) |
| 583 DELEGATE_TO_WEBCONTEXT_R(createProgram, Platform3DObject) |
| 584 DELEGATE_TO_WEBCONTEXT_R(createRenderbuffer, Platform3DObject) |
| 585 DELEGATE_TO_WEBCONTEXT_1R(createShader, GC3Denum, Platform3DObject) |
| 586 DELEGATE_TO_WEBCONTEXT_R(createTexture, Platform3DObject) |
| 587 |
| 588 DELEGATE_TO_WEBCONTEXT_1(deleteBuffer, Platform3DObject) |
| 589 DELEGATE_TO_WEBCONTEXT_1(deleteFramebuffer, Platform3DObject) |
| 590 DELEGATE_TO_WEBCONTEXT_1(deleteProgram, Platform3DObject) |
| 591 DELEGATE_TO_WEBCONTEXT_1(deleteRenderbuffer, Platform3DObject) |
| 592 DELEGATE_TO_WEBCONTEXT_1(deleteShader, Platform3DObject) |
| 593 DELEGATE_TO_WEBCONTEXT_1(deleteTexture, Platform3DObject) |
| 594 |
| 595 DELEGATE_TO_WEBCONTEXT_1(synthesizeGLError, GC3Denum) |
| 596 |
| 597 Extensions3D* GraphicsContext3D::getExtensions() |
| 598 { |
| 599 return m_private->getExtensions(); |
| 600 } |
| 601 |
| 602 IntSize GraphicsContext3D::getInternalFramebufferSize() const |
| 603 { |
| 604 return IntSize(m_private->webContext()->width(), m_private->webContext()->he
ight()); |
| 605 } |
| 606 |
113 bool GraphicsContext3D::texImage2DResourceSafe(GC3Denum target, GC3Dint level, G
C3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3De
num format, GC3Denum type, GC3Dint unpackAlignment) | 607 bool GraphicsContext3D::texImage2DResourceSafe(GC3Denum target, GC3Dint level, G
C3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3De
num format, GC3Denum type, GC3Dint unpackAlignment) |
114 { | 608 { |
115 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); | 609 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); |
116 OwnArrayPtr<unsigned char> zero; | 610 OwnArrayPtr<unsigned char> zero; |
117 if (!isResourceSafe() && width > 0 && height > 0) { | 611 if (!isResourceSafe() && width > 0 && height > 0) { |
118 unsigned int size; | 612 unsigned int size; |
119 GC3Denum error = computeImageSizeInBytes(format, type, width, height, un
packAlignment, &size, 0); | 613 GC3Denum error = computeImageSizeInBytes(format, type, width, height, un
packAlignment, &size, 0); |
120 if (error != GraphicsContext3D::NO_ERROR) { | 614 if (error != GraphicsContext3D::NO_ERROR) { |
121 synthesizeGLError(error); | 615 synthesizeGLError(error); |
122 return false; | 616 return false; |
123 } | 617 } |
124 zero = adoptArrayPtr(new unsigned char[size]); | 618 zero = adoptArrayPtr(new unsigned char[size]); |
125 if (!zero) { | 619 if (!zero) { |
126 synthesizeGLError(GraphicsContext3D::INVALID_VALUE); | 620 synthesizeGLError(GraphicsContext3D::INVALID_VALUE); |
127 return false; | 621 return false; |
128 } | 622 } |
129 memset(zero.get(), 0, size); | 623 memset(zero.get(), 0, size); |
130 } | 624 } |
131 return texImage2D(target, level, internalformat, width, height, border, form
at, type, zero.get()); | 625 texImage2D(target, level, internalformat, width, height, border, format, typ
e, zero.get()); |
| 626 return true; |
132 } | 627 } |
133 | 628 |
134 bool GraphicsContext3D::computeFormatAndTypeParameters(GC3Denum format, | 629 bool GraphicsContext3D::computeFormatAndTypeParameters(GC3Denum format, |
135 GC3Denum type, | 630 GC3Denum type, |
136 unsigned int* componentsP
erPixel, | 631 unsigned int* componentsP
erPixel, |
137 unsigned int* bytesPerCom
ponent) | 632 unsigned int* bytesPerCom
ponent) |
138 { | 633 { |
139 switch (format) { | 634 switch (format) { |
140 case GraphicsContext3D::ALPHA: | 635 case GraphicsContext3D::ALPHA: |
141 case GraphicsContext3D::LUMINANCE: | 636 case GraphicsContext3D::LUMINANCE: |
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 case GraphicsContext3D::DEPTH_STENCIL: | 1962 case GraphicsContext3D::DEPTH_STENCIL: |
1468 return ChannelDepth | ChannelStencil; | 1963 return ChannelDepth | ChannelStencil; |
1469 default: | 1964 default: |
1470 return 0; | 1965 return 0; |
1471 } | 1966 } |
1472 } | 1967 } |
1473 | 1968 |
1474 } // namespace WebCore | 1969 } // namespace WebCore |
1475 | 1970 |
1476 #endif // USE(3D_GRAPHICS) | 1971 #endif // USE(3D_GRAPHICS) |
OLD | NEW |