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 10 matching lines...) Expand all Loading... |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (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. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 | 29 |
30 #include "core/platform/graphics/GraphicsContext3D.h" | 30 #include "core/platform/graphics/GraphicsContext3D.h" |
31 #include "core/platform/graphics/cpu/arm/GraphicsContext3DNEON.h" | |
32 | 31 |
| 32 #include "GrContext.h" |
| 33 #include "GrGLInterface.h" |
33 #include "SkTypes.h" | 34 #include "SkTypes.h" |
34 #include "core/html/ImageData.h" | 35 #include "core/html/ImageData.h" |
35 #include "core/html/canvas/CheckedInt.h" | 36 #include "core/html/canvas/CheckedInt.h" |
36 #include "core/platform/chromium/support/GraphicsContext3DPrivate.h" | |
37 #include "core/platform/graphics/Extensions3D.h" | 37 #include "core/platform/graphics/Extensions3D.h" |
| 38 #include "core/platform/graphics/GraphicsContext.h" |
38 #include "core/platform/graphics/Image.h" | 39 #include "core/platform/graphics/Image.h" |
39 #include "core/platform/graphics/ImageBuffer.h" | 40 #include "core/platform/graphics/ImageBuffer.h" |
40 #include "core/platform/graphics/ImageObserver.h" | 41 #include "core/platform/graphics/ImageObserver.h" |
| 42 #include "core/platform/graphics/cpu/arm/GraphicsContext3DNEON.h" |
41 #include "core/platform/graphics/gpu/DrawingBuffer.h" | 43 #include "core/platform/graphics/gpu/DrawingBuffer.h" |
42 #include "core/platform/image-decoders/ImageDecoder.h" | 44 #include "core/platform/image-decoders/ImageDecoder.h" |
| 45 #include "wtf/ArrayBufferView.h" |
| 46 #include "wtf/OwnArrayPtr.h" |
| 47 #include "wtf/PassOwnArrayPtr.h" |
| 48 #include "wtf/text/CString.h" |
| 49 #include "wtf/text/StringHash.h" |
| 50 #include "wtf/text/WTFString.h" |
43 | 51 |
44 #include <public/Platform.h> | 52 #include <public/Platform.h> |
45 #include <public/WebGraphicsContext3D.h> | 53 #include <public/WebGraphicsContext3D.h> |
46 #include <wtf/ArrayBufferView.h> | 54 #include <public/WebGraphicsContext3DProvider.h> |
47 #include <wtf/OwnArrayPtr.h> | 55 #include <public/WebGraphicsMemoryAllocation.h> |
48 #include <wtf/PassOwnArrayPtr.h> | 56 |
49 #include <wtf/text/CString.h> | 57 namespace { |
50 #include <wtf/text/WTFString.h> | 58 |
| 59 // The limit of the number of textures we hold in the GrContext's bitmap->textur
e cache. |
| 60 const int maxGaneshTextureCacheCount = 2048; |
| 61 // The limit of the bytes allocated toward textures in the GrContext's bitmap->t
exture cache. |
| 62 const size_t maxGaneshTextureCacheBytes = 96 * 1024 * 1024; |
| 63 |
| 64 } |
51 | 65 |
52 namespace WebCore { | 66 namespace WebCore { |
53 | 67 |
54 namespace { | 68 namespace { |
55 | 69 |
56 GraphicsContext3D::DataFormat getDataFormat(GC3Denum destinationFormat, GC3Denum
destinationType) | 70 GraphicsContext3D::DataFormat getDataFormat(GC3Denum destinationFormat, GC3Denum
destinationType) |
57 { | 71 { |
58 GraphicsContext3D::DataFormat dstFormat = GraphicsContext3D::DataFormatRGBA8
; | 72 GraphicsContext3D::DataFormat dstFormat = GraphicsContext3D::DataFormatRGBA8
; |
59 switch (destinationType) { | 73 switch (destinationType) { |
60 case GraphicsContext3D::UNSIGNED_BYTE: | 74 case GraphicsContext3D::UNSIGNED_BYTE: |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 281 |
268 unsigned short convertFloatToHalfFloat(float f) | 282 unsigned short convertFloatToHalfFloat(float f) |
269 { | 283 { |
270 unsigned temp = *(reinterpret_cast<unsigned *>(&f)); | 284 unsigned temp = *(reinterpret_cast<unsigned *>(&f)); |
271 unsigned signexp = (temp >> 23) & 0x1ff; | 285 unsigned signexp = (temp >> 23) & 0x1ff; |
272 return baseTable[signexp] + ((temp & 0x007fffff) >> shiftTable[signexp]); | 286 return baseTable[signexp] + ((temp & 0x007fffff) >> shiftTable[signexp]); |
273 } | 287 } |
274 | 288 |
275 } // anonymous namespace | 289 } // anonymous namespace |
276 | 290 |
| 291 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<WebKit::WebGraphicsContext3D> we
bContext, bool preserveDrawingBuffer) |
| 292 : m_impl(webContext.get()) |
| 293 , m_ownedWebContext(webContext) |
| 294 , m_initializedAvailableExtensions(false) |
| 295 , m_layerComposited(false) |
| 296 , m_preserveDrawingBuffer(preserveDrawingBuffer) |
| 297 , m_resourceSafety(ResourceSafetyUnknown) |
| 298 , m_grContext(0) |
| 299 { |
| 300 } |
| 301 |
| 302 GraphicsContext3D::GraphicsContext3D(PassOwnPtr<WebKit::WebGraphicsContext3DProv
ider> provider, bool preserveDrawingBuffer) |
| 303 : m_provider(provider) |
| 304 , m_impl(m_provider->context3d()) |
| 305 , m_initializedAvailableExtensions(false) |
| 306 , m_layerComposited(false) |
| 307 , m_preserveDrawingBuffer(preserveDrawingBuffer) |
| 308 , m_resourceSafety(ResourceSafetyUnknown) |
| 309 , m_grContext(m_provider->grContext()) |
| 310 { |
| 311 } |
| 312 |
| 313 GraphicsContext3D::~GraphicsContext3D() |
| 314 { |
| 315 setContextLostCallback(nullptr); |
| 316 setErrorMessageCallback(nullptr); |
| 317 |
| 318 if (m_ownedGrContext) { |
| 319 m_ownedWebContext->setMemoryAllocationChangedCallbackCHROMIUM(0); |
| 320 m_ownedGrContext->contextDestroyed(); |
| 321 } |
| 322 } |
| 323 |
277 // Macros to assist in delegating from GraphicsContext3D to | 324 // Macros to assist in delegating from GraphicsContext3D to |
278 // WebGraphicsContext3D. | 325 // WebGraphicsContext3D. |
279 | 326 |
280 #define DELEGATE_TO_WEBCONTEXT(name) \ | 327 #define DELEGATE_TO_WEBCONTEXT(name) \ |
281 void GraphicsContext3D::name() \ | 328 void GraphicsContext3D::name() \ |
282 { \ | 329 { \ |
283 m_private->webContext()->name(); \ | 330 m_impl->name(); \ |
284 } | 331 } |
285 | 332 |
286 #define DELEGATE_TO_WEBCONTEXT_R(name, rt) \ | 333 #define DELEGATE_TO_WEBCONTEXT_R(name, rt) \ |
287 rt GraphicsContext3D::name() \ | 334 rt GraphicsContext3D::name() \ |
288 { \ | 335 { \ |
289 return m_private->webContext()->name(); \ | 336 return m_impl->name(); \ |
290 } | 337 } |
291 | 338 |
292 #define DELEGATE_TO_WEBCONTEXT_1(name, t1) \ | 339 #define DELEGATE_TO_WEBCONTEXT_1(name, t1) \ |
293 void GraphicsContext3D::name(t1 a1) \ | 340 void GraphicsContext3D::name(t1 a1) \ |
294 { \ | 341 { \ |
295 m_private->webContext()->name(a1); \ | 342 m_impl->name(a1); \ |
296 } | 343 } |
297 | 344 |
298 #define DELEGATE_TO_WEBCONTEXT_1R(name, t1, rt) \ | 345 #define DELEGATE_TO_WEBCONTEXT_1R(name, t1, rt) \ |
299 rt GraphicsContext3D::name(t1 a1) \ | 346 rt GraphicsContext3D::name(t1 a1) \ |
300 { \ | 347 { \ |
301 return m_private->webContext()->name(a1); \ | 348 return m_impl->name(a1); \ |
302 } | 349 } |
303 | 350 |
304 #define DELEGATE_TO_WEBCONTEXT_2(name, t1, t2) \ | 351 #define DELEGATE_TO_WEBCONTEXT_2(name, t1, t2) \ |
305 void GraphicsContext3D::name(t1 a1, t2 a2) \ | 352 void GraphicsContext3D::name(t1 a1, t2 a2) \ |
306 { \ | 353 { \ |
307 m_private->webContext()->name(a1, a2); \ | 354 m_impl->name(a1, a2); \ |
308 } | 355 } |
309 | 356 |
310 #define DELEGATE_TO_WEBCONTEXT_2R(name, t1, t2, rt) \ | 357 #define DELEGATE_TO_WEBCONTEXT_2R(name, t1, t2, rt) \ |
311 rt GraphicsContext3D::name(t1 a1, t2 a2) \ | 358 rt GraphicsContext3D::name(t1 a1, t2 a2) \ |
312 { \ | 359 { \ |
313 return m_private->webContext()->name(a1, a2); \ | 360 return m_impl->name(a1, a2); \ |
314 } | 361 } |
315 | 362 |
316 #define DELEGATE_TO_WEBCONTEXT_3(name, t1, t2, t3) \ | 363 #define DELEGATE_TO_WEBCONTEXT_3(name, t1, t2, t3) \ |
317 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \ | 364 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \ |
318 { \ | 365 { \ |
319 m_private->webContext()->name(a1, a2, a3); \ | 366 m_impl->name(a1, a2, a3); \ |
320 } | 367 } |
321 | 368 |
322 #define DELEGATE_TO_WEBCONTEXT_3R(name, t1, t2, t3, rt) \ | 369 #define DELEGATE_TO_WEBCONTEXT_3R(name, t1, t2, t3, rt) \ |
323 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \ | 370 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3) \ |
324 { \ | 371 { \ |
325 return m_private->webContext()->name(a1, a2, a3); \ | 372 return m_impl->name(a1, a2, a3); \ |
326 } | 373 } |
327 | 374 |
328 #define DELEGATE_TO_WEBCONTEXT_4(name, t1, t2, t3, t4) \ | 375 #define DELEGATE_TO_WEBCONTEXT_4(name, t1, t2, t3, t4) \ |
329 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \ | 376 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \ |
330 { \ | 377 { \ |
331 m_private->webContext()->name(a1, a2, a3, a4); \ | 378 m_impl->name(a1, a2, a3, a4); \ |
332 } | 379 } |
333 | 380 |
334 #define DELEGATE_TO_WEBCONTEXT_4R(name, t1, t2, t3, t4, rt) \ | 381 #define DELEGATE_TO_WEBCONTEXT_4R(name, t1, t2, t3, t4, rt) \ |
335 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \ | 382 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4) \ |
336 { \ | 383 { \ |
337 return m_private->webContext()->name(a1, a2, a3, a4); \ | 384 return m_impl->name(a1, a2, a3, a4); \ |
338 } | 385 } |
339 | 386 |
340 #define DELEGATE_TO_WEBCONTEXT_5(name, t1, t2, t3, t4, t5) \ | 387 #define DELEGATE_TO_WEBCONTEXT_5(name, t1, t2, t3, t4, t5) \ |
341 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) \ | 388 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) \ |
342 { \ | 389 { \ |
343 m_private->webContext()->name(a1, a2, a3, a4, a5); \ | 390 m_impl->name(a1, a2, a3, a4, a5); \ |
344 } | 391 } |
345 | 392 |
346 #define DELEGATE_TO_WEBCONTEXT_6(name, t1, t2, t3, t4, t5, t6) \ | 393 #define DELEGATE_TO_WEBCONTEXT_6(name, t1, t2, t3, t4, t5, t6) \ |
347 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \ | 394 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \ |
348 { \ | 395 { \ |
349 m_private->webContext()->name(a1, a2, a3, a4, a5, a6); \ | 396 m_impl->name(a1, a2, a3, a4, a5, a6); \ |
350 } | 397 } |
351 | 398 |
352 #define DELEGATE_TO_WEBCONTEXT_6R(name, t1, t2, t3, t4, t5, t6, rt) \ | 399 #define DELEGATE_TO_WEBCONTEXT_6R(name, t1, t2, t3, t4, t5, t6, rt) \ |
353 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \ | 400 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6) \ |
354 { \ | 401 { \ |
355 return m_private->webContext()->name(a1, a2, a3, a4, a5, a6); \ | 402 return m_impl->name(a1, a2, a3, a4, a5, a6); \ |
356 } | 403 } |
357 | 404 |
358 #define DELEGATE_TO_WEBCONTEXT_7(name, t1, t2, t3, t4, t5, t6, t7) \ | 405 #define DELEGATE_TO_WEBCONTEXT_7(name, t1, t2, t3, t4, t5, t6, t7) \ |
359 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \ | 406 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \ |
360 { \ | 407 { \ |
361 m_private->webContext()->name(a1, a2, a3, a4, a5, a6, a7); \ | 408 m_impl->name(a1, a2, a3, a4, a5, a6, a7); \ |
362 } | 409 } |
363 | 410 |
364 #define DELEGATE_TO_WEBCONTEXT_7R(name, t1, t2, t3, t4, t5, t6, t7, rt) \ | 411 #define DELEGATE_TO_WEBCONTEXT_7R(name, t1, t2, t3, t4, t5, t6, t7, rt) \ |
365 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \ | 412 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7) \ |
366 { \ | 413 { \ |
367 return m_private->webContext()->name(a1, a2, a3, a4, a5, a6, a7); \ | 414 return m_impl->name(a1, a2, a3, a4, a5, a6, a7); \ |
368 } | 415 } |
369 | 416 |
370 #define DELEGATE_TO_WEBCONTEXT_8(name, t1, t2, t3, t4, t5, t6, t7, t8) \ | 417 #define DELEGATE_TO_WEBCONTEXT_8(name, t1, t2, t3, t4, t5, t6, t7, t8) \ |
371 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8
a8) \ | 418 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8
a8) \ |
372 { \ | 419 { \ |
373 m_private->webContext()->name(a1, a2, a3, a4, a5, a6, a7, a8); \ | 420 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8); \ |
374 } | 421 } |
375 | 422 |
376 #define DELEGATE_TO_WEBCONTEXT_9(name, t1, t2, t3, t4, t5, t6, t7, t8, t9) \ | 423 #define DELEGATE_TO_WEBCONTEXT_9(name, t1, t2, t3, t4, t5, t6, t7, t8, t9) \ |
377 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8
a8, t9 a9) \ | 424 void GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8
a8, t9 a9) \ |
378 { \ | 425 { \ |
379 m_private->webContext()->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ | 426 m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ |
380 } | 427 } |
381 | 428 |
382 #define DELEGATE_TO_WEBCONTEXT_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt)
\ | 429 #define DELEGATE_TO_WEBCONTEXT_9R(name, t1, t2, t3, t4, t5, t6, t7, t8, t9, rt)
\ |
383 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a
8, t9 a9) \ | 430 rt GraphicsContext3D::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7, t8 a
8, t9 a9) \ |
384 { \ | 431 { \ |
385 return m_private->webContext()->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ | 432 return m_impl->name(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ |
386 } | 433 } |
387 | 434 |
388 GraphicsContext3D::GraphicsContext3D() | 435 class GraphicsContext3DContextLostCallbackAdapter : public WebKit::WebGraphicsCo
ntext3D::WebGraphicsContextLostCallback { |
389 { | 436 public: |
390 } | 437 GraphicsContext3DContextLostCallbackAdapter(PassOwnPtr<GraphicsContext3D::Co
ntextLostCallback> callback) |
| 438 : m_contextLostCallback(callback) { } |
| 439 virtual ~GraphicsContext3DContextLostCallbackAdapter() { } |
391 | 440 |
392 GraphicsContext3D::~GraphicsContext3D() | 441 virtual void onContextLost() |
393 { | 442 { |
394 m_private->setContextLostCallback(nullptr); | 443 if (m_contextLostCallback) |
395 m_private->setErrorMessageCallback(nullptr); | 444 m_contextLostCallback->onContextLost(); |
396 } | 445 } |
| 446 private: |
| 447 OwnPtr<GraphicsContext3D::ContextLostCallback> m_contextLostCallback; |
| 448 }; |
| 449 |
| 450 class GraphicsContext3DErrorMessageCallbackAdapter : public WebKit::WebGraphicsC
ontext3D::WebGraphicsErrorMessageCallback { |
| 451 public: |
| 452 GraphicsContext3DErrorMessageCallbackAdapter(PassOwnPtr<GraphicsContext3D::E
rrorMessageCallback> callback) |
| 453 : m_errorMessageCallback(callback) { } |
| 454 virtual ~GraphicsContext3DErrorMessageCallbackAdapter() { } |
| 455 |
| 456 virtual void onErrorMessage(const WebKit::WebString& message, WebKit::WGC3Di
nt id) |
| 457 { |
| 458 if (m_errorMessageCallback) |
| 459 m_errorMessageCallback->onErrorMessage(message, id); |
| 460 } |
| 461 private: |
| 462 OwnPtr<GraphicsContext3D::ErrorMessageCallback> m_errorMessageCallback; |
| 463 }; |
397 | 464 |
398 void GraphicsContext3D::setContextLostCallback(PassOwnPtr<GraphicsContext3D::Con
textLostCallback> callback) | 465 void GraphicsContext3D::setContextLostCallback(PassOwnPtr<GraphicsContext3D::Con
textLostCallback> callback) |
399 { | 466 { |
400 m_private->setContextLostCallback(callback); | 467 if (m_ownedWebContext) { |
| 468 m_contextLostCallbackAdapter = adoptPtr(new GraphicsContext3DContextLost
CallbackAdapter(callback)); |
| 469 m_ownedWebContext->setContextLostCallback(m_contextLostCallbackAdapter.g
et()); |
| 470 } |
401 } | 471 } |
402 | 472 |
403 void GraphicsContext3D::setErrorMessageCallback(PassOwnPtr<GraphicsContext3D::Er
rorMessageCallback> callback) | 473 void GraphicsContext3D::setErrorMessageCallback(PassOwnPtr<GraphicsContext3D::Er
rorMessageCallback> callback) |
404 { | 474 { |
405 m_private->setErrorMessageCallback(callback); | 475 if (m_ownedWebContext) { |
| 476 m_errorMessageCallbackAdapter = adoptPtr(new GraphicsContext3DErrorMessa
geCallbackAdapter(callback)); |
| 477 m_ownedWebContext->setErrorMessageCallback(m_errorMessageCallbackAdapter
.get()); |
| 478 } |
406 } | 479 } |
407 | 480 |
408 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attri
butes attrs) | 481 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attri
butes attrs) |
409 { | 482 { |
410 WebKit::WebGraphicsContext3D::Attributes webAttributes; | 483 WebKit::WebGraphicsContext3D::Attributes webAttributes; |
411 webAttributes.alpha = attrs.alpha; | 484 webAttributes.alpha = attrs.alpha; |
412 webAttributes.depth = attrs.depth; | 485 webAttributes.depth = attrs.depth; |
413 webAttributes.stencil = attrs.stencil; | 486 webAttributes.stencil = attrs.stencil; |
414 webAttributes.antialias = attrs.antialias; | 487 webAttributes.antialias = attrs.antialias; |
415 webAttributes.premultipliedAlpha = attrs.premultipliedAlpha; | 488 webAttributes.premultipliedAlpha = attrs.premultipliedAlpha; |
416 webAttributes.noExtensions = attrs.noExtensions; | 489 webAttributes.noExtensions = attrs.noExtensions; |
417 webAttributes.shareResources = attrs.shareResources; | 490 webAttributes.shareResources = attrs.shareResources; |
418 webAttributes.preferDiscreteGPU = attrs.preferDiscreteGPU; | 491 webAttributes.preferDiscreteGPU = attrs.preferDiscreteGPU; |
419 webAttributes.topDocumentURL = attrs.topDocumentURL.string(); | 492 webAttributes.topDocumentURL = attrs.topDocumentURL.string(); |
420 | 493 |
421 OwnPtr<WebKit::WebGraphicsContext3D> webContext = adoptPtr(WebKit::Platform:
:current()->createOffscreenGraphicsContext3D(webAttributes)); | 494 OwnPtr<WebKit::WebGraphicsContext3D> webContext = adoptPtr(WebKit::Platform:
:current()->createOffscreenGraphicsContext3D(webAttributes)); |
422 if (!webContext) | 495 if (!webContext) |
423 return 0; | 496 return 0; |
424 | 497 |
425 return GraphicsContext3DPrivate::createGraphicsContextFromWebContext(webCont
ext.release(), attrs.preserveDrawingBuffer); | 498 return GraphicsContext3D::createGraphicsContextFromWebContext(webContext.rel
ease(), attrs.preserveDrawingBuffer); |
| 499 } |
| 500 |
| 501 PassRefPtr<GraphicsContext3D> GraphicsContext3D::createGraphicsContextFromProvid
er(PassOwnPtr<WebKit::WebGraphicsContext3DProvider> provider, bool preserveDrawi
ngBuffer) |
| 502 { |
| 503 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(provider,
preserveDrawingBuffer)); |
| 504 return context.release(); |
| 505 } |
| 506 |
| 507 PassRefPtr<GraphicsContext3D> GraphicsContext3D::createGraphicsContextFromWebCon
text(PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, bool preserveDrawingBu
ffer) |
| 508 { |
| 509 RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(webContex
t, preserveDrawingBuffer)); |
| 510 return context.release(); |
| 511 } |
| 512 |
| 513 class GrMemoryAllocationChangedCallbackAdapter : public WebKit::WebGraphicsConte
xt3D::WebGraphicsMemoryAllocationChangedCallbackCHROMIUM { |
| 514 public: |
| 515 GrMemoryAllocationChangedCallbackAdapter(GrContext* context) |
| 516 : m_context(context) |
| 517 { |
| 518 } |
| 519 |
| 520 virtual void onMemoryAllocationChanged(WebKit::WebGraphicsMemoryAllocation a
llocation) OVERRIDE |
| 521 { |
| 522 if (!m_context) |
| 523 return; |
| 524 |
| 525 if (!allocation.gpuResourceSizeInBytes) { |
| 526 m_context->freeGpuResources(); |
| 527 m_context->setTextureCacheLimits(0, 0); |
| 528 } else |
| 529 m_context->setTextureCacheLimits(maxGaneshTextureCacheCount, maxGane
shTextureCacheBytes); |
| 530 } |
| 531 |
| 532 private: |
| 533 GrContext* m_context; |
| 534 }; |
| 535 |
| 536 namespace { |
| 537 void bindWebGraphicsContext3DGLContextCallback(const GrGLInterface* interface) |
| 538 { |
| 539 reinterpret_cast<WebKit::WebGraphicsContext3D*>(interface->fCallbackData)->m
akeContextCurrent(); |
| 540 } |
426 } | 541 } |
427 | 542 |
428 GrContext* GraphicsContext3D::grContext() | 543 GrContext* GraphicsContext3D::grContext() |
429 { | 544 { |
430 return m_private->grContext(); | 545 if (m_grContext) |
| 546 return m_grContext; |
| 547 if (!m_ownedWebContext) |
| 548 return 0; |
| 549 |
| 550 SkAutoTUnref<GrGLInterface> interface(m_ownedWebContext->createGrGLInterface
()); |
| 551 if (!interface) |
| 552 return 0; |
| 553 |
| 554 interface->fCallback = bindWebGraphicsContext3DGLContextCallback; |
| 555 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(m_own
edWebContext.get()); |
| 556 |
| 557 m_ownedGrContext.reset(GrContext::Create(kOpenGL_GrBackend, reinterpret_cast
<GrBackendContext>(interface.get()))); |
| 558 m_grContext = m_ownedGrContext; |
| 559 if (!m_grContext) |
| 560 return 0; |
| 561 |
| 562 m_grContext->setTextureCacheLimits(maxGaneshTextureCacheCount, maxGaneshText
ureCacheBytes); |
| 563 m_grContextMemoryAllocationCallbackAdapter = adoptPtr(new GrMemoryAllocation
ChangedCallbackAdapter(m_grContext)); |
| 564 m_ownedWebContext->setMemoryAllocationChangedCallbackCHROMIUM(m_grContextMem
oryAllocationCallbackAdapter.get()); |
| 565 |
| 566 return m_grContext; |
431 } | 567 } |
432 | 568 |
433 DELEGATE_TO_WEBCONTEXT_R(makeContextCurrent, bool) | 569 DELEGATE_TO_WEBCONTEXT_R(makeContextCurrent, bool) |
434 | 570 |
435 bool GraphicsContext3D::isResourceSafe() | 571 bool GraphicsContext3D::isResourceSafe() |
436 { | 572 { |
437 return m_private->isResourceSafe(); | 573 if (m_resourceSafety == ResourceSafetyUnknown) |
| 574 m_resourceSafety = getExtensions()->isEnabled("GL_CHROMIUM_resource_safe
") ? ResourceSafe : ResourceUnsafe; |
| 575 return m_resourceSafety == ResourceSafe; |
438 } | 576 } |
439 | 577 |
440 DELEGATE_TO_WEBCONTEXT_1(activeTexture, GC3Denum) | 578 DELEGATE_TO_WEBCONTEXT_1(activeTexture, GC3Denum) |
441 DELEGATE_TO_WEBCONTEXT_2(attachShader, Platform3DObject, Platform3DObject) | 579 DELEGATE_TO_WEBCONTEXT_2(attachShader, Platform3DObject, Platform3DObject) |
442 | 580 |
443 void GraphicsContext3D::bindAttribLocation(Platform3DObject program, GC3Duint in
dex, const String& name) | 581 void GraphicsContext3D::bindAttribLocation(Platform3DObject program, GC3Duint in
dex, const String& name) |
444 { | 582 { |
445 m_private->webContext()->bindAttribLocation(program, index, name.utf8().data
()); | 583 m_impl->bindAttribLocation(program, index, name.utf8().data()); |
446 } | 584 } |
447 | 585 |
448 DELEGATE_TO_WEBCONTEXT_2(bindBuffer, GC3Denum, Platform3DObject) | 586 DELEGATE_TO_WEBCONTEXT_2(bindBuffer, GC3Denum, Platform3DObject) |
449 DELEGATE_TO_WEBCONTEXT_2(bindFramebuffer, GC3Denum, Platform3DObject) | 587 DELEGATE_TO_WEBCONTEXT_2(bindFramebuffer, GC3Denum, Platform3DObject) |
450 DELEGATE_TO_WEBCONTEXT_2(bindRenderbuffer, GC3Denum, Platform3DObject) | 588 DELEGATE_TO_WEBCONTEXT_2(bindRenderbuffer, GC3Denum, Platform3DObject) |
451 DELEGATE_TO_WEBCONTEXT_2(bindTexture, GC3Denum, Platform3DObject) | 589 DELEGATE_TO_WEBCONTEXT_2(bindTexture, GC3Denum, Platform3DObject) |
452 DELEGATE_TO_WEBCONTEXT_4(blendColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dcla
mpf) | 590 DELEGATE_TO_WEBCONTEXT_4(blendColor, GC3Dclampf, GC3Dclampf, GC3Dclampf, GC3Dcla
mpf) |
453 DELEGATE_TO_WEBCONTEXT_1(blendEquation, GC3Denum) | 591 DELEGATE_TO_WEBCONTEXT_1(blendEquation, GC3Denum) |
454 DELEGATE_TO_WEBCONTEXT_2(blendEquationSeparate, GC3Denum, GC3Denum) | 592 DELEGATE_TO_WEBCONTEXT_2(blendEquationSeparate, GC3Denum, GC3Denum) |
455 DELEGATE_TO_WEBCONTEXT_2(blendFunc, GC3Denum, GC3Denum) | 593 DELEGATE_TO_WEBCONTEXT_2(blendFunc, GC3Denum, GC3Denum) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 DELEGATE_TO_WEBCONTEXT(finish) | 628 DELEGATE_TO_WEBCONTEXT(finish) |
491 DELEGATE_TO_WEBCONTEXT(flush) | 629 DELEGATE_TO_WEBCONTEXT(flush) |
492 DELEGATE_TO_WEBCONTEXT_4(framebufferRenderbuffer, GC3Denum, GC3Denum, GC3Denum,
Platform3DObject) | 630 DELEGATE_TO_WEBCONTEXT_4(framebufferRenderbuffer, GC3Denum, GC3Denum, GC3Denum,
Platform3DObject) |
493 DELEGATE_TO_WEBCONTEXT_5(framebufferTexture2D, GC3Denum, GC3Denum, GC3Denum, Pla
tform3DObject, GC3Dint) | 631 DELEGATE_TO_WEBCONTEXT_5(framebufferTexture2D, GC3Denum, GC3Denum, GC3Denum, Pla
tform3DObject, GC3Dint) |
494 DELEGATE_TO_WEBCONTEXT_1(frontFace, GC3Denum) | 632 DELEGATE_TO_WEBCONTEXT_1(frontFace, GC3Denum) |
495 DELEGATE_TO_WEBCONTEXT_1(generateMipmap, GC3Denum) | 633 DELEGATE_TO_WEBCONTEXT_1(generateMipmap, GC3Denum) |
496 | 634 |
497 bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, GC3Duint index
, ActiveInfo& info) | 635 bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, GC3Duint index
, ActiveInfo& info) |
498 { | 636 { |
499 WebKit::WebGraphicsContext3D::ActiveInfo webInfo; | 637 WebKit::WebGraphicsContext3D::ActiveInfo webInfo; |
500 if (!m_private->webContext()->getActiveAttrib(program, index, webInfo)) | 638 if (!m_impl->getActiveAttrib(program, index, webInfo)) |
501 return false; | 639 return false; |
502 info.name = webInfo.name; | 640 info.name = webInfo.name; |
503 info.type = webInfo.type; | 641 info.type = webInfo.type; |
504 info.size = webInfo.size; | 642 info.size = webInfo.size; |
505 return true; | 643 return true; |
506 } | 644 } |
507 | 645 |
508 bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint inde
x, ActiveInfo& info) | 646 bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint inde
x, ActiveInfo& info) |
509 { | 647 { |
510 WebKit::WebGraphicsContext3D::ActiveInfo webInfo; | 648 WebKit::WebGraphicsContext3D::ActiveInfo webInfo; |
511 if (!m_private->webContext()->getActiveUniform(program, index, webInfo)) | 649 if (!m_impl->getActiveUniform(program, index, webInfo)) |
512 return false; | 650 return false; |
513 info.name = webInfo.name; | 651 info.name = webInfo.name; |
514 info.type = webInfo.type; | 652 info.type = webInfo.type; |
515 info.size = webInfo.size; | 653 info.size = webInfo.size; |
516 return true; | 654 return true; |
517 } | 655 } |
518 | 656 |
519 DELEGATE_TO_WEBCONTEXT_4(getAttachedShaders, Platform3DObject, GC3Dsizei, GC3Dsi
zei*, Platform3DObject*) | 657 DELEGATE_TO_WEBCONTEXT_4(getAttachedShaders, Platform3DObject, GC3Dsizei, GC3Dsi
zei*, Platform3DObject*) |
520 | 658 |
521 GC3Dint GraphicsContext3D::getAttribLocation(Platform3DObject program, const Str
ing& name) | 659 GC3Dint GraphicsContext3D::getAttribLocation(Platform3DObject program, const Str
ing& name) |
522 { | 660 { |
523 return m_private->webContext()->getAttribLocation(program, name.utf8().data(
)); | 661 return m_impl->getAttribLocation(program, name.utf8().data()); |
524 } | 662 } |
525 | 663 |
526 DELEGATE_TO_WEBCONTEXT_2(getBooleanv, GC3Denum, GC3Dboolean*) | 664 DELEGATE_TO_WEBCONTEXT_2(getBooleanv, GC3Denum, GC3Dboolean*) |
527 DELEGATE_TO_WEBCONTEXT_3(getBufferParameteriv, GC3Denum, GC3Denum, GC3Dint*) | 665 DELEGATE_TO_WEBCONTEXT_3(getBufferParameteriv, GC3Denum, GC3Denum, GC3Dint*) |
528 | 666 |
529 GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes() | 667 GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes() |
530 { | 668 { |
531 WebKit::WebGraphicsContext3D::Attributes webAttributes = m_private->webConte
xt()->getContextAttributes(); | 669 WebKit::WebGraphicsContext3D::Attributes webAttributes = m_impl->getContextA
ttributes(); |
532 GraphicsContext3D::Attributes attributes; | 670 GraphicsContext3D::Attributes attributes; |
533 attributes.alpha = webAttributes.alpha; | 671 attributes.alpha = webAttributes.alpha; |
534 attributes.depth = webAttributes.depth; | 672 attributes.depth = webAttributes.depth; |
535 attributes.stencil = webAttributes.stencil; | 673 attributes.stencil = webAttributes.stencil; |
536 attributes.antialias = webAttributes.antialias; | 674 attributes.antialias = webAttributes.antialias; |
537 attributes.premultipliedAlpha = webAttributes.premultipliedAlpha; | 675 attributes.premultipliedAlpha = webAttributes.premultipliedAlpha; |
538 attributes.preserveDrawingBuffer = m_private->preserveDrawingBuffer(); | 676 attributes.preserveDrawingBuffer = m_preserveDrawingBuffer; |
539 attributes.preferDiscreteGPU = webAttributes.preferDiscreteGPU; | 677 attributes.preferDiscreteGPU = webAttributes.preferDiscreteGPU; |
540 return attributes; | 678 return attributes; |
541 } | 679 } |
542 | 680 |
543 DELEGATE_TO_WEBCONTEXT_R(getError, GC3Denum) | 681 DELEGATE_TO_WEBCONTEXT_R(getError, GC3Denum) |
544 DELEGATE_TO_WEBCONTEXT_2(getFloatv, GC3Denum, GC3Dfloat*) | 682 DELEGATE_TO_WEBCONTEXT_2(getFloatv, GC3Denum, GC3Dfloat*) |
545 DELEGATE_TO_WEBCONTEXT_4(getFramebufferAttachmentParameteriv, GC3Denum, GC3Denum
, GC3Denum, GC3Dint*) | 683 DELEGATE_TO_WEBCONTEXT_4(getFramebufferAttachmentParameteriv, GC3Denum, GC3Denum
, GC3Denum, GC3Dint*) |
546 DELEGATE_TO_WEBCONTEXT_2(getIntegerv, GC3Denum, GC3Dint*) | 684 DELEGATE_TO_WEBCONTEXT_2(getIntegerv, GC3Denum, GC3Dint*) |
547 DELEGATE_TO_WEBCONTEXT_3(getProgramiv, Platform3DObject, GC3Denum, GC3Dint*) | 685 DELEGATE_TO_WEBCONTEXT_3(getProgramiv, Platform3DObject, GC3Denum, GC3Dint*) |
548 DELEGATE_TO_WEBCONTEXT_1R(getProgramInfoLog, Platform3DObject, String) | 686 DELEGATE_TO_WEBCONTEXT_1R(getProgramInfoLog, Platform3DObject, String) |
549 DELEGATE_TO_WEBCONTEXT_3(getRenderbufferParameteriv, GC3Denum, GC3Denum, GC3Dint
*) | 687 DELEGATE_TO_WEBCONTEXT_3(getRenderbufferParameteriv, GC3Denum, GC3Denum, GC3Dint
*) |
550 DELEGATE_TO_WEBCONTEXT_3(getShaderiv, Platform3DObject, GC3Denum, GC3Dint*) | 688 DELEGATE_TO_WEBCONTEXT_3(getShaderiv, Platform3DObject, GC3Denum, GC3Dint*) |
551 DELEGATE_TO_WEBCONTEXT_1R(getShaderInfoLog, Platform3DObject, String) | 689 DELEGATE_TO_WEBCONTEXT_1R(getShaderInfoLog, Platform3DObject, String) |
552 DELEGATE_TO_WEBCONTEXT_4(getShaderPrecisionFormat, GC3Denum, GC3Denum, GC3Dint*,
GC3Dint*) | 690 DELEGATE_TO_WEBCONTEXT_4(getShaderPrecisionFormat, GC3Denum, GC3Denum, GC3Dint*,
GC3Dint*) |
553 DELEGATE_TO_WEBCONTEXT_1R(getShaderSource, Platform3DObject, String) | 691 DELEGATE_TO_WEBCONTEXT_1R(getShaderSource, Platform3DObject, String) |
554 DELEGATE_TO_WEBCONTEXT_1R(getString, GC3Denum, String) | 692 DELEGATE_TO_WEBCONTEXT_1R(getString, GC3Denum, String) |
555 DELEGATE_TO_WEBCONTEXT_3(getTexParameterfv, GC3Denum, GC3Denum, GC3Dfloat*) | 693 DELEGATE_TO_WEBCONTEXT_3(getTexParameterfv, GC3Denum, GC3Denum, GC3Dfloat*) |
556 DELEGATE_TO_WEBCONTEXT_3(getTexParameteriv, GC3Denum, GC3Denum, GC3Dint*) | 694 DELEGATE_TO_WEBCONTEXT_3(getTexParameteriv, GC3Denum, GC3Denum, GC3Dint*) |
557 DELEGATE_TO_WEBCONTEXT_3(getUniformfv, Platform3DObject, GC3Dint, GC3Dfloat*) | 695 DELEGATE_TO_WEBCONTEXT_3(getUniformfv, Platform3DObject, GC3Dint, GC3Dfloat*) |
558 DELEGATE_TO_WEBCONTEXT_3(getUniformiv, Platform3DObject, GC3Dint, GC3Dint*) | 696 DELEGATE_TO_WEBCONTEXT_3(getUniformiv, Platform3DObject, GC3Dint, GC3Dint*) |
559 | 697 |
560 GC3Dint GraphicsContext3D::getUniformLocation(Platform3DObject program, const St
ring& name) | 698 GC3Dint GraphicsContext3D::getUniformLocation(Platform3DObject program, const St
ring& name) |
561 { | 699 { |
562 return m_private->webContext()->getUniformLocation(program, name.utf8().data
()); | 700 return m_impl->getUniformLocation(program, name.utf8().data()); |
563 } | 701 } |
564 | 702 |
565 DELEGATE_TO_WEBCONTEXT_3(getVertexAttribfv, GC3Duint, GC3Denum, GC3Dfloat*) | 703 DELEGATE_TO_WEBCONTEXT_3(getVertexAttribfv, GC3Duint, GC3Denum, GC3Dfloat*) |
566 DELEGATE_TO_WEBCONTEXT_3(getVertexAttribiv, GC3Duint, GC3Denum, GC3Dint*) | 704 DELEGATE_TO_WEBCONTEXT_3(getVertexAttribiv, GC3Duint, GC3Denum, GC3Dint*) |
567 DELEGATE_TO_WEBCONTEXT_2R(getVertexAttribOffset, GC3Duint, GC3Denum, GC3Dsizeipt
r) | 705 DELEGATE_TO_WEBCONTEXT_2R(getVertexAttribOffset, GC3Duint, GC3Denum, GC3Dsizeipt
r) |
568 | 706 |
569 DELEGATE_TO_WEBCONTEXT_2(hint, GC3Denum, GC3Denum) | 707 DELEGATE_TO_WEBCONTEXT_2(hint, GC3Denum, GC3Denum) |
570 DELEGATE_TO_WEBCONTEXT_1R(isBuffer, Platform3DObject, GC3Dboolean) | 708 DELEGATE_TO_WEBCONTEXT_1R(isBuffer, Platform3DObject, GC3Dboolean) |
571 DELEGATE_TO_WEBCONTEXT_1R(isEnabled, GC3Denum, GC3Dboolean) | 709 DELEGATE_TO_WEBCONTEXT_1R(isEnabled, GC3Denum, GC3Dboolean) |
572 DELEGATE_TO_WEBCONTEXT_1R(isFramebuffer, Platform3DObject, GC3Dboolean) | 710 DELEGATE_TO_WEBCONTEXT_1R(isFramebuffer, Platform3DObject, GC3Dboolean) |
573 DELEGATE_TO_WEBCONTEXT_1R(isProgram, Platform3DObject, GC3Dboolean) | 711 DELEGATE_TO_WEBCONTEXT_1R(isProgram, Platform3DObject, GC3Dboolean) |
574 DELEGATE_TO_WEBCONTEXT_1R(isRenderbuffer, Platform3DObject, GC3Dboolean) | 712 DELEGATE_TO_WEBCONTEXT_1R(isRenderbuffer, Platform3DObject, GC3Dboolean) |
575 DELEGATE_TO_WEBCONTEXT_1R(isShader, Platform3DObject, GC3Dboolean) | 713 DELEGATE_TO_WEBCONTEXT_1R(isShader, Platform3DObject, GC3Dboolean) |
576 DELEGATE_TO_WEBCONTEXT_1R(isTexture, Platform3DObject, GC3Dboolean) | 714 DELEGATE_TO_WEBCONTEXT_1R(isTexture, Platform3DObject, GC3Dboolean) |
577 DELEGATE_TO_WEBCONTEXT_1(lineWidth, GC3Dfloat) | 715 DELEGATE_TO_WEBCONTEXT_1(lineWidth, GC3Dfloat) |
578 DELEGATE_TO_WEBCONTEXT_1(linkProgram, Platform3DObject) | 716 DELEGATE_TO_WEBCONTEXT_1(linkProgram, Platform3DObject) |
579 DELEGATE_TO_WEBCONTEXT_2(pixelStorei, GC3Denum, GC3Dint) | 717 DELEGATE_TO_WEBCONTEXT_2(pixelStorei, GC3Denum, GC3Dint) |
580 DELEGATE_TO_WEBCONTEXT_2(polygonOffset, GC3Dfloat, GC3Dfloat) | 718 DELEGATE_TO_WEBCONTEXT_2(polygonOffset, GC3Dfloat, GC3Dfloat) |
581 | 719 |
582 DELEGATE_TO_WEBCONTEXT_7(readPixels, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3
Denum, GC3Denum, void*) | 720 DELEGATE_TO_WEBCONTEXT_7(readPixels, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei, GC3
Denum, GC3Denum, void*) |
583 | 721 |
584 DELEGATE_TO_WEBCONTEXT(releaseShaderCompiler) | 722 DELEGATE_TO_WEBCONTEXT(releaseShaderCompiler) |
585 DELEGATE_TO_WEBCONTEXT_4(renderbufferStorage, GC3Denum, GC3Denum, GC3Dsizei, GC3
Dsizei) | 723 DELEGATE_TO_WEBCONTEXT_4(renderbufferStorage, GC3Denum, GC3Denum, GC3Dsizei, GC3
Dsizei) |
586 DELEGATE_TO_WEBCONTEXT_2(sampleCoverage, GC3Dclampf, GC3Dboolean) | 724 DELEGATE_TO_WEBCONTEXT_2(sampleCoverage, GC3Dclampf, GC3Dboolean) |
587 DELEGATE_TO_WEBCONTEXT_4(scissor, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei) | 725 DELEGATE_TO_WEBCONTEXT_4(scissor, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei) |
588 | 726 |
589 void GraphicsContext3D::shaderSource(Platform3DObject shader, const String& stri
ng) | 727 void GraphicsContext3D::shaderSource(Platform3DObject shader, const String& stri
ng) |
590 { | 728 { |
591 m_private->webContext()->shaderSource(shader, string.utf8().data()); | 729 m_impl->shaderSource(shader, string.utf8().data()); |
592 } | 730 } |
593 | 731 |
594 DELEGATE_TO_WEBCONTEXT_3(stencilFunc, GC3Denum, GC3Dint, GC3Duint) | 732 DELEGATE_TO_WEBCONTEXT_3(stencilFunc, GC3Denum, GC3Dint, GC3Duint) |
595 DELEGATE_TO_WEBCONTEXT_4(stencilFuncSeparate, GC3Denum, GC3Denum, GC3Dint, GC3Du
int) | 733 DELEGATE_TO_WEBCONTEXT_4(stencilFuncSeparate, GC3Denum, GC3Denum, GC3Dint, GC3Du
int) |
596 DELEGATE_TO_WEBCONTEXT_1(stencilMask, GC3Duint) | 734 DELEGATE_TO_WEBCONTEXT_1(stencilMask, GC3Duint) |
597 DELEGATE_TO_WEBCONTEXT_2(stencilMaskSeparate, GC3Denum, GC3Duint) | 735 DELEGATE_TO_WEBCONTEXT_2(stencilMaskSeparate, GC3Denum, GC3Duint) |
598 DELEGATE_TO_WEBCONTEXT_3(stencilOp, GC3Denum, GC3Denum, GC3Denum) | 736 DELEGATE_TO_WEBCONTEXT_3(stencilOp, GC3Denum, GC3Denum, GC3Denum) |
599 DELEGATE_TO_WEBCONTEXT_4(stencilOpSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Den
um) | 737 DELEGATE_TO_WEBCONTEXT_4(stencilOpSeparate, GC3Denum, GC3Denum, GC3Denum, GC3Den
um) |
600 | 738 |
601 DELEGATE_TO_WEBCONTEXT_9(texImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dsizei, GC3
Dsizei, GC3Dint, GC3Denum, GC3Denum, const void*) | 739 DELEGATE_TO_WEBCONTEXT_9(texImage2D, GC3Denum, GC3Dint, GC3Denum, GC3Dsizei, GC3
Dsizei, GC3Dint, GC3Denum, GC3Denum, const void*) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 DELEGATE_TO_WEBCONTEXT_4(vertexAttrib3f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dflo
at) | 771 DELEGATE_TO_WEBCONTEXT_4(vertexAttrib3f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dflo
at) |
634 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib3fv, GC3Duint, GC3Dfloat*) | 772 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib3fv, GC3Duint, GC3Dfloat*) |
635 DELEGATE_TO_WEBCONTEXT_5(vertexAttrib4f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dflo
at, GC3Dfloat) | 773 DELEGATE_TO_WEBCONTEXT_5(vertexAttrib4f, GC3Duint, GC3Dfloat, GC3Dfloat, GC3Dflo
at, GC3Dfloat) |
636 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib4fv, GC3Duint, GC3Dfloat*) | 774 DELEGATE_TO_WEBCONTEXT_2(vertexAttrib4fv, GC3Duint, GC3Dfloat*) |
637 DELEGATE_TO_WEBCONTEXT_6(vertexAttribPointer, GC3Duint, GC3Dint, GC3Denum, GC3Db
oolean, GC3Dsizei, GC3Dintptr) | 775 DELEGATE_TO_WEBCONTEXT_6(vertexAttribPointer, GC3Duint, GC3Dint, GC3Denum, GC3Db
oolean, GC3Dsizei, GC3Dintptr) |
638 | 776 |
639 DELEGATE_TO_WEBCONTEXT_4(viewport, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei) | 777 DELEGATE_TO_WEBCONTEXT_4(viewport, GC3Dint, GC3Dint, GC3Dsizei, GC3Dsizei) |
640 | 778 |
641 void GraphicsContext3D::reshape(int width, int height) | 779 void GraphicsContext3D::reshape(int width, int height) |
642 { | 780 { |
643 if (width == m_private->webContext()->width() && height == m_private->webCon
text()->height()) | 781 if (width == m_impl->width() && height == m_impl->height()) |
644 return; | 782 return; |
645 | 783 |
646 m_private->webContext()->reshape(width, height); | 784 m_impl->reshape(width, height); |
647 } | 785 } |
648 | 786 |
649 void GraphicsContext3D::markContextChanged() | 787 void GraphicsContext3D::markContextChanged() |
650 { | 788 { |
651 m_private->markContextChanged(); | 789 m_layerComposited = false; |
652 } | 790 } |
653 | 791 |
654 bool GraphicsContext3D::layerComposited() const | 792 bool GraphicsContext3D::layerComposited() const |
655 { | 793 { |
656 return m_private->layerComposited(); | 794 return m_layerComposited; |
657 } | 795 } |
658 | 796 |
659 void GraphicsContext3D::markLayerComposited() | 797 void GraphicsContext3D::markLayerComposited() |
660 { | 798 { |
661 m_private->markLayerComposited(); | 799 m_layerComposited = true; |
662 } | 800 } |
663 | 801 |
664 void GraphicsContext3D::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer,
DrawingBuffer* drawingBuffer) | 802 void GraphicsContext3D::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer,
DrawingBuffer* drawingBuffer) |
665 { | 803 { |
666 Platform3DObject framebufferId; | 804 Platform3DObject framebufferId; |
667 int width, height; | 805 int width, height; |
668 getDrawingParameters(drawingBuffer, m_private->webContext(), &framebufferId,
&width, &height); | 806 getDrawingParameters(drawingBuffer, m_impl, &framebufferId, &width, &height)
; |
669 m_private->paintFramebufferToCanvas(framebufferId, width, height, !getContex
tAttributes().premultipliedAlpha, imageBuffer); | 807 paintFramebufferToCanvas(framebufferId, width, height, !getContextAttributes
().premultipliedAlpha, imageBuffer); |
670 } | 808 } |
671 | 809 |
672 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(Drawin
gBuffer* drawingBuffer) | 810 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(Drawin
gBuffer* drawingBuffer) |
673 { | 811 { |
674 if (getContextAttributes().premultipliedAlpha) | 812 if (getContextAttributes().premultipliedAlpha) |
675 return 0; | 813 return 0; |
676 | 814 |
677 Platform3DObject framebufferId; | 815 Platform3DObject framebufferId; |
678 int width, height; | 816 int width, height; |
679 getDrawingParameters(drawingBuffer, m_private->webContext(), &framebufferId,
&width, &height); | 817 getDrawingParameters(drawingBuffer, m_impl, &framebufferId, &width, &height)
; |
680 | 818 |
681 RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height)); | 819 RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height)); |
682 unsigned char* pixels = imageData->data()->data(); | 820 unsigned char* pixels = imageData->data()->data(); |
683 size_t bufferSize = 4 * width * height; | 821 size_t bufferSize = 4 * width * height; |
684 | 822 |
685 m_private->webContext()->readBackFramebuffer(pixels, bufferSize, framebuffer
Id, width, height); | 823 m_impl->readBackFramebuffer(pixels, bufferSize, framebufferId, width, height
); |
686 | 824 |
687 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT | 825 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT |
688 // If the implementation swapped the red and blue channels, un-swap them. | 826 // If the implementation swapped the red and blue channels, un-swap them. |
689 for (size_t i = 0; i < bufferSize; i += 4) | 827 for (size_t i = 0; i < bufferSize; i += 4) |
690 std::swap(pixels[i], pixels[i + 2]); | 828 std::swap(pixels[i], pixels[i + 2]); |
691 #endif | 829 #endif |
692 | 830 |
693 return imageData.release(); | 831 return imageData.release(); |
694 } | 832 } |
695 | 833 |
696 bool GraphicsContext3D::paintCompositedResultsToCanvas(ImageBuffer*) | |
697 { | |
698 return false; | |
699 } | |
700 | |
701 DELEGATE_TO_WEBCONTEXT_R(createBuffer, Platform3DObject) | 834 DELEGATE_TO_WEBCONTEXT_R(createBuffer, Platform3DObject) |
702 DELEGATE_TO_WEBCONTEXT_R(createFramebuffer, Platform3DObject) | 835 DELEGATE_TO_WEBCONTEXT_R(createFramebuffer, Platform3DObject) |
703 DELEGATE_TO_WEBCONTEXT_R(createProgram, Platform3DObject) | 836 DELEGATE_TO_WEBCONTEXT_R(createProgram, Platform3DObject) |
704 DELEGATE_TO_WEBCONTEXT_R(createRenderbuffer, Platform3DObject) | 837 DELEGATE_TO_WEBCONTEXT_R(createRenderbuffer, Platform3DObject) |
705 DELEGATE_TO_WEBCONTEXT_1R(createShader, GC3Denum, Platform3DObject) | 838 DELEGATE_TO_WEBCONTEXT_1R(createShader, GC3Denum, Platform3DObject) |
706 DELEGATE_TO_WEBCONTEXT_R(createTexture, Platform3DObject) | 839 DELEGATE_TO_WEBCONTEXT_R(createTexture, Platform3DObject) |
707 | 840 |
708 DELEGATE_TO_WEBCONTEXT_1(deleteBuffer, Platform3DObject) | 841 DELEGATE_TO_WEBCONTEXT_1(deleteBuffer, Platform3DObject) |
709 DELEGATE_TO_WEBCONTEXT_1(deleteFramebuffer, Platform3DObject) | 842 DELEGATE_TO_WEBCONTEXT_1(deleteFramebuffer, Platform3DObject) |
710 DELEGATE_TO_WEBCONTEXT_1(deleteProgram, Platform3DObject) | 843 DELEGATE_TO_WEBCONTEXT_1(deleteProgram, Platform3DObject) |
711 DELEGATE_TO_WEBCONTEXT_1(deleteRenderbuffer, Platform3DObject) | 844 DELEGATE_TO_WEBCONTEXT_1(deleteRenderbuffer, Platform3DObject) |
712 DELEGATE_TO_WEBCONTEXT_1(deleteShader, Platform3DObject) | 845 DELEGATE_TO_WEBCONTEXT_1(deleteShader, Platform3DObject) |
713 DELEGATE_TO_WEBCONTEXT_1(deleteTexture, Platform3DObject) | 846 DELEGATE_TO_WEBCONTEXT_1(deleteTexture, Platform3DObject) |
714 | 847 |
715 DELEGATE_TO_WEBCONTEXT_1(synthesizeGLError, GC3Denum) | 848 DELEGATE_TO_WEBCONTEXT_1(synthesizeGLError, GC3Denum) |
716 | 849 |
717 Extensions3D* GraphicsContext3D::getExtensions() | 850 Extensions3D* GraphicsContext3D::getExtensions() |
718 { | 851 { |
719 return m_private->getExtensions(); | 852 if (!m_extensions) |
| 853 m_extensions = adoptPtr(new Extensions3D(this)); |
| 854 return m_extensions.get(); |
720 } | 855 } |
721 | 856 |
722 bool GraphicsContext3D::texImage2DResourceSafe(GC3Denum target, GC3Dint level, G
C3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3De
num format, GC3Denum type, GC3Dint unpackAlignment) | 857 bool GraphicsContext3D::texImage2DResourceSafe(GC3Denum target, GC3Dint level, G
C3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3De
num format, GC3Denum type, GC3Dint unpackAlignment) |
723 { | 858 { |
724 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); | 859 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); |
725 OwnArrayPtr<unsigned char> zero; | 860 OwnArrayPtr<unsigned char> zero; |
726 if (!isResourceSafe() && width > 0 && height > 0) { | 861 if (!isResourceSafe() && width > 0 && height > 0) { |
727 unsigned int size; | 862 unsigned int size; |
728 GC3Denum error = computeImageSizeInBytes(format, type, width, height, un
packAlignment, &size, 0); | 863 GC3Denum error = computeImageSizeInBytes(format, type, width, height, un
packAlignment, &size, 0); |
729 if (error != GraphicsContext3D::NO_ERROR) { | 864 if (error != GraphicsContext3D::NO_ERROR) { |
(...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2308 return ChannelDepth; | 2443 return ChannelDepth; |
2309 case GraphicsContext3D::STENCIL_INDEX8: | 2444 case GraphicsContext3D::STENCIL_INDEX8: |
2310 return ChannelStencil; | 2445 return ChannelStencil; |
2311 case GraphicsContext3D::DEPTH_STENCIL: | 2446 case GraphicsContext3D::DEPTH_STENCIL: |
2312 return ChannelDepth | ChannelStencil; | 2447 return ChannelDepth | ChannelStencil; |
2313 default: | 2448 default: |
2314 return 0; | 2449 return 0; |
2315 } | 2450 } |
2316 } | 2451 } |
2317 | 2452 |
| 2453 void GraphicsContext3D::paintFramebufferToCanvas(int framebuffer, int width, int
height, bool premultiplyAlpha, ImageBuffer* imageBuffer) |
| 2454 { |
| 2455 unsigned char* pixels = 0; |
| 2456 size_t bufferSize = 4 * width * height; |
| 2457 |
| 2458 const SkBitmap* canvasBitmap = imageBuffer->context()->bitmap(); |
| 2459 const SkBitmap* readbackBitmap = 0; |
| 2460 ASSERT(canvasBitmap->config() == SkBitmap::kARGB_8888_Config); |
| 2461 if (canvasBitmap->width() == width && canvasBitmap->height() == height) { |
| 2462 // This is the fastest and most common case. We read back |
| 2463 // directly into the canvas's backing store. |
| 2464 readbackBitmap = canvasBitmap; |
| 2465 m_resizingBitmap.reset(); |
| 2466 } else { |
| 2467 // We need to allocate a temporary bitmap for reading back the |
| 2468 // pixel data. We will then use Skia to rescale this bitmap to |
| 2469 // the size of the canvas's backing store. |
| 2470 if (m_resizingBitmap.width() != width || m_resizingBitmap.height() != he
ight) { |
| 2471 m_resizingBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, heigh
t); |
| 2472 if (!m_resizingBitmap.allocPixels()) |
| 2473 return; |
| 2474 } |
| 2475 readbackBitmap = &m_resizingBitmap; |
| 2476 } |
| 2477 |
| 2478 // Read back the frame buffer. |
| 2479 SkAutoLockPixels bitmapLock(*readbackBitmap); |
| 2480 pixels = static_cast<unsigned char*>(readbackBitmap->getPixels()); |
| 2481 |
| 2482 m_impl->readBackFramebuffer(pixels, 4 * width * height, framebuffer, width,
height); |
| 2483 |
| 2484 if (premultiplyAlpha) { |
| 2485 for (size_t i = 0; i < bufferSize; i += 4) { |
| 2486 pixels[i + 0] = std::min(255, pixels[i + 0] * pixels[i + 3] / 255); |
| 2487 pixels[i + 1] = std::min(255, pixels[i + 1] * pixels[i + 3] / 255); |
| 2488 pixels[i + 2] = std::min(255, pixels[i + 2] * pixels[i + 3] / 255); |
| 2489 } |
| 2490 } |
| 2491 |
| 2492 readbackBitmap->notifyPixelsChanged(); |
| 2493 if (m_resizingBitmap.readyToDraw()) { |
| 2494 // We need to draw the resizing bitmap into the canvas's backing store. |
| 2495 SkCanvas canvas(*canvasBitmap); |
| 2496 SkRect dst; |
| 2497 dst.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(canvasBitmap->
width()), SkIntToScalar(canvasBitmap->height())); |
| 2498 canvas.drawBitmapRect(m_resizingBitmap, 0, dst); |
| 2499 } |
| 2500 } |
| 2501 |
| 2502 namespace { |
| 2503 |
| 2504 void splitStringHelper(const String& str, HashSet<String>& set) |
| 2505 { |
| 2506 Vector<String> substrings; |
| 2507 str.split(" ", substrings); |
| 2508 for (size_t i = 0; i < substrings.size(); ++i) |
| 2509 set.add(substrings[i]); |
| 2510 } |
| 2511 |
| 2512 String mapExtensionName(const String& name) |
| 2513 { |
| 2514 if (name == "GL_ANGLE_framebuffer_blit" |
| 2515 || name == "GL_ANGLE_framebuffer_multisample") |
| 2516 return "GL_CHROMIUM_framebuffer_multisample"; |
| 2517 return name; |
| 2518 } |
| 2519 |
| 2520 } // anonymous namespace |
| 2521 |
| 2522 void GraphicsContext3D::initializeExtensions() |
| 2523 { |
| 2524 if (m_initializedAvailableExtensions) |
| 2525 return; |
| 2526 |
| 2527 m_initializedAvailableExtensions = true; |
| 2528 bool success = m_impl->makeContextCurrent(); |
| 2529 ASSERT(success); |
| 2530 if (!success) |
| 2531 return; |
| 2532 |
| 2533 String extensionsString = m_impl->getString(GraphicsContext3D::EXTENSIONS); |
| 2534 splitStringHelper(extensionsString, m_enabledExtensions); |
| 2535 |
| 2536 String requestableExtensionsString = m_impl->getRequestableExtensionsCHROMIU
M(); |
| 2537 splitStringHelper(requestableExtensionsString, m_requestableExtensions); |
| 2538 } |
| 2539 |
| 2540 |
| 2541 bool GraphicsContext3D::supportsExtension(const String& name) |
| 2542 { |
| 2543 initializeExtensions(); |
| 2544 String mappedName = mapExtensionName(name); |
| 2545 return m_enabledExtensions.contains(mappedName) || m_requestableExtensions.c
ontains(mappedName); |
| 2546 } |
| 2547 |
| 2548 bool GraphicsContext3D::ensureExtensionEnabled(const String& name) |
| 2549 { |
| 2550 initializeExtensions(); |
| 2551 |
| 2552 String mappedName = mapExtensionName(name); |
| 2553 if (m_enabledExtensions.contains(mappedName)) |
| 2554 return true; |
| 2555 |
| 2556 if (m_requestableExtensions.contains(mappedName)) { |
| 2557 m_impl->requestExtensionCHROMIUM(mappedName.ascii().data()); |
| 2558 m_enabledExtensions.clear(); |
| 2559 m_requestableExtensions.clear(); |
| 2560 m_initializedAvailableExtensions = false; |
| 2561 } |
| 2562 |
| 2563 initializeExtensions(); |
| 2564 return m_enabledExtensions.contains(mappedName); |
| 2565 } |
| 2566 |
| 2567 bool GraphicsContext3D::isExtensionEnabled(const String& name) |
| 2568 { |
| 2569 initializeExtensions(); |
| 2570 String mappedName = mapExtensionName(name); |
| 2571 return m_enabledExtensions.contains(mappedName); |
| 2572 } |
| 2573 |
2318 } // namespace WebCore | 2574 } // namespace WebCore |
OLD | NEW |