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 28 matching lines...) Expand all Loading... |
39 #include "wtf/CPU.h" | 39 #include "wtf/CPU.h" |
40 #include "wtf/text/CString.h" | 40 #include "wtf/text/CString.h" |
41 #include "wtf/text/StringHash.h" | 41 #include "wtf/text/StringHash.h" |
42 | 42 |
43 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
44 #include "public/platform/WebGraphicsContext3D.h" | 44 #include "public/platform/WebGraphicsContext3D.h" |
45 #include "public/platform/WebGraphicsContext3DProvider.h" | 45 #include "public/platform/WebGraphicsContext3DProvider.h" |
46 | 46 |
47 namespace WebCore { | 47 namespace WebCore { |
48 | 48 |
49 namespace { | |
50 | |
51 void getDrawingParameters(DrawingBuffer* drawingBuffer, blink::WebGraphicsContex
t3D* graphicsContext3D, | |
52 Platform3DObject* frameBufferId, int* width, int* heig
ht) | |
53 { | |
54 ASSERT(drawingBuffer); | |
55 *frameBufferId = drawingBuffer->framebuffer(); | |
56 *width = drawingBuffer->size().width(); | |
57 *height = drawingBuffer->size().height(); | |
58 } | |
59 | |
60 } // anonymous namespace | |
61 | |
62 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3D> web
Context, bool preserveDrawingBuffer) | 49 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3D> web
Context, bool preserveDrawingBuffer) |
63 : m_impl(webContext.get()) | 50 : m_impl(webContext.get()) |
64 , m_ownedWebContext(webContext) | 51 , m_ownedWebContext(webContext) |
65 , m_initializedAvailableExtensions(false) | 52 , m_initializedAvailableExtensions(false) |
66 , m_layerComposited(false) | |
67 , m_preserveDrawingBuffer(preserveDrawingBuffer) | 53 , m_preserveDrawingBuffer(preserveDrawingBuffer) |
68 , m_packAlignment(4) | |
69 , m_grContext(0) | 54 , m_grContext(0) |
70 { | 55 { |
71 } | 56 } |
72 | 57 |
73 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3DProvi
der> provider, bool preserveDrawingBuffer) | 58 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<blink::WebGraphicsContext3DProvi
der> provider, bool preserveDrawingBuffer) |
74 : m_provider(provider) | 59 : m_provider(provider) |
75 , m_impl(m_provider->context3d()) | 60 , m_impl(m_provider->context3d()) |
76 , m_initializedAvailableExtensions(false) | 61 , m_initializedAvailableExtensions(false) |
77 , m_layerComposited(false) | |
78 , m_preserveDrawingBuffer(preserveDrawingBuffer) | 62 , m_preserveDrawingBuffer(preserveDrawingBuffer) |
79 , m_packAlignment(4) | |
80 , m_grContext(m_provider->grContext()) | 63 , m_grContext(m_provider->grContext()) |
81 { | 64 { |
82 } | 65 } |
83 | 66 |
84 GraphicsContext3D::GraphicsContext3D(blink::WebGraphicsContext3D* webContext) | 67 GraphicsContext3D::GraphicsContext3D(blink::WebGraphicsContext3D* webContext) |
85 : m_impl(webContext) | 68 : m_impl(webContext) |
86 , m_initializedAvailableExtensions(false) | 69 , m_initializedAvailableExtensions(false) |
87 , m_layerComposited(false) | |
88 , m_preserveDrawingBuffer(false) | 70 , m_preserveDrawingBuffer(false) |
89 , m_packAlignment(4) | |
90 , m_grContext(0) | 71 , m_grContext(0) |
91 { | 72 { |
92 } | 73 } |
93 | 74 |
94 GraphicsContext3D::~GraphicsContext3D() | 75 GraphicsContext3D::~GraphicsContext3D() |
95 { | 76 { |
96 setContextLostCallback(nullptr); | |
97 setErrorMessageCallback(nullptr); | |
98 } | 77 } |
99 | 78 |
100 // Macros to assist in delegating from GraphicsContext3D to | 79 // Macros to assist in delegating from GraphicsContext3D to |
101 // WebGraphicsContext3D. | 80 // WebGraphicsContext3D. |
102 | 81 |
103 #define DELEGATE_TO_WEBCONTEXT(name) \ | 82 #define DELEGATE_TO_WEBCONTEXT(name) \ |
104 void GraphicsContext3D::name() \ | 83 void GraphicsContext3D::name() \ |
105 { \ | 84 { \ |
106 m_impl->name(); \ | 85 m_impl->name(); \ |
107 } | 86 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 { \ | 138 { \ |
160 m_impl->name(a1, a2, a3, a4, a5, a6, a7); \ | 139 m_impl->name(a1, a2, a3, a4, a5, a6, a7); \ |
161 } | 140 } |
162 | 141 |
163 #define DELEGATE_TO_WEBCONTEXT_9(name, t1, t2, t3, t4, t5, t6, t7, t8, t9) \ | 142 #define DELEGATE_TO_WEBCONTEXT_9(name, t1, t2, t3, t4, t5, t6, t7, t8, t9) \ |
164 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8
a8, t9 a9) \ | 143 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8
a8, t9 a9) \ |
165 { \ | 144 { \ |
166 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ | 145 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ |
167 } | 146 } |
168 | 147 |
169 class GraphicsContext3DContextLostCallbackAdapter : public blink::WebGraphicsCon
text3D::WebGraphicsContextLostCallback { | |
170 public: | |
171 GraphicsContext3DContextLostCallbackAdapter(PassOwnPtr<GraphicsContext3D::Co
ntextLostCallback> callback) | |
172 : m_contextLostCallback(callback) { } | |
173 virtual ~GraphicsContext3DContextLostCallbackAdapter() { } | |
174 | |
175 virtual void onContextLost() | |
176 { | |
177 if (m_contextLostCallback) | |
178 m_contextLostCallback->onContextLost(); | |
179 } | |
180 private: | |
181 OwnPtr<GraphicsContext3D::ContextLostCallback> m_contextLostCallback; | |
182 }; | |
183 | |
184 class GraphicsContext3DErrorMessageCallbackAdapter : public blink::WebGraphicsCo
ntext3D::WebGraphicsErrorMessageCallback { | |
185 public: | |
186 GraphicsContext3DErrorMessageCallbackAdapter(PassOwnPtr<GraphicsContext3D::E
rrorMessageCallback> callback) | |
187 : m_errorMessageCallback(callback) { } | |
188 virtual ~GraphicsContext3DErrorMessageCallbackAdapter() { } | |
189 | |
190 virtual void onErrorMessage(const blink::WebString& message, blink::WGC3Dint
id) | |
191 { | |
192 if (m_errorMessageCallback) | |
193 m_errorMessageCallback->onErrorMessage(message, id); | |
194 } | |
195 private: | |
196 OwnPtr<GraphicsContext3D::ErrorMessageCallback> m_errorMessageCallback; | |
197 }; | |
198 | |
199 void GraphicsContext3D::setContextLostCallback(PassOwnPtr<GraphicsContext3D::Con
textLostCallback> callback) | |
200 { | |
201 if (m_ownedWebContext) { | |
202 m_contextLostCallbackAdapter = adoptPtr(new GraphicsContext3DContextLost
CallbackAdapter(callback)); | |
203 m_ownedWebContext->setContextLostCallback(m_contextLostCallbackAdapter.g
et()); | |
204 } | |
205 } | |
206 | |
207 void GraphicsContext3D::setErrorMessageCallback(PassOwnPtr<GraphicsContext3D::Er
rorMessageCallback> callback) | |
208 { | |
209 if (m_ownedWebContext) { | |
210 m_errorMessageCallbackAdapter = adoptPtr(new GraphicsContext3DErrorMessa
geCallbackAdapter(callback)); | |
211 m_ownedWebContext->setErrorMessageCallback(m_errorMessageCallbackAdapter
.get()); | |
212 } | |
213 } | |
214 | |
215 PassRefPtr<GraphicsContext3D> GraphicsContext3D::createContextSupport(blink::Web
GraphicsContext3D* webContext) | 148 PassRefPtr<GraphicsContext3D> GraphicsContext3D::createContextSupport(blink::Web
GraphicsContext3D* webContext) |
216 { | 149 { |
217 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(webContex
t)); | 150 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(webContex
t)); |
218 return context.release(); | 151 return context.release(); |
219 } | 152 } |
220 | 153 |
221 // The following three creation methods are obsolete and should not be used by n
ew code. They will be removed soon. | 154 // The following three creation methods are obsolete and should not be used by n
ew code. They will be removed soon. |
222 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attri
butes attrs) | 155 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attri
butes attrs) |
223 { | 156 { |
224 blink::WebGraphicsContext3D::Attributes webAttributes; | 157 blink::WebGraphicsContext3D::Attributes webAttributes; |
(...skipping 26 matching lines...) Expand all Loading... |
251 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(webContex
t, preserveDrawingBuffer)); | 184 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(webContex
t, preserveDrawingBuffer)); |
252 return context.release(); | 185 return context.release(); |
253 } | 186 } |
254 | 187 |
255 GrContext* GraphicsContext3D::grContext() | 188 GrContext* GraphicsContext3D::grContext() |
256 { | 189 { |
257 return m_grContext; | 190 return m_grContext; |
258 } | 191 } |
259 | 192 |
260 DELEGATE_TO_WEBCONTEXT_R(makeContextCurrent, bool) | 193 DELEGATE_TO_WEBCONTEXT_R(makeContextCurrent, bool) |
261 DELEGATE_TO_WEBCONTEXT_R(lastFlushID, uint32_t) | |
262 | 194 |
263 DELEGATE_TO_WEBCONTEXT_1(activeTexture, GLenum) | 195 DELEGATE_TO_WEBCONTEXT_1(activeTexture, GLenum) |
264 DELEGATE_TO_WEBCONTEXT_2(attachShader, Platform3DObject, Platform3DObject) | 196 DELEGATE_TO_WEBCONTEXT_2(attachShader, Platform3DObject, Platform3DObject) |
265 | 197 |
266 DELEGATE_TO_WEBCONTEXT_2(bindBuffer, GLenum, Platform3DObject) | 198 DELEGATE_TO_WEBCONTEXT_2(bindBuffer, GLenum, Platform3DObject) |
267 DELEGATE_TO_WEBCONTEXT_2(bindFramebuffer, GLenum, Platform3DObject) | 199 DELEGATE_TO_WEBCONTEXT_2(bindFramebuffer, GLenum, Platform3DObject) |
268 DELEGATE_TO_WEBCONTEXT_2(bindRenderbuffer, GLenum, Platform3DObject) | 200 DELEGATE_TO_WEBCONTEXT_2(bindRenderbuffer, GLenum, Platform3DObject) |
269 DELEGATE_TO_WEBCONTEXT_2(bindTexture, GLenum, Platform3DObject) | 201 DELEGATE_TO_WEBCONTEXT_2(bindTexture, GLenum, Platform3DObject) |
270 | 202 |
271 DELEGATE_TO_WEBCONTEXT_4(bufferData, GLenum, GLsizeiptr, const void*, GLenum) | 203 DELEGATE_TO_WEBCONTEXT_4(bufferData, GLenum, GLsizeiptr, const void*, GLenum) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 DELEGATE_TO_WEBCONTEXT_3(getProgramiv, Platform3DObject, GLenum, GLint*) | 257 DELEGATE_TO_WEBCONTEXT_3(getProgramiv, Platform3DObject, GLenum, GLint*) |
326 DELEGATE_TO_WEBCONTEXT_3(getShaderiv, Platform3DObject, GLenum, GLint*) | 258 DELEGATE_TO_WEBCONTEXT_3(getShaderiv, Platform3DObject, GLenum, GLint*) |
327 DELEGATE_TO_WEBCONTEXT_1R(getString, GLenum, String) | 259 DELEGATE_TO_WEBCONTEXT_1R(getString, GLenum, String) |
328 | 260 |
329 GLint GraphicsContext3D::getUniformLocation(Platform3DObject program, const Stri
ng& name) | 261 GLint GraphicsContext3D::getUniformLocation(Platform3DObject program, const Stri
ng& name) |
330 { | 262 { |
331 return m_impl->getUniformLocation(program, name.utf8().data()); | 263 return m_impl->getUniformLocation(program, name.utf8().data()); |
332 } | 264 } |
333 | 265 |
334 DELEGATE_TO_WEBCONTEXT_1(linkProgram, Platform3DObject) | 266 DELEGATE_TO_WEBCONTEXT_1(linkProgram, Platform3DObject) |
335 | 267 DELEGATE_TO_WEBCONTEXT_2(pixelStorei, GLenum, GLint) |
336 void GraphicsContext3D::pixelStorei(GLenum pname, GLint param) | |
337 { | |
338 if (pname == GL_PACK_ALIGNMENT) | |
339 m_packAlignment = param; | |
340 m_impl->pixelStorei(pname, param); | |
341 } | |
342 | 268 |
343 DELEGATE_TO_WEBCONTEXT_7(readPixels, GLint, GLint, GLsizei, GLsizei, GLenum, GLe
num, void*) | 269 DELEGATE_TO_WEBCONTEXT_7(readPixels, GLint, GLint, GLsizei, GLsizei, GLenum, GLe
num, void*) |
344 | 270 |
345 DELEGATE_TO_WEBCONTEXT_4(renderbufferStorage, GLenum, GLenum, GLsizei, GLsizei) | 271 DELEGATE_TO_WEBCONTEXT_4(renderbufferStorage, GLenum, GLenum, GLsizei, GLsizei) |
346 | 272 |
347 void GraphicsContext3D::shaderSource(Platform3DObject shader, const String& stri
ng) | 273 void GraphicsContext3D::shaderSource(Platform3DObject shader, const String& stri
ng) |
348 { | 274 { |
349 m_impl->shaderSource(shader, string.utf8().data()); | 275 m_impl->shaderSource(shader, string.utf8().data()); |
350 } | 276 } |
351 | 277 |
352 DELEGATE_TO_WEBCONTEXT_2(stencilMaskSeparate, GLenum, GLuint) | 278 DELEGATE_TO_WEBCONTEXT_2(stencilMaskSeparate, GLenum, GLuint) |
353 | 279 |
354 DELEGATE_TO_WEBCONTEXT_9(texImage2D, GLenum, GLint, GLenum, GLsizei, GLsizei, GL
int, GLenum, GLenum, const void*) | 280 DELEGATE_TO_WEBCONTEXT_9(texImage2D, GLenum, GLint, GLenum, GLsizei, GLsizei, GL
int, GLenum, GLenum, const void*) |
355 DELEGATE_TO_WEBCONTEXT_3(texParameteri, GLenum, GLenum, GLint) | 281 DELEGATE_TO_WEBCONTEXT_3(texParameteri, GLenum, GLenum, GLint) |
356 | 282 |
357 DELEGATE_TO_WEBCONTEXT_2(uniform1f, GLint, GLfloat) | 283 DELEGATE_TO_WEBCONTEXT_2(uniform1f, GLint, GLfloat) |
358 DELEGATE_TO_WEBCONTEXT_3(uniform1fv, GLint, GLsizei, GLfloat*) | 284 DELEGATE_TO_WEBCONTEXT_3(uniform1fv, GLint, GLsizei, GLfloat*) |
359 DELEGATE_TO_WEBCONTEXT_2(uniform1i, GLint, GLint) | 285 DELEGATE_TO_WEBCONTEXT_2(uniform1i, GLint, GLint) |
360 DELEGATE_TO_WEBCONTEXT_3(uniform2f, GLint, GLfloat, GLfloat) | 286 DELEGATE_TO_WEBCONTEXT_3(uniform2f, GLint, GLfloat, GLfloat) |
361 DELEGATE_TO_WEBCONTEXT_4(uniform3f, GLint, GLfloat, GLfloat, GLfloat) | 287 DELEGATE_TO_WEBCONTEXT_4(uniform3f, GLint, GLfloat, GLfloat, GLfloat) |
362 DELEGATE_TO_WEBCONTEXT_5(uniform4f, GLint, GLfloat, GLfloat, GLfloat, GLfloat) | 288 DELEGATE_TO_WEBCONTEXT_5(uniform4f, GLint, GLfloat, GLfloat, GLfloat, GLfloat) |
363 DELEGATE_TO_WEBCONTEXT_4(uniformMatrix4fv, GLint, GLsizei, GLboolean, GLfloat*) | 289 DELEGATE_TO_WEBCONTEXT_4(uniformMatrix4fv, GLint, GLsizei, GLboolean, GLfloat*) |
364 | 290 |
365 DELEGATE_TO_WEBCONTEXT_1(useProgram, Platform3DObject) | 291 DELEGATE_TO_WEBCONTEXT_1(useProgram, Platform3DObject) |
366 | 292 |
367 DELEGATE_TO_WEBCONTEXT_6(vertexAttribPointer, GLuint, GLint, GLenum, GLboolean,
GLsizei, GLintptr) | 293 DELEGATE_TO_WEBCONTEXT_6(vertexAttribPointer, GLuint, GLint, GLenum, GLboolean,
GLsizei, GLintptr) |
368 | 294 |
369 DELEGATE_TO_WEBCONTEXT_4(viewport, GLint, GLint, GLsizei, GLsizei) | 295 DELEGATE_TO_WEBCONTEXT_4(viewport, GLint, GLint, GLsizei, GLsizei) |
370 | 296 |
371 void GraphicsContext3D::markContextChanged() | |
372 { | |
373 m_layerComposited = false; | |
374 } | |
375 | |
376 bool GraphicsContext3D::layerComposited() const | |
377 { | |
378 return m_layerComposited; | |
379 } | |
380 | |
381 void GraphicsContext3D::markLayerComposited() | |
382 { | |
383 m_layerComposited = true; | |
384 } | |
385 | |
386 void GraphicsContext3D::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer,
DrawingBuffer* drawingBuffer) | |
387 { | |
388 Platform3DObject framebufferId; | |
389 int width, height; | |
390 getDrawingParameters(drawingBuffer, m_impl, &framebufferId, &width, &height)
; | |
391 paintFramebufferToCanvas(framebufferId, width, height, !getContextAttributes
().premultipliedAlpha, imageBuffer); | |
392 } | |
393 | |
394 PassRefPtr<Uint8ClampedArray> GraphicsContext3D::paintRenderingResultsToImageDat
a(DrawingBuffer* drawingBuffer, int& width, int& height) | |
395 { | |
396 if (getContextAttributes().premultipliedAlpha) | |
397 return 0; | |
398 | |
399 Platform3DObject framebufferId; | |
400 getDrawingParameters(drawingBuffer, m_impl, &framebufferId, &width, &height)
; | |
401 | |
402 Checked<int, RecordOverflow> dataSize = 4; | |
403 dataSize *= width; | |
404 dataSize *= height; | |
405 if (dataSize.hasOverflowed()) | |
406 return 0; | |
407 | |
408 RefPtr<Uint8ClampedArray> pixels = Uint8ClampedArray::createUninitialized(wi
dth * height * 4); | |
409 | |
410 m_impl->bindFramebuffer(GL_FRAMEBUFFER, framebufferId); | |
411 readBackFramebuffer(pixels->data(), width, height, ReadbackRGBA, AlphaDoNoth
ing); | |
412 flipVertically(pixels->data(), width, height); | |
413 | |
414 return pixels.release(); | |
415 } | |
416 | |
417 void GraphicsContext3D::readBackFramebuffer(unsigned char* pixels, int width, in
t height, ReadbackOrder readbackOrder, AlphaOp op) | |
418 { | |
419 if (m_packAlignment > 4) | |
420 m_impl->pixelStorei(GL_PACK_ALIGNMENT, 1); | |
421 m_impl->readPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | |
422 if (m_packAlignment > 4) | |
423 m_impl->pixelStorei(GL_PACK_ALIGNMENT, m_packAlignment); | |
424 | |
425 size_t bufferSize = 4 * width * height; | |
426 | |
427 if (readbackOrder == ReadbackSkia) { | |
428 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT | |
429 // Swizzle red and blue channels to match SkBitmap's byte ordering. | |
430 // TODO(kbr): expose GL_BGRA as extension. | |
431 for (size_t i = 0; i < bufferSize; i += 4) { | |
432 std::swap(pixels[i], pixels[i + 2]); | |
433 } | |
434 #endif | |
435 } | |
436 | |
437 if (op == AlphaDoPremultiply) { | |
438 for (size_t i = 0; i < bufferSize; i += 4) { | |
439 pixels[i + 0] = std::min(255, pixels[i + 0] * pixels[i + 3] / 255); | |
440 pixels[i + 1] = std::min(255, pixels[i + 1] * pixels[i + 3] / 255); | |
441 pixels[i + 2] = std::min(255, pixels[i + 2] * pixels[i + 3] / 255); | |
442 } | |
443 } else if (op != AlphaDoNothing) { | |
444 ASSERT_NOT_REACHED(); | |
445 } | |
446 } | |
447 | |
448 void GraphicsContext3D::setPackAlignment(GLint param) | |
449 { | |
450 m_packAlignment = param; | |
451 } | |
452 | |
453 DELEGATE_TO_WEBCONTEXT_R(createBuffer, Platform3DObject) | 297 DELEGATE_TO_WEBCONTEXT_R(createBuffer, Platform3DObject) |
454 DELEGATE_TO_WEBCONTEXT_R(createFramebuffer, Platform3DObject) | 298 DELEGATE_TO_WEBCONTEXT_R(createFramebuffer, Platform3DObject) |
455 DELEGATE_TO_WEBCONTEXT_R(createProgram, Platform3DObject) | 299 DELEGATE_TO_WEBCONTEXT_R(createProgram, Platform3DObject) |
456 DELEGATE_TO_WEBCONTEXT_R(createRenderbuffer, Platform3DObject) | 300 DELEGATE_TO_WEBCONTEXT_R(createRenderbuffer, Platform3DObject) |
457 DELEGATE_TO_WEBCONTEXT_1R(createShader, GLenum, Platform3DObject) | 301 DELEGATE_TO_WEBCONTEXT_1R(createShader, GLenum, Platform3DObject) |
458 DELEGATE_TO_WEBCONTEXT_R(createTexture, Platform3DObject) | 302 DELEGATE_TO_WEBCONTEXT_R(createTexture, Platform3DObject) |
459 | 303 |
460 DELEGATE_TO_WEBCONTEXT_1(deleteBuffer, Platform3DObject) | 304 DELEGATE_TO_WEBCONTEXT_1(deleteBuffer, Platform3DObject) |
461 DELEGATE_TO_WEBCONTEXT_1(deleteFramebuffer, Platform3DObject) | 305 DELEGATE_TO_WEBCONTEXT_1(deleteFramebuffer, Platform3DObject) |
462 DELEGATE_TO_WEBCONTEXT_1(deleteProgram, Platform3DObject) | 306 DELEGATE_TO_WEBCONTEXT_1(deleteProgram, Platform3DObject) |
463 DELEGATE_TO_WEBCONTEXT_1(deleteRenderbuffer, Platform3DObject) | 307 DELEGATE_TO_WEBCONTEXT_1(deleteRenderbuffer, Platform3DObject) |
464 DELEGATE_TO_WEBCONTEXT_1(deleteShader, Platform3DObject) | 308 DELEGATE_TO_WEBCONTEXT_1(deleteShader, Platform3DObject) |
465 DELEGATE_TO_WEBCONTEXT_1(deleteTexture, Platform3DObject) | 309 DELEGATE_TO_WEBCONTEXT_1(deleteTexture, Platform3DObject) |
466 | 310 |
467 DELEGATE_TO_WEBCONTEXT_1(synthesizeGLError, GLenum) | 311 DELEGATE_TO_WEBCONTEXT_1(synthesizeGLError, GLenum) |
468 | 312 |
469 bool GraphicsContext3D::texImage2DResourceSafe(GLenum target, GLint level, GLenu
m internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GL
enum type, GLint unpackAlignment) | |
470 { | |
471 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); | |
472 texImage2D(target, level, internalformat, width, height, border, format, typ
e, 0); | |
473 return true; | |
474 } | |
475 | |
476 bool GraphicsContext3D::computeFormatAndTypeParameters(GLenum format, GLenum typ
e, unsigned* componentsPerPixel, unsigned* bytesPerComponent) | 313 bool GraphicsContext3D::computeFormatAndTypeParameters(GLenum format, GLenum typ
e, unsigned* componentsPerPixel, unsigned* bytesPerComponent) |
477 { | 314 { |
478 switch (format) { | 315 switch (format) { |
479 case GL_ALPHA: | 316 case GL_ALPHA: |
480 case GL_LUMINANCE: | 317 case GL_LUMINANCE: |
481 case GL_DEPTH_COMPONENT: | 318 case GL_DEPTH_COMPONENT: |
482 case GL_DEPTH_STENCIL_OES: | 319 case GL_DEPTH_STENCIL_OES: |
483 *componentsPerPixel = 1; | 320 *componentsPerPixel = 1; |
484 break; | 321 break; |
485 case GL_LUMINANCE_ALPHA: | 322 case GL_LUMINANCE_ALPHA: |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 return ChannelDepth; | 508 return ChannelDepth; |
672 case GL_STENCIL_INDEX8: | 509 case GL_STENCIL_INDEX8: |
673 return ChannelStencil; | 510 return ChannelStencil; |
674 case GL_DEPTH_STENCIL_OES: | 511 case GL_DEPTH_STENCIL_OES: |
675 return ChannelDepth | ChannelStencil; | 512 return ChannelDepth | ChannelStencil; |
676 default: | 513 default: |
677 return 0; | 514 return 0; |
678 } | 515 } |
679 } | 516 } |
680 | 517 |
681 void GraphicsContext3D::paintFramebufferToCanvas(int framebuffer, int width, int
height, bool premultiplyAlpha, ImageBuffer* imageBuffer) | |
682 { | |
683 unsigned char* pixels = 0; | |
684 | |
685 const SkBitmap* canvasBitmap = imageBuffer->context()->bitmap(); | |
686 const SkBitmap* readbackBitmap = 0; | |
687 ASSERT(canvasBitmap->config() == SkBitmap::kARGB_8888_Config); | |
688 if (canvasBitmap->width() == width && canvasBitmap->height() == height) { | |
689 // This is the fastest and most common case. We read back | |
690 // directly into the canvas's backing store. | |
691 readbackBitmap = canvasBitmap; | |
692 m_resizingBitmap.reset(); | |
693 } else { | |
694 // We need to allocate a temporary bitmap for reading back the | |
695 // pixel data. We will then use Skia to rescale this bitmap to | |
696 // the size of the canvas's backing store. | |
697 if (m_resizingBitmap.width() != width || m_resizingBitmap.height() != he
ight) { | |
698 m_resizingBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, heigh
t); | |
699 if (!m_resizingBitmap.allocPixels()) | |
700 return; | |
701 } | |
702 readbackBitmap = &m_resizingBitmap; | |
703 } | |
704 | |
705 // Read back the frame buffer. | |
706 SkAutoLockPixels bitmapLock(*readbackBitmap); | |
707 pixels = static_cast<unsigned char*>(readbackBitmap->getPixels()); | |
708 | |
709 m_impl->bindFramebuffer(GL_FRAMEBUFFER, framebuffer); | |
710 readBackFramebuffer(pixels, width, height, ReadbackSkia, premultiplyAlpha ?
AlphaDoPremultiply : AlphaDoNothing); | |
711 flipVertically(pixels, width, height); | |
712 | |
713 readbackBitmap->notifyPixelsChanged(); | |
714 if (m_resizingBitmap.readyToDraw()) { | |
715 // We need to draw the resizing bitmap into the canvas's backing store. | |
716 SkCanvas canvas(*canvasBitmap); | |
717 SkRect dst; | |
718 dst.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(canvasBitmap->
width()), SkIntToScalar(canvasBitmap->height())); | |
719 canvas.drawBitmapRect(m_resizingBitmap, 0, dst); | |
720 } | |
721 } | |
722 | |
723 namespace { | 518 namespace { |
724 | 519 |
725 void splitStringHelper(const String& str, HashSet<String>& set) | 520 void splitStringHelper(const String& str, HashSet<String>& set) |
726 { | 521 { |
727 Vector<String> substrings; | 522 Vector<String> substrings; |
728 str.split(" ", substrings); | 523 str.split(" ", substrings); |
729 for (size_t i = 0; i < substrings.size(); ++i) | 524 for (size_t i = 0; i < substrings.size(); ++i) |
730 set.add(substrings[i]); | 525 set.add(substrings[i]); |
731 } | 526 } |
732 | 527 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 { | 592 { |
798 // FIXME: restriction of (RGB || RGBA)/UNSIGNED_BYTE/(Level 0) should be lif
ted when | 593 // FIXME: restriction of (RGB || RGBA)/UNSIGNED_BYTE/(Level 0) should be lif
ted when |
799 // WebGraphicsContext3D::copyTextureCHROMIUM(...) are fully functional. | 594 // WebGraphicsContext3D::copyTextureCHROMIUM(...) are fully functional. |
800 if ((destFormat == GL_RGB || destFormat == GL_RGBA) | 595 if ((destFormat == GL_RGB || destFormat == GL_RGBA) |
801 && destType == GL_UNSIGNED_BYTE | 596 && destType == GL_UNSIGNED_BYTE |
802 && !level) | 597 && !level) |
803 return true; | 598 return true; |
804 return false; | 599 return false; |
805 } | 600 } |
806 | 601 |
807 void GraphicsContext3D::flipVertically(uint8_t* framebuffer, int width, int heig
ht) | |
808 { | |
809 m_scanline.resize(width * 4); | |
810 uint8* scanline = &m_scanline[0]; | |
811 unsigned rowBytes = width * 4; | |
812 unsigned count = height / 2; | |
813 for (unsigned i = 0; i < count; i++) { | |
814 uint8* rowA = framebuffer + i * rowBytes; | |
815 uint8* rowB = framebuffer + (height - i - 1) * rowBytes; | |
816 memcpy(scanline, rowB, rowBytes); | |
817 memcpy(rowB, rowA, rowBytes); | |
818 memcpy(rowA, scanline, rowBytes); | |
819 } | |
820 } | |
821 | |
822 } // namespace WebCore | 602 } // namespace WebCore |
OLD | NEW |