OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef GraphicsContext3D_h | 26 #ifndef GraphicsContext3D_h |
27 #define GraphicsContext3D_h | 27 #define GraphicsContext3D_h |
28 | 28 |
| 29 #include "SkBitmap.h" |
29 #include "core/platform/KURL.h" | 30 #include "core/platform/KURL.h" |
| 31 #include "core/platform/graphics/Extensions3D.h" |
30 #include "core/platform/graphics/GraphicsTypes3D.h" | 32 #include "core/platform/graphics/GraphicsTypes3D.h" |
31 #include "core/platform/graphics/Image.h" | 33 #include "core/platform/graphics/Image.h" |
32 #include "core/platform/graphics/IntRect.h" | 34 #include "core/platform/graphics/IntRect.h" |
33 #include "core/platform/graphics/PlatformLayer.h" | 35 #include "core/platform/graphics/PlatformLayer.h" |
34 #include <wtf/HashMap.h> | 36 #include "wtf/HashMap.h" |
35 #include <wtf/ListHashSet.h> | 37 #include "wtf/HashSet.h" |
36 #include <wtf/Noncopyable.h> | 38 #include "wtf/ListHashSet.h" |
37 #include <wtf/OwnArrayPtr.h> | 39 #include "wtf/Noncopyable.h" |
38 #include <wtf/PassOwnArrayPtr.h> | 40 #include "wtf/OwnArrayPtr.h" |
39 #include <wtf/RefCounted.h> | 41 #include "wtf/OwnPtr.h" |
40 #include <wtf/text/WTFString.h> | 42 #include "wtf/PassOwnArrayPtr.h" |
| 43 #include "wtf/RefCounted.h" |
| 44 #include "wtf/text/WTFString.h" |
41 | 45 |
42 // FIXME: Find a better way to avoid the name confliction for NO_ERROR. | 46 // FIXME: Find a better way to avoid the name confliction for NO_ERROR. |
43 #if OS(WINDOWS) | 47 #if OS(WINDOWS) |
44 #undef NO_ERROR | 48 #undef NO_ERROR |
45 #endif | 49 #endif |
46 | 50 |
47 class GrContext; | 51 class GrContext; |
48 | 52 |
| 53 namespace WebKit { |
| 54 class WebGraphicsContext3D; |
| 55 class WebGraphicsContext3DProvider; |
| 56 } |
| 57 |
49 namespace WebCore { | 58 namespace WebCore { |
50 class DrawingBuffer; | 59 class DrawingBuffer; |
51 class Extensions3D; | 60 class Extensions3D; |
| 61 class GraphicsContext3DContextLostCallbackAdapter; |
| 62 class GraphicsContext3DErrorMessageCallbackAdapter; |
| 63 class GrMemoryAllocationChangedCallbackAdapter; |
52 class Image; | 64 class Image; |
53 class ImageBuffer; | 65 class ImageBuffer; |
54 class ImageData; | 66 class ImageData; |
55 class IntRect; | 67 class IntRect; |
56 class IntSize; | 68 class IntSize; |
57 | 69 |
58 struct ActiveInfo { | 70 struct ActiveInfo { |
59 String name; | 71 String name; |
60 GC3Denum type; | 72 GC3Denum type; |
61 GC3Dint size; | 73 GC3Dint size; |
62 }; | 74 }; |
63 | 75 |
64 class GraphicsContext3DPrivate; | |
65 | |
66 class GraphicsContext3D : public RefCounted<GraphicsContext3D> { | 76 class GraphicsContext3D : public RefCounted<GraphicsContext3D> { |
67 public: | 77 public: |
68 enum { | 78 enum { |
69 DEPTH_BUFFER_BIT = 0x00000100, | 79 DEPTH_BUFFER_BIT = 0x00000100, |
70 STENCIL_BUFFER_BIT = 0x00000400, | 80 STENCIL_BUFFER_BIT = 0x00000400, |
71 COLOR_BUFFER_BIT = 0x00004000, | 81 COLOR_BUFFER_BIT = 0x00004000, |
72 POINTS = 0x0000, | 82 POINTS = 0x0000, |
73 LINES = 0x0001, | 83 LINES = 0x0001, |
74 LINE_LOOP = 0x0002, | 84 LINE_LOOP = 0x0002, |
75 LINE_STRIP = 0x0003, | 85 LINE_STRIP = 0x0003, |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 class ErrorMessageCallback { | 425 class ErrorMessageCallback { |
416 public: | 426 public: |
417 virtual void onErrorMessage(const String& message, GC3Dint id) = 0; | 427 virtual void onErrorMessage(const String& message, GC3Dint id) = 0; |
418 virtual ~ErrorMessageCallback() { } | 428 virtual ~ErrorMessageCallback() { } |
419 }; | 429 }; |
420 | 430 |
421 void setContextLostCallback(PassOwnPtr<ContextLostCallback>); | 431 void setContextLostCallback(PassOwnPtr<ContextLostCallback>); |
422 void setErrorMessageCallback(PassOwnPtr<ErrorMessageCallback>); | 432 void setErrorMessageCallback(PassOwnPtr<ErrorMessageCallback>); |
423 | 433 |
424 static PassRefPtr<GraphicsContext3D> create(Attributes); | 434 static PassRefPtr<GraphicsContext3D> create(Attributes); |
425 static PassRefPtr<GraphicsContext3D> createForCurrentGLContext(); | 435 |
| 436 // Callers must make the context current before using it AND check that the
context was created successfully |
| 437 // via ContextLost before using the context in any way. Once made current on
a thread, the context cannot |
| 438 // be used on any other thread. |
| 439 static PassRefPtr<GraphicsContext3D> createGraphicsContextFromWebContext(Pas
sOwnPtr<WebKit::WebGraphicsContext3D>, bool preserveDrawingBuffer = false); |
| 440 static PassRefPtr<GraphicsContext3D> createGraphicsContextFromProvider(PassO
wnPtr<WebKit::WebGraphicsContext3DProvider>, bool preserveDrawingBuffer = false)
; |
| 441 |
426 ~GraphicsContext3D(); | 442 ~GraphicsContext3D(); |
427 | 443 |
428 GrContext* grContext(); | 444 GrContext* grContext(); |
| 445 WebKit::WebGraphicsContext3D* webContext() const { return m_impl; } |
| 446 |
429 bool makeContextCurrent(); | 447 bool makeContextCurrent(); |
430 | 448 |
431 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0. | 449 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0. |
432 // Return true if no GL error is synthesized. | 450 // Return true if no GL error is synthesized. |
433 // By default, alignment is 4, the OpenGL default setting. | 451 // By default, alignment is 4, the OpenGL default setting. |
434 bool texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum interna
lformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3
Denum type, GC3Dint alignment = 4); | 452 bool texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum interna
lformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3
Denum type, GC3Dint alignment = 4); |
435 | 453 |
436 //---------------------------------------------------------------------- | 454 //---------------------------------------------------------------------- |
437 // Helpers for texture uploading and pixel readback. | 455 // Helpers for texture uploading and pixel readback. |
438 // | 456 // |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); | 689 void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); |
672 | 690 |
673 void reshape(int width, int height); | 691 void reshape(int width, int height); |
674 | 692 |
675 void markContextChanged(); | 693 void markContextChanged(); |
676 void markLayerComposited(); | 694 void markLayerComposited(); |
677 bool layerComposited() const; | 695 bool layerComposited() const; |
678 | 696 |
679 void paintRenderingResultsToCanvas(ImageBuffer*, DrawingBuffer*); | 697 void paintRenderingResultsToCanvas(ImageBuffer*, DrawingBuffer*); |
680 PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*); | 698 PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*); |
681 bool paintCompositedResultsToCanvas(ImageBuffer*); | |
682 | 699 |
683 // Support for buffer creation and deletion | 700 // Support for buffer creation and deletion |
684 Platform3DObject createBuffer(); | 701 Platform3DObject createBuffer(); |
685 Platform3DObject createFramebuffer(); | 702 Platform3DObject createFramebuffer(); |
686 Platform3DObject createProgram(); | 703 Platform3DObject createProgram(); |
687 Platform3DObject createRenderbuffer(); | 704 Platform3DObject createRenderbuffer(); |
688 Platform3DObject createShader(GC3Denum); | 705 Platform3DObject createShader(GC3Denum); |
689 Platform3DObject createTexture(); | 706 Platform3DObject createTexture(); |
690 | 707 |
691 void deleteBuffer(Platform3DObject); | 708 void deleteBuffer(Platform3DObject); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 bool m_extractSucceeded; | 791 bool m_extractSucceeded; |
775 const void* m_imagePixelData; | 792 const void* m_imagePixelData; |
776 unsigned m_imageWidth; | 793 unsigned m_imageWidth; |
777 unsigned m_imageHeight; | 794 unsigned m_imageHeight; |
778 DataFormat m_imageSourceFormat; | 795 DataFormat m_imageSourceFormat; |
779 AlphaOp m_alphaOp; | 796 AlphaOp m_alphaOp; |
780 unsigned m_imageSourceUnpackAlignment; | 797 unsigned m_imageSourceUnpackAlignment; |
781 }; | 798 }; |
782 | 799 |
783 private: | 800 private: |
784 GraphicsContext3D(); | 801 friend class Extensions3D; |
| 802 |
| 803 GraphicsContext3D(PassOwnPtr<WebKit::WebGraphicsContext3D>, bool preserveDra
wingBuffer); |
| 804 GraphicsContext3D(PassOwnPtr<WebKit::WebGraphicsContext3DProvider>, bool pre
serveDrawingBuffer); |
785 | 805 |
786 // Helper for packImageData/extractImageData/extractTextureData which implem
ent packing of pixel | 806 // Helper for packImageData/extractImageData/extractTextureData which implem
ent packing of pixel |
787 // data into the specified OpenGL destination format and type. | 807 // data into the specified OpenGL destination format and type. |
788 // A sourceUnpackAlignment of zero indicates that the source | 808 // A sourceUnpackAlignment of zero indicates that the source |
789 // data is tightly packed. Non-zero values may take a slow path. | 809 // data is tightly packed. Non-zero values may take a slow path. |
790 // Destination data will have no gaps between rows. | 810 // Destination data will have no gaps between rows. |
791 static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataForma
t, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned des
tinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool f
lipY); | 811 static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataForma
t, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned des
tinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool f
lipY); |
792 | 812 |
| 813 void paintFramebufferToCanvas(int framebuffer, int width, int height, bool p
remultiplyAlpha, ImageBuffer*); |
| 814 |
| 815 // Extensions3D support. |
| 816 bool supportsExtension(const String& name); |
| 817 bool ensureExtensionEnabled(const String& name); |
| 818 bool isExtensionEnabled(const String& name); |
| 819 |
| 820 void initializeExtensions(); |
| 821 |
793 bool isResourceSafe(); | 822 bool isResourceSafe(); |
794 | 823 |
795 friend class GraphicsContext3DPrivate; | 824 bool preserveDrawingBuffer() const { return m_preserveDrawingBuffer; } |
796 OwnPtr<GraphicsContext3DPrivate> m_private; | 825 |
| 826 OwnPtr<WebKit::WebGraphicsContext3DProvider> m_provider; |
| 827 WebKit::WebGraphicsContext3D* m_impl; |
| 828 OwnPtr<WebKit::WebGraphicsContext3D> m_ownedWebContext; |
| 829 OwnPtr<Extensions3D> m_extensions; |
| 830 OwnPtr<GraphicsContext3DContextLostCallbackAdapter> m_contextLostCallbackAda
pter; |
| 831 OwnPtr<GraphicsContext3DErrorMessageCallbackAdapter> m_errorMessageCallbackA
dapter; |
| 832 OwnPtr<GrMemoryAllocationChangedCallbackAdapter> m_grContextMemoryAllocation
CallbackAdapter; |
| 833 bool m_initializedAvailableExtensions; |
| 834 HashSet<String> m_enabledExtensions; |
| 835 HashSet<String> m_requestableExtensions; |
| 836 bool m_layerComposited; |
| 837 bool m_preserveDrawingBuffer; |
| 838 |
| 839 enum ResourceSafety { |
| 840 ResourceSafetyUnknown, |
| 841 ResourceSafe, |
| 842 ResourceUnsafe |
| 843 }; |
| 844 ResourceSafety m_resourceSafety; |
| 845 |
| 846 // If the width and height of the Canvas's backing store don't |
| 847 // match those that we were given in the most recent call to |
| 848 // reshape(), then we need an intermediate bitmap to read back the |
| 849 // frame buffer into. This seems to happen when CSS styles are |
| 850 // used to resize the Canvas. |
| 851 SkBitmap m_resizingBitmap; |
| 852 |
| 853 GrContext* m_grContext; |
| 854 SkAutoTUnref<GrContext> m_ownedGrContext; |
797 }; | 855 }; |
798 | 856 |
799 } // namespace WebCore | 857 } // namespace WebCore |
800 | 858 |
801 #endif // GraphicsContext3D_h | 859 #endif // GraphicsContext3D_h |
OLD | NEW |