Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: Source/core/platform/graphics/GraphicsContext3DImagePacking.cpp

Issue 15501004: Moved image packing code out of GraphicsContext3D.cpp and into a new file (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/platform/graphics/GraphicsContext3D.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Copyright (C) 2010 Mozilla Corporation. All rights reserved. 3 * Copyright (C) 2010 Mozilla Corporation. All rights reserved.
5 * 4 *
6 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
8 * are met: 7 * are met:
9 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
14 * 13 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 25 */
27 26
28 #include "config.h" 27 #include "config.h"
29
30 #include "core/platform/graphics/GraphicsContext3D.h" 28 #include "core/platform/graphics/GraphicsContext3D.h"
31 29
32 #include "GrContext.h"
33 #include "GrGLInterface.h"
34 #include "SkTypes.h"
35 #include "core/html/ImageData.h" 30 #include "core/html/ImageData.h"
36 #include "core/html/canvas/CheckedInt.h" 31 #include "core/html/canvas/CheckedInt.h"
37 #include "core/platform/graphics/Extensions3D.h"
38 #include "core/platform/graphics/GraphicsContext.h"
39 #include "core/platform/graphics/Image.h"
40 #include "core/platform/graphics/ImageBuffer.h"
41 #include "core/platform/graphics/ImageObserver.h" 32 #include "core/platform/graphics/ImageObserver.h"
42 #include "core/platform/graphics/cpu/arm/GraphicsContext3DNEON.h"
43 #include "core/platform/graphics/gpu/DrawingBuffer.h"
44 #include "core/platform/image-decoders/ImageDecoder.h" 33 #include "core/platform/image-decoders/ImageDecoder.h"
45 #include "wtf/ArrayBufferView.h"
46 #include "wtf/CPU.h"
47 #include "wtf/OwnArrayPtr.h"
48 #include "wtf/PassOwnArrayPtr.h"
49 #include "wtf/text/CString.h"
50 #include "wtf/text/StringHash.h"
51 #include "wtf/text/WTFString.h"
52
53 #include <public/Platform.h>
54 #include <public/WebGraphicsContext3D.h>
55 #include <public/WebGraphicsContext3DProvider.h>
56 #include <public/WebGraphicsMemoryAllocation.h>
57
58 namespace {
59
60 // The limit of the number of textures we hold in the GrContext's bitmap->textur e cache.
61 const int maxGaneshTextureCacheCount = 2048;
62 // The limit of the bytes allocated toward textures in the GrContext's bitmap->t exture cache.
63 const size_t maxGaneshTextureCacheBytes = 96 * 1024 * 1024;
64
65 }
66 34
67 namespace WebCore { 35 namespace WebCore {
68 36
69 namespace { 37 namespace {
70 38
71 GraphicsContext3D::DataFormat getDataFormat(GC3Denum destinationFormat, GC3Denum destinationType) 39 GraphicsContext3D::DataFormat getDataFormat(GC3Denum destinationFormat, GC3Denum destinationType)
72 { 40 {
73 GraphicsContext3D::DataFormat dstFormat = GraphicsContext3D::DataFormatRGBA8 ; 41 GraphicsContext3D::DataFormat dstFormat = GraphicsContext3D::DataFormatRGBA8 ;
74 switch (destinationType) { 42 switch (destinationType) {
75 case GraphicsContext3D::UNSIGNED_BYTE: 43 case GraphicsContext3D::UNSIGNED_BYTE:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 default: 111 default:
144 ASSERT_NOT_REACHED(); 112 ASSERT_NOT_REACHED();
145 } 113 }
146 break; 114 break;
147 default: 115 default:
148 ASSERT_NOT_REACHED(); 116 ASSERT_NOT_REACHED();
149 } 117 }
150 return dstFormat; 118 return dstFormat;
151 } 119 }
152 120
153 void getDrawingParameters(DrawingBuffer* drawingBuffer, WebKit::WebGraphicsConte xt3D* graphicsContext3D,
154 Platform3DObject* frameBufferId, int* width, int* heig ht)
155 {
156 if (drawingBuffer) {
157 *frameBufferId = drawingBuffer->framebuffer();
158 *width = drawingBuffer->size().width();
159 *height = drawingBuffer->size().height();
160 } else {
161 *frameBufferId = 0;
162 *width = graphicsContext3D->width();
163 *height = graphicsContext3D->height();
164 }
165 }
166
167 // Following Float to Half-Float converion code is from the implementation of ft p://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf, 121 // Following Float to Half-Float converion code is from the implementation of ft p://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf,
168 // "Fast Half Float Conversions" by Jeroen van der Zijp, November 2008 (Revised September 2010). 122 // "Fast Half Float Conversions" by Jeroen van der Zijp, November 2008 (Revised September 2010).
169 // Specially, the basetable[512] and shifttable[512] are generated as follows: 123 // Specially, the basetable[512] and shifttable[512] are generated as follows:
170 /* 124 /*
171 unsigned short basetable[512]; 125 unsigned short basetable[512];
172 unsigned char shifttable[512]; 126 unsigned char shifttable[512];
173 127
174 void generatetables(){ 128 void generatetables(){
175 unsigned int i; 129 unsigned int i;
176 int e; 130 int e;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13 234 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13
281 }; 235 };
282 236
283 unsigned short convertFloatToHalfFloat(float f) 237 unsigned short convertFloatToHalfFloat(float f)
284 { 238 {
285 unsigned temp = *(reinterpret_cast<unsigned *>(&f)); 239 unsigned temp = *(reinterpret_cast<unsigned *>(&f));
286 unsigned signexp = (temp >> 23) & 0x1ff; 240 unsigned signexp = (temp >> 23) & 0x1ff;
287 return baseTable[signexp] + ((temp & 0x007fffff) >> shiftTable[signexp]); 241 return baseTable[signexp] + ((temp & 0x007fffff) >> shiftTable[signexp]);
288 } 242 }
289 243
290 } // anonymous namespace
291
292 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<WebKit::WebGraphicsContext3D> we bContext, bool preserveDrawingBuffer)
293 : m_impl(webContext.get())
294 , m_ownedWebContext(webContext)
295 , m_initializedAvailableExtensions(false)
296 , m_layerComposited(false)
297 , m_preserveDrawingBuffer(preserveDrawingBuffer)
298 , m_resourceSafety(ResourceSafetyUnknown)
299 , m_grContext(0)
300 {
301 }
302
303 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<WebKit::WebGraphicsContext3DProv ider> provider, bool preserveDrawingBuffer)
304 : m_provider(provider)
305 , m_impl(m_provider->context3d())
306 , m_initializedAvailableExtensions(false)
307 , m_layerComposited(false)
308 , m_preserveDrawingBuffer(preserveDrawingBuffer)
309 , m_resourceSafety(ResourceSafetyUnknown)
310 , m_grContext(m_provider->grContext())
311 {
312 }
313
314 GraphicsContext3D::~GraphicsContext3D()
315 {
316 setContextLostCallback(nullptr);
317 setErrorMessageCallback(nullptr);
318
319 if (m_ownedGrContext) {
320 m_ownedWebContext->setMemoryAllocationChangedCallbackCHROMIUM(0);
321 m_ownedGrContext->contextDestroyed();
322 }
323 }
324
325 // Macros to assist in delegating from GraphicsContext3D to
326 // WebGraphicsContext3D.
327
328 #define DELEGATE_TO_WEBCONTEXT(name) \
329 void GraphicsContext3D::name() \
330 { \
331 m_impl->name(); \
332 }
333
334 #define DELEGATE_TO_WEBCONTEXT_R(name, rt) \
335 rt GraphicsContext3D::name() \
336 { \
337 return m_impl->name(); \
338 }
339
340 #define DELEGATE_TO_WEBCONTEXT_1(name, t1) \
341 void GraphicsContext3D::name(t1 a1) \
342 { \
343 m_impl->name(a1); \
344 }
345
346 #define DELEGATE_TO_WEBCONTEXT_1R(name, t1, rt) \
347 rt GraphicsContext3D::name(t1 a1) \
348 { \
349 return m_impl->name(a1); \
350 }
351
352 #define DELEGATE_TO_WEBCONTEXT_2(name, t1, t2) \
353 void GraphicsContext3D::name(t1 a1, t2 a2) \
354 { \
355 m_impl->name(a1, a2); \
356 }
357
358 #define DELEGATE_TO_WEBCONTEXT_2R(name, t1, t2, rt) \
359 rt GraphicsContext3D::name(t1 a1, t2 a2) \
360 { \
361 return m_impl->name(a1, a2); \
362 }
363
364 #define DELEGATE_TO_WEBCONTEXT_3(name, t1, t2, t3) \
365 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \
366 { \
367 m_impl->name(a1, a2, a3); \
368 }
369
370 #define DELEGATE_TO_WEBCONTEXT_3R(name, t1, t2, t3, rt) \
371 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \
372 { \
373 return m_impl->name(a1, a2, a3); \
374 }
375
376 #define DELEGATE_TO_WEBCONTEXT_4(name, t1, t2, t3, t4) \
377 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \
378 { \
379 m_impl->name(a1, a2, a3, a4); \
380 }
381
382 #define DELEGATE_TO_WEBCONTEXT_4R(name, t1, t2, t3, t4, rt) \
383 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \
384 { \
385 return m_impl->name(a1, a2, a3, a4); \
386 }
387
388 #define DELEGATE_TO_WEBCONTEXT_5(name, t1, t2, t3, t4, t5) \
389 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) \
390 { \
391 m_impl->name(a1, a2, a3, a4, a5); \
392 }
393
394 #define DELEGATE_TO_WEBCONTEXT_6(name, t1, t2, t3, t4, t5, t6) \
395 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
396 { \
397 m_impl->name(a1, a2, a3, a4, a5, a6); \
398 }
399
400 #define DELEGATE_TO_WEBCONTEXT_6R(name, t1, t2, t3, t4, t5, t6, rt) \
401 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \
402 { \
403 return m_impl->name(a1, a2, a3, a4, a5, a6); \
404 }
405
406 #define DELEGATE_TO_WEBCONTEXT_7(name, t1, t2, t3, t4, t5, t6, t7) \
407 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
408 { \
409 m_impl->name(a1, a2, a3, a4, a5, a6, a7); \
410 }
411
412 #define DELEGATE_TO_WEBCONTEXT_7R(name, t1, t2, t3, t4, t5, t6, t7, rt) \
413 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \
414 { \
415 return m_impl->name(a1, a2, a3, a4, a5, a6, a7); \
416 }
417
418 #define DELEGATE_TO_WEBCONTEXT_8(name, t1, t2, t3, t4, t5, t6, t7, t8) \
419 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8) \
420 { \
421 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8); \
422 }
423
424 #define DELEGATE_TO_WEBCONTEXT_9(name, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
425 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a8, t9 a9) \
426 { \
427 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
428 }
429
430 #define DELEGATE_TO_WEBCONTEXT_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt) \
431 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a 8, t9 a9) \
432 { \
433 return m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
434 }
435
436 class GraphicsContext3DContextLostCallbackAdapter : public WebKit::WebGraphicsCo ntext3D::WebGraphicsContextLostCallback {
437 public:
438 GraphicsContext3DContextLostCallbackAdapter(PassOwnPtr<GraphicsContext3D::Co ntextLostCallback> callback)
439 : m_contextLostCallback(callback) { }
440 virtual ~GraphicsContext3DContextLostCallbackAdapter() { }
441
442 virtual void onContextLost()
443 {
444 if (m_contextLostCallback)
445 m_contextLostCallback->onContextLost();
446 }
447 private:
448 OwnPtr<GraphicsContext3D::ContextLostCallback> m_contextLostCallback;
449 };
450
451 class GraphicsContext3DErrorMessageCallbackAdapter : public WebKit::WebGraphicsC ontext3D::WebGraphicsErrorMessageCallback {
452 public:
453 GraphicsContext3DErrorMessageCallbackAdapter(PassOwnPtr<GraphicsContext3D::E rrorMessageCallback> callback)
454 : m_errorMessageCallback(callback) { }
455 virtual ~GraphicsContext3DErrorMessageCallbackAdapter() { }
456
457 virtual void onErrorMessage(const WebKit::WebString& message, WebKit::WGC3Di nt id)
458 {
459 if (m_errorMessageCallback)
460 m_errorMessageCallback->onErrorMessage(message, id);
461 }
462 private:
463 OwnPtr<GraphicsContext3D::ErrorMessageCallback> m_errorMessageCallback;
464 };
465
466 void GraphicsContext3D::setContextLostCallback(PassOwnPtr<GraphicsContext3D::Con textLostCallback> callback)
467 {
468 if (m_ownedWebContext) {
469 m_contextLostCallbackAdapter = adoptPtr(new GraphicsContext3DContextLost CallbackAdapter(callback));
470 m_ownedWebContext->setContextLostCallback(m_contextLostCallbackAdapter.g et());
471 }
472 }
473
474 void GraphicsContext3D::setErrorMessageCallback(PassOwnPtr<GraphicsContext3D::Er rorMessageCallback> callback)
475 {
476 if (m_ownedWebContext) {
477 m_errorMessageCallbackAdapter = adoptPtr(new GraphicsContext3DErrorMessa geCallbackAdapter(callback));
478 m_ownedWebContext->setErrorMessageCallback(m_errorMessageCallbackAdapter .get());
479 }
480 }
481
482 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attri butes attrs)
483 {
484 WebKit::WebGraphicsContext3D::Attributes webAttributes;
485 webAttributes.alpha = attrs.alpha;
486 webAttributes.depth = attrs.depth;
487 webAttributes.stencil = attrs.stencil;
488 webAttributes.antialias = attrs.antialias;
489 webAttributes.premultipliedAlpha = attrs.premultipliedAlpha;
490 webAttributes.noExtensions = attrs.noExtensions;
491 webAttributes.shareResources = attrs.shareResources;
492 webAttributes.preferDiscreteGPU = attrs.preferDiscreteGPU;
493 webAttributes.topDocumentURL = attrs.topDocumentURL.string();
494
495 OwnPtr<WebKit::WebGraphicsContext3D> webContext = adoptPtr(WebKit::Platform: :current()->createOffscreenGraphicsContext3D(webAttributes));
496 if (!webContext)
497 return 0;
498
499 return GraphicsContext3D::createGraphicsContextFromWebContext(webContext.rel ease(), attrs.preserveDrawingBuffer);
500 }
501
502 PassRefPtr<GraphicsContext3D> GraphicsContext3D::createGraphicsContextFromProvid er(PassOwnPtr<WebKit::WebGraphicsContext3DProvider> provider, bool preserveDrawi ngBuffer)
503 {
504 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(provider, preserveDrawingBuffer));
505 return context.release();
506 }
507
508 PassRefPtr<GraphicsContext3D> GraphicsContext3D::createGraphicsContextFromWebCon text(PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, bool preserveDrawingBu ffer)
509 {
510 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(webContex t, preserveDrawingBuffer));
511 return context.release();
512 }
513
514 class GrMemoryAllocationChangedCallbackAdapter : public WebKit::WebGraphicsConte xt3D::WebGraphicsMemoryAllocationChangedCallbackCHROMIUM {
515 public:
516 GrMemoryAllocationChangedCallbackAdapter(GrContext* context)
517 : m_context(context)
518 {
519 }
520
521 virtual void onMemoryAllocationChanged(WebKit::WebGraphicsMemoryAllocation a llocation) OVERRIDE
522 {
523 if (!m_context)
524 return;
525
526 if (!allocation.gpuResourceSizeInBytes) {
527 m_context->freeGpuResources();
528 m_context->setTextureCacheLimits(0, 0);
529 } else
530 m_context->setTextureCacheLimits(maxGaneshTextureCacheCount, maxGane shTextureCacheBytes);
531 }
532
533 private:
534 GrContext* m_context;
535 };
536
537 namespace {
538 void bindWebGraphicsContext3DGLContextCallback(const GrGLInterface* interface)
539 {
540 reinterpret_cast<WebKit::WebGraphicsContext3D*>(interface->fCallbackData)->m akeContextCurrent();
541 }
542 }
543
544 GrContext* GraphicsContext3D::grContext()
545 {
546 if (m_grContext)
547 return m_grContext;
548 if (!m_ownedWebContext)
549 return 0;
550
551 SkAutoTUnref<GrGLInterface> interface(m_ownedWebContext->createGrGLInterface ());
552 if (!interface)
553 return 0;
554
555 interface->fCallback = bindWebGraphicsContext3DGLContextCallback;
556 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(m_own edWebContext.get());
557
558 m_ownedGrContext.reset(GrContext::Create(kOpenGL_GrBackend, reinterpret_cast <GrBackendContext>(interface.get())));
559 m_grContext = m_ownedGrContext;
560 if (!m_grContext)
561 return 0;
562
563 m_grContext->setTextureCacheLimits(maxGaneshTextureCacheCount, maxGaneshText ureCacheBytes);
564 m_grContextMemoryAllocationCallbackAdapter = adoptPtr(new GrMemoryAllocation ChangedCallbackAdapter(m_grContext));
565 m_ownedWebContext->setMemoryAllocationChangedCallbackCHROMIUM(m_grContextMem oryAllocationCallbackAdapter.get());
566
567 return m_grContext;
568 }
569
570 DELEGATE_TO_WEBCONTEXT_R(makeContextCurrent, bool)
571
572 bool GraphicsContext3D::isResourceSafe()
573 {
574 if (m_resourceSafety == ResourceSafetyUnknown)
575 m_resourceSafety = getExtensions()->isEnabled("GL_CHROMIUM_resource_safe ") ? ResourceSafe : ResourceUnsafe;
576 return m_resourceSafety == ResourceSafe;
577 }
578
579 DELEGATE_TO_WEBCONTEXT_1(activeTexture, GC3Denum)
580 DELEGATE_TO_WEBCONTEXT_2(attachShader, Platform3DObject, Platform3DObject)
581
582 void GraphicsContext3D::bindAttribLocation(Platform3DObject program, GC3Duint in dex, const String& name)
583 {
584 m_impl->bindAttribLocation(program, index, name.utf8().data());
585 }
586
587 DELEGATE_TO_WEBCONTEXT_2(bindBuffer, GC3Denum, Platform3DObject)
588 DELEGATE_TO_WEBCONTEXT_2(bindFramebuffer, GC3Denum, Platform3DObject)
589 DELEGATE_TO_WEBCONTEXT_2(bindRenderbuffer, GC3Denum, Platform3DObject)
590 DELEGATE_TO_WEBCONTEXT_2(bindTexture, GC3Denum, Platform3DObject)
591 DELEGATE_TO_WEBCONTEXT_4(blendColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dcla mpf)
592 DELEGATE_TO_WEBCONTEXT_1(blendEquation, GC3Denum)
593 DELEGATE_TO_WEBCONTEXT_2(blendEquationSeparate, GC3Denum, GC3Denum)
594 DELEGATE_TO_WEBCONTEXT_2(blendFunc, GC3Denum, GC3Denum)
595 DELEGATE_TO_WEBCONTEXT_4(blendFuncSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Den um)
596
597 void GraphicsContext3D::bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage)
598 {
599 bufferData(target, size, 0, usage);
600 }
601
602 DELEGATE_TO_WEBCONTEXT_4(bufferData, GC3Denum, GC3Dsizeiptr, const void*, GC3Den um)
603 DELEGATE_TO_WEBCONTEXT_4(bufferSubData, GC3Denum, GC3Dintptr, GC3Dsizeiptr, cons t void*)
604
605 DELEGATE_TO_WEBCONTEXT_1R(checkFramebufferStatus, GC3Denum, GC3Denum)
606 DELEGATE_TO_WEBCONTEXT_1(clear, GC3Dbitfield)
607 DELEGATE_TO_WEBCONTEXT_4(clearColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dcla mpf)
608 DELEGATE_TO_WEBCONTEXT_1(clearDepth, GC3Dclampf)
609 DELEGATE_TO_WEBCONTEXT_1(clearStencil, GC3Dint)
610 DELEGATE_TO_WEBCONTEXT_4(colorMask, GC3Dboolean, GC3Dboolean, GC3Dboolean, GC3Db oolean)
611 DELEGATE_TO_WEBCONTEXT_1(compileShader, Platform3DObject)
612
613 DELEGATE_TO_WEBCONTEXT_8(compressedTexImage2D, GC3Denum, GC3Dint, GC3Denum, GC3D int, GC3Dint, GC3Dsizei, GC3Dsizei, const void*)
614 DELEGATE_TO_WEBCONTEXT_9(compressedTexSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC 3Dint, GC3Dint, GC3Dint, GC3Denum, GC3Dsizei, const void*)
615 DELEGATE_TO_WEBCONTEXT_8(copyTexImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dint, G C3Dint, GC3Dsizei, GC3Dsizei, GC3Dint)
616 DELEGATE_TO_WEBCONTEXT_8(copyTexSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
617 DELEGATE_TO_WEBCONTEXT_1(cullFace, GC3Denum)
618 DELEGATE_TO_WEBCONTEXT_1(depthFunc, GC3Denum)
619 DELEGATE_TO_WEBCONTEXT_1(depthMask, GC3Dboolean)
620 DELEGATE_TO_WEBCONTEXT_2(depthRange, GC3Dclampf, GC3Dclampf)
621 DELEGATE_TO_WEBCONTEXT_2(detachShader, Platform3DObject, Platform3DObject)
622 DELEGATE_TO_WEBCONTEXT_1(disable, GC3Denum)
623 DELEGATE_TO_WEBCONTEXT_1(disableVertexAttribArray, GC3Duint)
624 DELEGATE_TO_WEBCONTEXT_3(drawArrays, GC3Denum, GC3Dint, GC3Dsizei)
625 DELEGATE_TO_WEBCONTEXT_4(drawElements, GC3Denum, GC3Dsizei, GC3Denum, GC3Dintptr )
626
627 DELEGATE_TO_WEBCONTEXT_1(enable, GC3Denum)
628 DELEGATE_TO_WEBCONTEXT_1(enableVertexAttribArray, GC3Duint)
629 DELEGATE_TO_WEBCONTEXT(finish)
630 DELEGATE_TO_WEBCONTEXT(flush)
631 DELEGATE_TO_WEBCONTEXT_4(framebufferRenderbuffer, GC3Denum, GC3Denum, GC3Denum, Platform3DObject)
632 DELEGATE_TO_WEBCONTEXT_5(framebufferTexture2D, GC3Denum, GC3Denum, GC3Denum, Pla tform3DObject, GC3Dint)
633 DELEGATE_TO_WEBCONTEXT_1(frontFace, GC3Denum)
634 DELEGATE_TO_WEBCONTEXT_1(generateMipmap, GC3Denum)
635
636 bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, GC3Duint index , ActiveInfo& info)
637 {
638 WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
639 if (!m_impl->getActiveAttrib(program, index, webInfo))
640 return false;
641 info.name = webInfo.name;
642 info.type = webInfo.type;
643 info.size = webInfo.size;
644 return true;
645 }
646
647 bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint inde x, ActiveInfo& info)
648 {
649 WebKit::WebGraphicsContext3D::ActiveInfo webInfo;
650 if (!m_impl->getActiveUniform(program, index, webInfo))
651 return false;
652 info.name = webInfo.name;
653 info.type = webInfo.type;
654 info.size = webInfo.size;
655 return true;
656 }
657
658 DELEGATE_TO_WEBCONTEXT_4(getAttachedShaders, Platform3DObject, GC3Dsizei, GC3Dsi zei*, Platform3DObject*)
659
660 GC3Dint GraphicsContext3D::getAttribLocation(Platform3DObject program, const Str ing& name)
661 {
662 return m_impl->getAttribLocation(program, name.utf8().data());
663 }
664
665 DELEGATE_TO_WEBCONTEXT_2(getBooleanv, GC3Denum, GC3Dboolean*)
666 DELEGATE_TO_WEBCONTEXT_3(getBufferParameteriv, GC3Denum, GC3Denum, GC3Dint*)
667
668 GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes()
669 {
670 WebKit::WebGraphicsContext3D::Attributes webAttributes = m_impl->getContextA ttributes();
671 GraphicsContext3D::Attributes attributes;
672 attributes.alpha = webAttributes.alpha;
673 attributes.depth = webAttributes.depth;
674 attributes.stencil = webAttributes.stencil;
675 attributes.antialias = webAttributes.antialias;
676 attributes.premultipliedAlpha = webAttributes.premultipliedAlpha;
677 attributes.preserveDrawingBuffer = m_preserveDrawingBuffer;
678 attributes.preferDiscreteGPU = webAttributes.preferDiscreteGPU;
679 return attributes;
680 }
681
682 DELEGATE_TO_WEBCONTEXT_R(getError, GC3Denum)
683 DELEGATE_TO_WEBCONTEXT_2(getFloatv, GC3Denum, GC3Dfloat*)
684 DELEGATE_TO_WEBCONTEXT_4(getFramebufferAttachmentParameteriv, GC3Denum, GC3Denum , GC3Denum, GC3Dint*)
685 DELEGATE_TO_WEBCONTEXT_2(getIntegerv, GC3Denum, GC3Dint*)
686 DELEGATE_TO_WEBCONTEXT_3(getProgramiv, Platform3DObject, GC3Denum, GC3Dint*)
687 DELEGATE_TO_WEBCONTEXT_1R(getProgramInfoLog, Platform3DObject, String)
688 DELEGATE_TO_WEBCONTEXT_3(getRenderbufferParameteriv, GC3Denum, GC3Denum, GC3Dint *)
689 DELEGATE_TO_WEBCONTEXT_3(getShaderiv, Platform3DObject, GC3Denum, GC3Dint*)
690 DELEGATE_TO_WEBCONTEXT_1R(getShaderInfoLog, Platform3DObject, String)
691 DELEGATE_TO_WEBCONTEXT_4(getShaderPrecisionFormat, GC3Denum, GC3Denum, GC3Dint*, GC3Dint*)
692 DELEGATE_TO_WEBCONTEXT_1R(getShaderSource, Platform3DObject, String)
693 DELEGATE_TO_WEBCONTEXT_1R(getString, GC3Denum, String)
694 DELEGATE_TO_WEBCONTEXT_3(getTexParameterfv, GC3Denum, GC3Denum, GC3Dfloat*)
695 DELEGATE_TO_WEBCONTEXT_3(getTexParameteriv, GC3Denum, GC3Denum, GC3Dint*)
696 DELEGATE_TO_WEBCONTEXT_3(getUniformfv, Platform3DObject, GC3Dint, GC3Dfloat*)
697 DELEGATE_TO_WEBCONTEXT_3(getUniformiv, Platform3DObject, GC3Dint, GC3Dint*)
698
699 GC3Dint GraphicsContext3D::getUniformLocation(Platform3DObject program, const St ring& name)
700 {
701 return m_impl->getUniformLocation(program, name.utf8().data());
702 }
703
704 DELEGATE_TO_WEBCONTEXT_3(getVertexAttribfv, GC3Duint, GC3Denum, GC3Dfloat*)
705 DELEGATE_TO_WEBCONTEXT_3(getVertexAttribiv, GC3Duint, GC3Denum, GC3Dint*)
706 DELEGATE_TO_WEBCONTEXT_2R(getVertexAttribOffset, GC3Duint, GC3Denum, GC3Dsizeipt r)
707
708 DELEGATE_TO_WEBCONTEXT_2(hint, GC3Denum, GC3Denum)
709 DELEGATE_TO_WEBCONTEXT_1R(isBuffer, Platform3DObject, GC3Dboolean)
710 DELEGATE_TO_WEBCONTEXT_1R(isEnabled, GC3Denum, GC3Dboolean)
711 DELEGATE_TO_WEBCONTEXT_1R(isFramebuffer, Platform3DObject, GC3Dboolean)
712 DELEGATE_TO_WEBCONTEXT_1R(isProgram, Platform3DObject, GC3Dboolean)
713 DELEGATE_TO_WEBCONTEXT_1R(isRenderbuffer, Platform3DObject, GC3Dboolean)
714 DELEGATE_TO_WEBCONTEXT_1R(isShader, Platform3DObject, GC3Dboolean)
715 DELEGATE_TO_WEBCONTEXT_1R(isTexture, Platform3DObject, GC3Dboolean)
716 DELEGATE_TO_WEBCONTEXT_1(lineWidth, GC3Dfloat)
717 DELEGATE_TO_WEBCONTEXT_1(linkProgram, Platform3DObject)
718 DELEGATE_TO_WEBCONTEXT_2(pixelStorei, GC3Denum, GC3Dint)
719 DELEGATE_TO_WEBCONTEXT_2(polygonOffset, GC3Dfloat, GC3Dfloat)
720
721 DELEGATE_TO_WEBCONTEXT_7(readPixels, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3 Denum, GC3Denum, void*)
722
723 DELEGATE_TO_WEBCONTEXT(releaseShaderCompiler)
724 DELEGATE_TO_WEBCONTEXT_4(renderbufferStorage, GC3Denum, GC3Denum, GC3Dsizei, GC3 Dsizei)
725 DELEGATE_TO_WEBCONTEXT_2(sampleCoverage, GC3Dclampf, GC3Dboolean)
726 DELEGATE_TO_WEBCONTEXT_4(scissor, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
727
728 void GraphicsContext3D::shaderSource(Platform3DObject shader, const String& stri ng)
729 {
730 m_impl->shaderSource(shader, string.utf8().data());
731 }
732
733 DELEGATE_TO_WEBCONTEXT_3(stencilFunc, GC3Denum, GC3Dint, GC3Duint)
734 DELEGATE_TO_WEBCONTEXT_4(stencilFuncSeparate, GC3Denum, GC3Denum, GC3Dint, GC3Du int)
735 DELEGATE_TO_WEBCONTEXT_1(stencilMask, GC3Duint)
736 DELEGATE_TO_WEBCONTEXT_2(stencilMaskSeparate, GC3Denum, GC3Duint)
737 DELEGATE_TO_WEBCONTEXT_3(stencilOp, GC3Denum, GC3Denum, GC3Denum)
738 DELEGATE_TO_WEBCONTEXT_4(stencilOpSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Den um)
739
740 DELEGATE_TO_WEBCONTEXT_9(texImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dsizei, GC3 Dsizei, GC3Dint, GC3Denum, GC3Denum, const void*)
741 DELEGATE_TO_WEBCONTEXT_3(texParameterf, GC3Denum, GC3Denum, GC3Dfloat)
742 DELEGATE_TO_WEBCONTEXT_3(texParameteri, GC3Denum, GC3Denum, GC3Dint)
743 DELEGATE_TO_WEBCONTEXT_9(texSubImage2D, GC3Denum, GC3Dint, GC3Dint, GC3Dint, GC3 Dsizei, GC3Dsizei, GC3Denum, GC3Denum, const void*)
744
745 DELEGATE_TO_WEBCONTEXT_2(uniform1f, GC3Dint, GC3Dfloat)
746 DELEGATE_TO_WEBCONTEXT_3(uniform1fv, GC3Dint, GC3Dsizei, GC3Dfloat*)
747 DELEGATE_TO_WEBCONTEXT_2(uniform1i, GC3Dint, GC3Dint)
748 DELEGATE_TO_WEBCONTEXT_3(uniform1iv, GC3Dint, GC3Dsizei, GC3Dint*)
749 DELEGATE_TO_WEBCONTEXT_3(uniform2f, GC3Dint, GC3Dfloat, GC3Dfloat)
750 DELEGATE_TO_WEBCONTEXT_3(uniform2fv, GC3Dint, GC3Dsizei, GC3Dfloat*)
751 DELEGATE_TO_WEBCONTEXT_3(uniform2i, GC3Dint, GC3Dint, GC3Dint)
752 DELEGATE_TO_WEBCONTEXT_3(uniform2iv, GC3Dint, GC3Dsizei, GC3Dint*)
753 DELEGATE_TO_WEBCONTEXT_4(uniform3f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat)
754 DELEGATE_TO_WEBCONTEXT_3(uniform3fv, GC3Dint, GC3Dsizei, GC3Dfloat*)
755 DELEGATE_TO_WEBCONTEXT_4(uniform3i, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
756 DELEGATE_TO_WEBCONTEXT_3(uniform3iv, GC3Dint, GC3Dsizei, GC3Dint*)
757 DELEGATE_TO_WEBCONTEXT_5(uniform4f, GC3Dint, GC3Dfloat, GC3Dfloat, GC3Dfloat, GC 3Dfloat)
758 DELEGATE_TO_WEBCONTEXT_3(uniform4fv, GC3Dint, GC3Dsizei, GC3Dfloat*)
759 DELEGATE_TO_WEBCONTEXT_5(uniform4i, GC3Dint, GC3Dint, GC3Dint, GC3Dint, GC3Dint)
760 DELEGATE_TO_WEBCONTEXT_3(uniform4iv, GC3Dint, GC3Dsizei, GC3Dint*)
761 DELEGATE_TO_WEBCONTEXT_4(uniformMatrix2fv, GC3Dint, GC3Dsizei, GC3Dboolean, GC3D float*)
762 DELEGATE_TO_WEBCONTEXT_4(uniformMatrix3fv, GC3Dint, GC3Dsizei, GC3Dboolean, GC3D float*)
763 DELEGATE_TO_WEBCONTEXT_4(uniformMatrix4fv, GC3Dint, GC3Dsizei, GC3Dboolean, GC3D float*)
764
765 DELEGATE_TO_WEBCONTEXT_1(useProgram, Platform3DObject)
766 DELEGATE_TO_WEBCONTEXT_1(validateProgram, Platform3DObject)
767
768 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib1f, GC3Duint, GC3Dfloat)
769 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib1fv, GC3Duint, GC3Dfloat*)
770 DELEGATE_TO_WEBCONTEXT_3(vertexAttrib2f, GC3Duint, GC3Dfloat, GC3Dfloat)
771 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib2fv, GC3Duint, GC3Dfloat*)
772 DELEGATE_TO_WEBCONTEXT_4(vertexAttrib3f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dflo at)
773 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib3fv, GC3Duint, GC3Dfloat*)
774 DELEGATE_TO_WEBCONTEXT_5(vertexAttrib4f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dflo at, GC3Dfloat)
775 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib4fv, GC3Duint, GC3Dfloat*)
776 DELEGATE_TO_WEBCONTEXT_6(vertexAttribPointer, GC3Duint, GC3Dint, GC3Denum, GC3Db oolean, GC3Dsizei, GC3Dintptr)
777
778 DELEGATE_TO_WEBCONTEXT_4(viewport, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei)
779
780 void GraphicsContext3D::reshape(int width, int height)
781 {
782 if (width == m_impl->width() && height == m_impl->height())
783 return;
784
785 m_impl->reshape(width, height);
786 }
787
788 void GraphicsContext3D::markContextChanged()
789 {
790 m_layerComposited = false;
791 }
792
793 bool GraphicsContext3D::layerComposited() const
794 {
795 return m_layerComposited;
796 }
797
798 void GraphicsContext3D::markLayerComposited()
799 {
800 m_layerComposited = true;
801 }
802
803 void GraphicsContext3D::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer, DrawingBuffer* drawingBuffer)
804 {
805 Platform3DObject framebufferId;
806 int width, height;
807 getDrawingParameters(drawingBuffer, m_impl, &framebufferId, &width, &height) ;
808 paintFramebufferToCanvas(framebufferId, width, height, !getContextAttributes ().premultipliedAlpha, imageBuffer);
809 }
810
811 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(Drawin gBuffer* drawingBuffer)
812 {
813 if (getContextAttributes().premultipliedAlpha)
814 return 0;
815
816 Platform3DObject framebufferId;
817 int width, height;
818 getDrawingParameters(drawingBuffer, m_impl, &framebufferId, &width, &height) ;
819
820 RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height));
821 unsigned char* pixels = imageData->data()->data();
822 size_t bufferSize = 4 * width * height;
823
824 m_impl->readBackFramebuffer(pixels, bufferSize, framebufferId, width, height );
825
826 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT
827 // If the implementation swapped the red and blue channels, un-swap them.
828 for (size_t i = 0; i < bufferSize; i += 4)
829 std::swap(pixels[i], pixels[i + 2]);
830 #endif
831
832 return imageData.release();
833 }
834
835 DELEGATE_TO_WEBCONTEXT_R(createBuffer, Platform3DObject)
836 DELEGATE_TO_WEBCONTEXT_R(createFramebuffer, Platform3DObject)
837 DELEGATE_TO_WEBCONTEXT_R(createProgram, Platform3DObject)
838 DELEGATE_TO_WEBCONTEXT_R(createRenderbuffer, Platform3DObject)
839 DELEGATE_TO_WEBCONTEXT_1R(createShader, GC3Denum, Platform3DObject)
840 DELEGATE_TO_WEBCONTEXT_R(createTexture, Platform3DObject)
841
842 DELEGATE_TO_WEBCONTEXT_1(deleteBuffer, Platform3DObject)
843 DELEGATE_TO_WEBCONTEXT_1(deleteFramebuffer, Platform3DObject)
844 DELEGATE_TO_WEBCONTEXT_1(deleteProgram, Platform3DObject)
845 DELEGATE_TO_WEBCONTEXT_1(deleteRenderbuffer, Platform3DObject)
846 DELEGATE_TO_WEBCONTEXT_1(deleteShader, Platform3DObject)
847 DELEGATE_TO_WEBCONTEXT_1(deleteTexture, Platform3DObject)
848
849 DELEGATE_TO_WEBCONTEXT_1(synthesizeGLError, GC3Denum)
850
851 Extensions3D* GraphicsContext3D::getExtensions()
852 {
853 if (!m_extensions)
854 m_extensions = adoptPtr(new Extensions3D(this));
855 return m_extensions.get();
856 }
857
858 bool GraphicsContext3D::texImage2DResourceSafe(GC3Denum target, GC3Dint level, G C3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3De num format, GC3Denum type, GC3Dint unpackAlignment)
859 {
860 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 || unpackAlignment == 8);
861 OwnArrayPtr<unsigned char> zero;
862 if (!isResourceSafe() && width > 0 && height > 0) {
863 unsigned int size;
864 GC3Denum error = computeImageSizeInBytes(format, type, width, height, un packAlignment, &size, 0);
865 if (error != GraphicsContext3D::NO_ERROR) {
866 synthesizeGLError(error);
867 return false;
868 }
869 zero = adoptArrayPtr(new unsigned char[size]);
870 if (!zero) {
871 synthesizeGLError(GraphicsContext3D::INVALID_VALUE);
872 return false;
873 }
874 memset(zero.get(), 0, size);
875 }
876 texImage2D(target, level, internalformat, width, height, border, format, typ e, zero.get());
877 return true;
878 }
879
880 bool GraphicsContext3D::computeFormatAndTypeParameters(GC3Denum format,
881 GC3Denum type,
882 unsigned int* componentsP erPixel,
883 unsigned int* bytesPerCom ponent)
884 {
885 switch (format) {
886 case GraphicsContext3D::ALPHA:
887 case GraphicsContext3D::LUMINANCE:
888 case GraphicsContext3D::DEPTH_COMPONENT:
889 case GraphicsContext3D::DEPTH_STENCIL:
890 *componentsPerPixel = 1;
891 break;
892 case GraphicsContext3D::LUMINANCE_ALPHA:
893 *componentsPerPixel = 2;
894 break;
895 case GraphicsContext3D::RGB:
896 *componentsPerPixel = 3;
897 break;
898 case GraphicsContext3D::RGBA:
899 case Extensions3D::BGRA_EXT: // GL_EXT_texture_format_BGRA8888
900 *componentsPerPixel = 4;
901 break;
902 default:
903 return false;
904 }
905 switch (type) {
906 case GraphicsContext3D::UNSIGNED_BYTE:
907 *bytesPerComponent = sizeof(GC3Dubyte);
908 break;
909 case GraphicsContext3D::UNSIGNED_SHORT:
910 *bytesPerComponent = sizeof(GC3Dushort);
911 break;
912 case GraphicsContext3D::UNSIGNED_SHORT_5_6_5:
913 case GraphicsContext3D::UNSIGNED_SHORT_4_4_4_4:
914 case GraphicsContext3D::UNSIGNED_SHORT_5_5_5_1:
915 *componentsPerPixel = 1;
916 *bytesPerComponent = sizeof(GC3Dushort);
917 break;
918 case GraphicsContext3D::UNSIGNED_INT_24_8:
919 case GraphicsContext3D::UNSIGNED_INT:
920 *bytesPerComponent = sizeof(GC3Duint);
921 break;
922 case GraphicsContext3D::FLOAT: // OES_texture_float
923 *bytesPerComponent = sizeof(GC3Dfloat);
924 break;
925 case GraphicsContext3D::HALF_FLOAT_OES: // OES_texture_half_float
926 *bytesPerComponent = sizeof(GC3Dhalffloat);
927 break;
928 default:
929 return false;
930 }
931 return true;
932 }
933
934 GC3Denum GraphicsContext3D::computeImageSizeInBytes(GC3Denum format, GC3Denum ty pe, GC3Dsizei width, GC3Dsizei height, GC3Dint alignment,
935 unsigned int* imageSizeInByt es, unsigned int* paddingInBytes)
936 {
937 ASSERT(imageSizeInBytes);
938 ASSERT(alignment == 1 || alignment == 2 || alignment == 4 || alignment == 8) ;
939 if (width < 0 || height < 0)
940 return GraphicsContext3D::INVALID_VALUE;
941 unsigned int bytesPerComponent, componentsPerPixel;
942 if (!computeFormatAndTypeParameters(format, type, &bytesPerComponent, &compo nentsPerPixel))
943 return GraphicsContext3D::INVALID_ENUM;
944 if (!width || !height) {
945 *imageSizeInBytes = 0;
946 if (paddingInBytes)
947 *paddingInBytes = 0;
948 return GraphicsContext3D::NO_ERROR;
949 }
950 CheckedInt<uint32_t> checkedValue(bytesPerComponent * componentsPerPixel);
951 checkedValue *= width;
952 if (!checkedValue.isValid())
953 return GraphicsContext3D::INVALID_VALUE;
954 unsigned int validRowSize = checkedValue.value();
955 unsigned int padding = 0;
956 unsigned int residual = validRowSize % alignment;
957 if (residual) {
958 padding = alignment - residual;
959 checkedValue += padding;
960 }
961 // Last row needs no padding.
962 checkedValue *= (height - 1);
963 checkedValue += validRowSize;
964 if (!checkedValue.isValid())
965 return GraphicsContext3D::INVALID_VALUE;
966 *imageSizeInBytes = checkedValue.value();
967 if (paddingInBytes)
968 *paddingInBytes = padding;
969 return GraphicsContext3D::NO_ERROR;
970 }
971
972 GraphicsContext3D::ImageExtractor::ImageExtractor(Image* image, ImageHtmlDomSour ce imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
973 {
974 m_image = image;
975 m_imageHtmlDomSource = imageHtmlDomSource;
976 m_extractSucceeded = extractImage(premultiplyAlpha, ignoreGammaAndColorProfi le);
977 }
978
979 GraphicsContext3D::ImageExtractor::~ImageExtractor()
980 {
981 if (m_skiaImage)
982 m_skiaImage->bitmap().unlockPixels();
983 }
984
985 bool GraphicsContext3D::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
986 {
987 if (!m_image)
988 return false;
989 m_skiaImage = m_image->nativeImageForCurrentFrame();
990 m_alphaOp = AlphaDoNothing;
991 bool hasAlpha = m_skiaImage ? !m_skiaImage->bitmap().isOpaque() : true;
992 if ((!m_skiaImage || ignoreGammaAndColorProfile || (hasAlpha && !premultiply Alpha)) && m_image->data()) {
993 // Attempt to get raw unpremultiplied image data.
994 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(
995 *(m_image->data()), ImageSource::AlphaNotPremultiplied,
996 ignoreGammaAndColorProfile ? ImageSource::GammaAndColorProfileIgnore d : ImageSource::GammaAndColorProfileApplied));
997 if (!decoder)
998 return false;
999 decoder->setData(m_image->data(), true);
1000 if (!decoder->frameCount())
1001 return false;
1002 ImageFrame* frame = decoder->frameBufferAtIndex(0);
1003 if (!frame || frame->status() != ImageFrame::FrameComplete)
1004 return false;
1005 hasAlpha = frame->hasAlpha();
1006 m_nativeImage = frame->asNewNativeImage();
1007 if (!m_nativeImage.get() || !m_nativeImage->isDataComplete() || !m_nativ eImage->bitmap().width() || !m_nativeImage->bitmap().height())
1008 return false;
1009 SkBitmap::Config skiaConfig = m_nativeImage->bitmap().config();
1010 if (skiaConfig != SkBitmap::kARGB_8888_Config)
1011 return false;
1012 m_skiaImage = m_nativeImage.get();
1013 if (hasAlpha && premultiplyAlpha)
1014 m_alphaOp = AlphaDoPremultiply;
1015 } else if (!premultiplyAlpha && hasAlpha) {
1016 // 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAl pha had been applied and the alpha value for each pixel is 0xFF
1017 // which is true at present and may be changed in the future and needs a djustment accordingly.
1018 // 2. For texImage2D with HTMLCanvasElement input in which Alpha is alre ady Premultiplied in this port,
1019 // do AlphaDoUnmultiply if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to fals e.
1020 if (m_imageHtmlDomSource != HtmlDomVideo)
1021 m_alphaOp = AlphaDoUnmultiply;
1022 }
1023 if (!m_skiaImage)
1024 return false;
1025
1026 m_imageSourceFormat = SK_B32_SHIFT ? DataFormatRGBA8 : DataFormatBGRA8;
1027 m_imageWidth = m_skiaImage->bitmap().width();
1028 m_imageHeight = m_skiaImage->bitmap().height();
1029 if (!m_imageWidth || !m_imageHeight)
1030 return false;
1031 m_imageSourceUnpackAlignment = 0;
1032 m_skiaImage->bitmap().lockPixels();
1033 m_imagePixelData = m_skiaImage->bitmap().getPixels();
1034 return true;
1035 }
1036
1037 bool GraphicsContext3D::packImageData(
1038 Image* image,
1039 const void* pixels,
1040 GC3Denum format,
1041 GC3Denum type,
1042 bool flipY,
1043 AlphaOp alphaOp,
1044 DataFormat sourceFormat,
1045 unsigned width,
1046 unsigned height,
1047 unsigned sourceUnpackAlignment,
1048 Vector<uint8_t>& data)
1049 {
1050 if (!pixels)
1051 return false;
1052
1053 unsigned packedSize;
1054 // Output data is tightly packed (alignment == 1).
1055 if (computeImageSizeInBytes(format, type, width, height, 1, &packedSize, 0) != GraphicsContext3D::NO_ERROR)
1056 return false;
1057 data.resize(packedSize);
1058
1059 if (!packPixels(reinterpret_cast<const uint8_t*>(pixels), sourceFormat, widt h, height, sourceUnpackAlignment, format, type, alphaOp, data.data(), flipY))
1060 return false;
1061 if (ImageObserver *observer = image->imageObserver())
1062 observer->didDraw(image);
1063 return true;
1064 }
1065
1066 bool GraphicsContext3D::extractImageData(ImageData* imageData,
1067 GC3Denum format,
1068 GC3Denum type,
1069 bool flipY,
1070 bool premultiplyAlpha,
1071 Vector<uint8_t>& data)
1072 {
1073 if (!imageData)
1074 return false;
1075 int width = imageData->width();
1076 int height = imageData->height();
1077
1078 unsigned int packedSize;
1079 // Output data is tightly packed (alignment == 1).
1080 if (computeImageSizeInBytes(format, type, width, height, 1, &packedSize, 0) != GraphicsContext3D::NO_ERROR)
1081 return false;
1082 data.resize(packedSize);
1083
1084 if (!packPixels(imageData->data()->data(), DataFormatRGBA8, width, height, 0 , format, type, premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing, data.dat a(), flipY))
1085 return false;
1086
1087 return true;
1088 }
1089
1090 bool GraphicsContext3D::extractTextureData(unsigned int width, unsigned int heig ht,
1091 GC3Denum format, GC3Denum type,
1092 unsigned int unpackAlignment,
1093 bool flipY, bool premultiplyAlpha,
1094 const void* pixels,
1095 Vector<uint8_t>& data)
1096 {
1097 // Assumes format, type, etc. have already been validated.
1098 DataFormat sourceDataFormat = getDataFormat(format, type);
1099
1100 // Resize the output buffer.
1101 unsigned int componentsPerPixel, bytesPerComponent;
1102 if (!computeFormatAndTypeParameters(format, type,
1103 &componentsPerPixel,
1104 &bytesPerComponent))
1105 return false;
1106 unsigned int bytesPerPixel = componentsPerPixel * bytesPerComponent;
1107 data.resize(width * height * bytesPerPixel);
1108
1109 if (!packPixels(static_cast<const uint8_t*>(pixels), sourceDataFormat, width , height, unpackAlignment, format, type, (premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing), data.data(), flipY))
1110 return false;
1111
1112 return true;
1113 }
1114
1115 namespace {
1116
1117 /* BEGIN CODE SHARED WITH MOZILLA FIREFOX */ 244 /* BEGIN CODE SHARED WITH MOZILLA FIREFOX */
1118 245
1119 // The following packing and unpacking routines are expressed in terms of functi on templates and inline functions to achieve generality and speedup. 246 // The following packing and unpacking routines are expressed in terms of functi on templates and inline functions to achieve generality and speedup.
1120 // Explicit template specializations correspond to the cases that would occur. 247 // Explicit template specializations correspond to the cases that would occur.
1121 // Some code are merged back from Mozilla code in http://mxr.mozilla.org/mozilla -central/source/content/canvas/src/WebGLTexelConversions.h 248 // Some code are merged back from Mozilla code in http://mxr.mozilla.org/mozilla -central/source/content/canvas/src/WebGLTexelConversions.h
1122 249
1123 //---------------------------------------------------------------------- 250 //----------------------------------------------------------------------
1124 // Pixel unpacking routines. 251 // Pixel unpacking routines.
1125 template<int format, typename SourceType, typename DstType> 252 template<int format, typename SourceType, typename DstType>
1126 void unpack(const SourceType*, DstType*, unsigned) 253 void unpack(const SourceType*, DstType*, unsigned)
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2326 srcRowStart += srcStrideInElements; 1453 srcRowStart += srcStrideInElements;
2327 dstRowStart += dstStrideInElements; 1454 dstRowStart += dstStrideInElements;
2328 } 1455 }
2329 } 1456 }
2330 m_success = true; 1457 m_success = true;
2331 return; 1458 return;
2332 } 1459 }
2333 1460
2334 } // anonymous namespace 1461 } // anonymous namespace
2335 1462
2336 bool GraphicsContext3D::packPixels(const uint8_t* sourceData, DataFormat sourceD ataFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsi gned destinationFormat, unsigned destinationType, AlphaOp alphaOp, void* destina tionData, bool flipY) 1463 bool GraphicsContext3D::packImageData(
1464 Image* image,
1465 const void* pixels,
1466 GC3Denum format,
1467 GC3Denum type,
1468 bool flipY,
1469 AlphaOp alphaOp,
1470 DataFormat sourceFormat,
1471 unsigned width,
1472 unsigned height,
1473 unsigned sourceUnpackAlignment,
1474 Vector<uint8_t>& data)
1475 {
1476 if (!pixels)
1477 return false;
1478
1479 unsigned packedSize;
1480 // Output data is tightly packed (alignment == 1).
1481 if (computeImageSizeInBytes(format, type, width, height, 1, &packedSize, 0) != GraphicsContext3D::NO_ERROR)
1482 return false;
1483 data.resize(packedSize);
1484
1485 if (!packPixels(reinterpret_cast<const uint8_t*>(pixels), sourceFormat, widt h, height, sourceUnpackAlignment, format, type, alphaOp, data.data(), flipY))
1486 return false;
1487 if (ImageObserver *observer = image->imageObserver())
1488 observer->didDraw(image);
1489 return true;
1490 }
1491
1492 bool GraphicsContext3D::extractImageData(
1493 ImageData* imageData,
1494 GC3Denum format,
1495 GC3Denum type,
1496 bool flipY,
1497 bool premultiplyAlpha,
1498 Vector<uint8_t>& data)
1499 {
1500 if (!imageData)
1501 return false;
1502 int width = imageData->width();
1503 int height = imageData->height();
1504
1505 unsigned packedSize;
1506 // Output data is tightly packed (alignment == 1).
1507 if (computeImageSizeInBytes(format, type, width, height, 1, &packedSize, 0) != GraphicsContext3D::NO_ERROR)
1508 return false;
1509 data.resize(packedSize);
1510
1511 if (!packPixels(imageData->data()->data(), DataFormatRGBA8, width, height, 0 , format, type, premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing, data.dat a(), flipY))
1512 return false;
1513
1514 return true;
1515 }
1516
1517 bool GraphicsContext3D::extractTextureData(
1518 unsigned width,
1519 unsigned height,
1520 GC3Denum format, GC3Denum type,
1521 unsigned unpackAlignment,
1522 bool flipY, bool premultiplyAlpha,
1523 const void* pixels,
1524 Vector<uint8_t>& data)
1525 {
1526 // Assumes format, type, etc. have already been validated.
1527 DataFormat sourceDataFormat = getDataFormat(format, type);
1528
1529 // Resize the output buffer.
1530 unsigned int componentsPerPixel, bytesPerComponent;
1531 if (!computeFormatAndTypeParameters(format, type, &componentsPerPixel, &byte sPerComponent))
1532 return false;
1533 unsigned bytesPerPixel = componentsPerPixel * bytesPerComponent;
1534 data.resize(width * height * bytesPerPixel);
1535
1536 if (!packPixels(static_cast<const uint8_t*>(pixels), sourceDataFormat, width , height, unpackAlignment, format, type, (premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing), data.data(), flipY))
1537 return false;
1538
1539 return true;
1540 }
1541
1542 bool GraphicsContext3D::packPixels(
1543 const uint8_t* sourceData,
1544 DataFormat sourceDataFormat,
1545 unsigned width,
1546 unsigned height,
1547 unsigned sourceUnpackAlignment,
1548 unsigned destinationFormat,
1549 unsigned destinationType,
1550 AlphaOp alphaOp,
1551 void* destinationData,
1552 bool flipY)
2337 { 1553 {
2338 int validSrc = width * TexelBytesForFormat(sourceDataFormat); 1554 int validSrc = width * TexelBytesForFormat(sourceDataFormat);
2339 int remainder = sourceUnpackAlignment ? (validSrc % sourceUnpackAlignment) : 0; 1555 int remainder = sourceUnpackAlignment ? (validSrc % sourceUnpackAlignment) : 0;
2340 int srcStride = remainder ? (validSrc + sourceUnpackAlignment - remainder) : validSrc; 1556 int srcStride = remainder ? (validSrc + sourceUnpackAlignment - remainder) : validSrc;
2341 1557
2342 DataFormat dstDataFormat = getDataFormat(destinationFormat, destinationType) ; 1558 DataFormat dstDataFormat = getDataFormat(destinationFormat, destinationType) ;
2343 int dstStride = width * TexelBytesForFormat(dstDataFormat); 1559 int dstStride = width * TexelBytesForFormat(dstDataFormat);
2344 if (flipY) { 1560 if (flipY) {
2345 destinationData = static_cast<uint8_t*>(destinationData) + dstStride*(he ight - 1); 1561 destinationData = static_cast<uint8_t*>(destinationData) + dstStride*(he ight - 1);
2346 dstStride = -dstStride; 1562 dstStride = -dstStride;
(...skipping 14 matching lines...) Expand all
2361 return true; 1577 return true;
2362 } 1578 }
2363 1579
2364 FormatConverter converter(width, height, sourceData, destinationData, srcStr ide, dstStride); 1580 FormatConverter converter(width, height, sourceData, destinationData, srcStr ide, dstStride);
2365 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); 1581 converter.convert(sourceDataFormat, dstDataFormat, alphaOp);
2366 if (!converter.Success()) 1582 if (!converter.Success())
2367 return false; 1583 return false;
2368 return true; 1584 return true;
2369 } 1585 }
2370 1586
2371 unsigned GraphicsContext3D::getClearBitsByAttachmentType(GC3Denum attachment) 1587 } // namespace WebCore
2372 {
2373 switch (attachment) {
2374 case GraphicsContext3D::COLOR_ATTACHMENT0:
2375 case Extensions3D::COLOR_ATTACHMENT1_EXT:
2376 case Extensions3D::COLOR_ATTACHMENT2_EXT:
2377 case Extensions3D::COLOR_ATTACHMENT3_EXT:
2378 case Extensions3D::COLOR_ATTACHMENT4_EXT:
2379 case Extensions3D::COLOR_ATTACHMENT5_EXT:
2380 case Extensions3D::COLOR_ATTACHMENT6_EXT:
2381 case Extensions3D::COLOR_ATTACHMENT7_EXT:
2382 case Extensions3D::COLOR_ATTACHMENT8_EXT:
2383 case Extensions3D::COLOR_ATTACHMENT9_EXT:
2384 case Extensions3D::COLOR_ATTACHMENT10_EXT:
2385 case Extensions3D::COLOR_ATTACHMENT11_EXT:
2386 case Extensions3D::COLOR_ATTACHMENT12_EXT:
2387 case Extensions3D::COLOR_ATTACHMENT13_EXT:
2388 case Extensions3D::COLOR_ATTACHMENT14_EXT:
2389 case Extensions3D::COLOR_ATTACHMENT15_EXT:
2390 return GraphicsContext3D::COLOR_BUFFER_BIT;
2391 case GraphicsContext3D::DEPTH_ATTACHMENT:
2392 return GraphicsContext3D::DEPTH_BUFFER_BIT;
2393 case GraphicsContext3D::STENCIL_ATTACHMENT:
2394 return GraphicsContext3D::STENCIL_BUFFER_BIT;
2395 case GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT:
2396 return GraphicsContext3D::DEPTH_BUFFER_BIT | GraphicsContext3D::STENCIL_ BUFFER_BIT;
2397 default:
2398 return 0;
2399 }
2400 }
2401 1588
2402 unsigned GraphicsContext3D::getClearBitsByFormat(GC3Denum format)
2403 {
2404 switch (format) {
2405 case GraphicsContext3D::ALPHA:
2406 case GraphicsContext3D::LUMINANCE:
2407 case GraphicsContext3D::LUMINANCE_ALPHA:
2408 case GraphicsContext3D::RGB:
2409 case GraphicsContext3D::RGB565:
2410 case GraphicsContext3D::RGBA:
2411 case GraphicsContext3D::RGBA4:
2412 case GraphicsContext3D::RGB5_A1:
2413 return GraphicsContext3D::COLOR_BUFFER_BIT;
2414 case GraphicsContext3D::DEPTH_COMPONENT16:
2415 case GraphicsContext3D::DEPTH_COMPONENT:
2416 return GraphicsContext3D::DEPTH_BUFFER_BIT;
2417 case GraphicsContext3D::STENCIL_INDEX8:
2418 return GraphicsContext3D::STENCIL_BUFFER_BIT;
2419 case GraphicsContext3D::DEPTH_STENCIL:
2420 return GraphicsContext3D::DEPTH_BUFFER_BIT | GraphicsContext3D::STENCIL_ BUFFER_BIT;
2421 default:
2422 return 0;
2423 }
2424 }
2425
2426 unsigned GraphicsContext3D::getChannelBitsByFormat(GC3Denum format)
2427 {
2428 switch (format) {
2429 case GraphicsContext3D::ALPHA:
2430 return ChannelAlpha;
2431 case GraphicsContext3D::LUMINANCE:
2432 return ChannelRGB;
2433 case GraphicsContext3D::LUMINANCE_ALPHA:
2434 return ChannelRGBA;
2435 case GraphicsContext3D::RGB:
2436 case GraphicsContext3D::RGB565:
2437 return ChannelRGB;
2438 case GraphicsContext3D::RGBA:
2439 case GraphicsContext3D::RGBA4:
2440 case GraphicsContext3D::RGB5_A1:
2441 return ChannelRGBA;
2442 case GraphicsContext3D::DEPTH_COMPONENT16:
2443 case GraphicsContext3D::DEPTH_COMPONENT:
2444 return ChannelDepth;
2445 case GraphicsContext3D::STENCIL_INDEX8:
2446 return ChannelStencil;
2447 case GraphicsContext3D::DEPTH_STENCIL:
2448 return ChannelDepth | ChannelStencil;
2449 default:
2450 return 0;
2451 }
2452 }
2453
2454 void GraphicsContext3D::paintFramebufferToCanvas(int framebuffer, int width, int height, bool premultiplyAlpha, ImageBuffer* imageBuffer)
2455 {
2456 unsigned char* pixels = 0;
2457 size_t bufferSize = 4 * width * height;
2458
2459 const SkBitmap* canvasBitmap = imageBuffer->context()->bitmap();
2460 const SkBitmap* readbackBitmap = 0;
2461 ASSERT(canvasBitmap->config() == SkBitmap::kARGB_8888_Config);
2462 if (canvasBitmap->width() == width && canvasBitmap->height() == height) {
2463 // This is the fastest and most common case. We read back
2464 // directly into the canvas's backing store.
2465 readbackBitmap = canvasBitmap;
2466 m_resizingBitmap.reset();
2467 } else {
2468 // We need to allocate a temporary bitmap for reading back the
2469 // pixel data. We will then use Skia to rescale this bitmap to
2470 // the size of the canvas's backing store.
2471 if (m_resizingBitmap.width() != width || m_resizingBitmap.height() != he ight) {
2472 m_resizingBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, heigh t);
2473 if (!m_resizingBitmap.allocPixels())
2474 return;
2475 }
2476 readbackBitmap = &m_resizingBitmap;
2477 }
2478
2479 // Read back the frame buffer.
2480 SkAutoLockPixels bitmapLock(*readbackBitmap);
2481 pixels = static_cast<unsigned char*>(readbackBitmap->getPixels());
2482
2483 m_impl->readBackFramebuffer(pixels, 4 * width * height, framebuffer, width, height);
2484
2485 if (premultiplyAlpha) {
2486 for (size_t i = 0; i < bufferSize; i += 4) {
2487 pixels[i + 0] = std::min(255, pixels[i + 0] * pixels[i + 3] / 255);
2488 pixels[i + 1] = std::min(255, pixels[i + 1] * pixels[i + 3] / 255);
2489 pixels[i + 2] = std::min(255, pixels[i + 2] * pixels[i + 3] / 255);
2490 }
2491 }
2492
2493 readbackBitmap->notifyPixelsChanged();
2494 if (m_resizingBitmap.readyToDraw()) {
2495 // We need to draw the resizing bitmap into the canvas's backing store.
2496 SkCanvas canvas(*canvasBitmap);
2497 SkRect dst;
2498 dst.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(canvasBitmap-> width()), SkIntToScalar(canvasBitmap->height()));
2499 canvas.drawBitmapRect(m_resizingBitmap, 0, dst);
2500 }
2501 }
2502
2503 namespace {
2504
2505 void splitStringHelper(const String& str, HashSet<String>& set)
2506 {
2507 Vector<String> substrings;
2508 str.split(" ", substrings);
2509 for (size_t i = 0; i < substrings.size(); ++i)
2510 set.add(substrings[i]);
2511 }
2512
2513 String mapExtensionName(const String& name)
2514 {
2515 if (name == "GL_ANGLE_framebuffer_blit"
2516 || name == "GL_ANGLE_framebuffer_multisample")
2517 return "GL_CHROMIUM_framebuffer_multisample";
2518 return name;
2519 }
2520
2521 } // anonymous namespace
2522
2523 void GraphicsContext3D::initializeExtensions()
2524 {
2525 if (m_initializedAvailableExtensions)
2526 return;
2527
2528 m_initializedAvailableExtensions = true;
2529 bool success = m_impl->makeContextCurrent();
2530 ASSERT(success);
2531 if (!success)
2532 return;
2533
2534 String extensionsString = m_impl->getString(GraphicsContext3D::EXTENSIONS);
2535 splitStringHelper(extensionsString, m_enabledExtensions);
2536
2537 String requestableExtensionsString = m_impl->getRequestableExtensionsCHROMIU M();
2538 splitStringHelper(requestableExtensionsString, m_requestableExtensions);
2539 }
2540
2541
2542 bool GraphicsContext3D::supportsExtension(const String& name)
2543 {
2544 initializeExtensions();
2545 String mappedName = mapExtensionName(name);
2546 return m_enabledExtensions.contains(mappedName) || m_requestableExtensions.c ontains(mappedName);
2547 }
2548
2549 bool GraphicsContext3D::ensureExtensionEnabled(const String& name)
2550 {
2551 initializeExtensions();
2552
2553 String mappedName = mapExtensionName(name);
2554 if (m_enabledExtensions.contains(mappedName))
2555 return true;
2556
2557 if (m_requestableExtensions.contains(mappedName)) {
2558 m_impl->requestExtensionCHROMIUM(mappedName.ascii().data());
2559 m_enabledExtensions.clear();
2560 m_requestableExtensions.clear();
2561 m_initializedAvailableExtensions = false;
2562 }
2563
2564 initializeExtensions();
2565 return m_enabledExtensions.contains(mappedName);
2566 }
2567
2568 bool GraphicsContext3D::isExtensionEnabled(const String& name)
2569 {
2570 initializeExtensions();
2571 String mappedName = mapExtensionName(name);
2572 return m_enabledExtensions.contains(mappedName);
2573 }
2574
2575 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/GraphicsContext3D.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698