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 | |
447 // Helper function to provide access to the lower-level WebGraphicsContext3D , | |
448 // which is needed for subordinate contexts like WebGL's to share resources | |
449 // with the compositor's context. | |
450 static WebKit::WebGraphicsContext3D* extractWebGraphicsContext3D(GraphicsCon text3D*); | |
Zhenyao Mo
2013/05/17 19:38:46
This is no longer needed. You can just use webCon
| |
451 | |
429 bool makeContextCurrent(); | 452 bool makeContextCurrent(); |
430 | 453 |
431 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0. | 454 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0. |
432 // Return true if no GL error is synthesized. | 455 // Return true if no GL error is synthesized. |
433 // By default, alignment is 4, the OpenGL default setting. | 456 // 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); | 457 bool texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum interna lformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3 Denum type, GC3Dint alignment = 4); |
435 | 458 |
436 //---------------------------------------------------------------------- | 459 //---------------------------------------------------------------------- |
437 // Helpers for texture uploading and pixel readback. | 460 // Helpers for texture uploading and pixel readback. |
438 // | 461 // |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
671 void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); | 694 void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); |
672 | 695 |
673 void reshape(int width, int height); | 696 void reshape(int width, int height); |
674 | 697 |
675 void markContextChanged(); | 698 void markContextChanged(); |
676 void markLayerComposited(); | 699 void markLayerComposited(); |
677 bool layerComposited() const; | 700 bool layerComposited() const; |
678 | 701 |
679 void paintRenderingResultsToCanvas(ImageBuffer*, DrawingBuffer*); | 702 void paintRenderingResultsToCanvas(ImageBuffer*, DrawingBuffer*); |
680 PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*); | 703 PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*); |
681 bool paintCompositedResultsToCanvas(ImageBuffer*); | |
682 | 704 |
683 // Support for buffer creation and deletion | 705 // Support for buffer creation and deletion |
684 Platform3DObject createBuffer(); | 706 Platform3DObject createBuffer(); |
685 Platform3DObject createFramebuffer(); | 707 Platform3DObject createFramebuffer(); |
686 Platform3DObject createProgram(); | 708 Platform3DObject createProgram(); |
687 Platform3DObject createRenderbuffer(); | 709 Platform3DObject createRenderbuffer(); |
688 Platform3DObject createShader(GC3Denum); | 710 Platform3DObject createShader(GC3Denum); |
689 Platform3DObject createTexture(); | 711 Platform3DObject createTexture(); |
690 | 712 |
691 void deleteBuffer(Platform3DObject); | 713 void deleteBuffer(Platform3DObject); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 bool m_extractSucceeded; | 796 bool m_extractSucceeded; |
775 const void* m_imagePixelData; | 797 const void* m_imagePixelData; |
776 unsigned m_imageWidth; | 798 unsigned m_imageWidth; |
777 unsigned m_imageHeight; | 799 unsigned m_imageHeight; |
778 DataFormat m_imageSourceFormat; | 800 DataFormat m_imageSourceFormat; |
779 AlphaOp m_alphaOp; | 801 AlphaOp m_alphaOp; |
780 unsigned m_imageSourceUnpackAlignment; | 802 unsigned m_imageSourceUnpackAlignment; |
781 }; | 803 }; |
782 | 804 |
783 private: | 805 private: |
784 GraphicsContext3D(); | 806 friend class Extensions3D; |
807 | |
808 GraphicsContext3D(PassOwnPtr<WebKit::WebGraphicsContext3D>, bool preserveDra wingBuffer); | |
809 GraphicsContext3D(PassOwnPtr<WebKit::WebGraphicsContext3DProvider>, bool pre serveDrawingBuffer); | |
785 | 810 |
786 // Helper for packImageData/extractImageData/extractTextureData which implem ent packing of pixel | 811 // Helper for packImageData/extractImageData/extractTextureData which implem ent packing of pixel |
787 // data into the specified OpenGL destination format and type. | 812 // data into the specified OpenGL destination format and type. |
788 // A sourceUnpackAlignment of zero indicates that the source | 813 // A sourceUnpackAlignment of zero indicates that the source |
789 // data is tightly packed. Non-zero values may take a slow path. | 814 // data is tightly packed. Non-zero values may take a slow path. |
790 // Destination data will have no gaps between rows. | 815 // 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); | 816 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 | 817 |
818 void paintFramebufferToCanvas(int framebuffer, int width, int height, bool p remultiplyAlpha, ImageBuffer*); | |
819 | |
820 // Extensions3D support. | |
821 bool supportsExtension(const String& name); | |
822 bool ensureExtensionEnabled(const String& name); | |
823 bool isExtensionEnabled(const String& name); | |
824 | |
825 void initializeExtensions(); | |
826 | |
793 bool isResourceSafe(); | 827 bool isResourceSafe(); |
794 | 828 |
795 friend class GraphicsContext3DPrivate; | 829 bool preserveDrawingBuffer() const { return m_preserveDrawingBuffer; } |
796 OwnPtr<GraphicsContext3DPrivate> m_private; | 830 |
831 OwnPtr<WebKit::WebGraphicsContext3DProvider> m_provider; | |
832 WebKit::WebGraphicsContext3D* m_impl; | |
833 OwnPtr<WebKit::WebGraphicsContext3D> m_ownedWebContext; | |
834 OwnPtr<Extensions3D> m_extensions; | |
835 OwnPtr<GraphicsContext3DContextLostCallbackAdapter> m_contextLostCallbackAda pter; | |
836 OwnPtr<GraphicsContext3DErrorMessageCallbackAdapter> m_errorMessageCallbackA dapter; | |
837 OwnPtr<GrMemoryAllocationChangedCallbackAdapter> m_grContextMemoryAllocation CallbackAdapter; | |
838 bool m_initializedAvailableExtensions; | |
839 HashSet<String> m_enabledExtensions; | |
840 HashSet<String> m_requestableExtensions; | |
841 bool m_layerComposited; | |
842 bool m_preserveDrawingBuffer; | |
843 | |
844 enum ResourceSafety { | |
845 ResourceSafetyUnknown, | |
846 ResourceSafe, | |
847 ResourceUnsafe | |
848 }; | |
849 ResourceSafety m_resourceSafety; | |
850 | |
851 // If the width and height of the Canvas's backing store don't | |
852 // match those that we were given in the most recent call to | |
853 // reshape(), then we need an intermediate bitmap to read back the | |
854 // frame buffer into. This seems to happen when CSS styles are | |
855 // used to resize the Canvas. | |
856 SkBitmap m_resizingBitmap; | |
857 | |
858 GrContext* m_grContext; | |
859 SkAutoTUnref<GrContext> m_ownedGrContext; | |
797 }; | 860 }; |
798 | 861 |
799 } // namespace WebCore | 862 } // namespace WebCore |
800 | 863 |
801 #endif // GraphicsContext3D_h | 864 #endif // GraphicsContext3D_h |
OLD | NEW |