tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / Image.h
1 /*
2  * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
3  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
25  */
26
27 #ifndef Image_h
28 #define Image_h
29
30 #include "Color.h"
31 #include "ColorSpace.h"
32 #include "GraphicsTypes.h"
33 #include "ImageSource.h"
34 #include "IntRect.h"
35 #include <wtf/PassRefPtr.h>
36 #include <wtf/RefCounted.h>
37 #include <wtf/RefPtr.h>
38 #include <wtf/RetainPtr.h>
39 #include <wtf/text/WTFString.h>
40
41 #if PLATFORM(MAC)
42 OBJC_CLASS NSImage;
43 #endif
44
45 #if USE(CG)
46 struct CGContext;
47 #endif
48
49 #if PLATFORM(WIN)
50 typedef struct tagSIZE SIZE;
51 typedef SIZE* LPSIZE;
52 typedef struct HBITMAP__ *HBITMAP;
53 #endif
54
55 #if PLATFORM(GTK)
56 typedef struct _GdkPixbuf GdkPixbuf;
57 #endif
58
59 namespace WebCore {
60
61 class AffineTransform;
62 class FloatPoint;
63 class FloatRect;
64 class FloatSize;
65 class GraphicsContext;
66 class SharedBuffer;
67 struct Length;
68
69 // This class gets notified when an image creates or destroys decoded frames and when it advances animation frames.
70 class ImageObserver;
71
72 class Image : public RefCounted<Image> {
73     friend class GeneratedImage;
74     friend class CrossfadeGeneratedImage;
75     friend class GeneratorGeneratedImage;
76     friend class GraphicsContext;
77
78 public:
79     virtual ~Image();
80     
81     static PassRefPtr<Image> create(ImageObserver* = 0);
82     static PassRefPtr<Image> loadPlatformResource(const char* name);
83     static bool supportsType(const String&); 
84
85     virtual bool isSVGImage() const { return false; }
86     virtual bool isBitmapImage() const { return false; }
87     virtual bool currentFrameHasAlpha() { return false; }
88
89     // Derived classes should override this if they can assure that 
90     // the image contains only resources from its own security origin.
91     virtual bool hasSingleSecurityOrigin() const { return false; }
92
93     static Image* nullImage();
94     bool isNull() const { return size().isEmpty(); }
95
96     virtual void setContainerSize(const IntSize&) { }
97     virtual bool usesContainerSize() const { return false; }
98     virtual bool hasRelativeWidth() const { return false; }
99     virtual bool hasRelativeHeight() const { return false; }
100     virtual void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
101
102     virtual IntSize size() const = 0;
103     IntRect rect() const { return IntRect(IntPoint(), size()); }
104     int width() const { return size().width(); }
105     int height() const { return size().height(); }
106     virtual bool getHotSpot(IntPoint&) const { return false; }
107
108     bool setData(PassRefPtr<SharedBuffer> data, bool allDataReceived);
109     virtual bool dataChanged(bool /*allDataReceived*/) { return false; }
110     
111     virtual String filenameExtension() const { return String(); } // null string if unknown
112
113     virtual void destroyDecodedData(bool destroyAll = true) = 0;
114     virtual unsigned decodedSize() const = 0;
115
116     SharedBuffer* data() { return m_data.get(); }
117
118     // Animation begins whenever someone draws the image, so startAnimation() is not normally called.
119     // It will automatically pause once all observers no longer want to render the image anywhere.
120     virtual void startAnimation(bool /*catchUpIfNecessary*/ = true) { }
121     virtual void stopAnimation() {}
122     virtual void resetAnimation() {}
123     
124     // Typically the CachedImage that owns us.
125     ImageObserver* imageObserver() const { return m_imageObserver; }
126     void setImageObserver(ImageObserver* observer) { m_imageObserver = observer; }
127
128     enum TileRule { StretchTile, RoundTile, SpaceTile, RepeatTile };
129
130     virtual NativeImagePtr nativeImageForCurrentFrame() { return 0; }
131     
132 #if PLATFORM(MAC)
133     // Accessors for native image formats.
134     virtual NSImage* getNSImage() { return 0; }
135     virtual CFDataRef getTIFFRepresentation() { return 0; }
136 #endif
137
138 #if USE(CG)
139     virtual CGImageRef getCGImageRef() { return 0; }
140     virtual CGImageRef getFirstCGImageRefOfSize(const IntSize&) { return 0; }
141     virtual RetainPtr<CFArrayRef> getCGImageArray() { return 0; }
142     static RetainPtr<CGImageRef> imageWithColorSpace(CGImageRef originalImage, ColorSpace);
143 #endif
144
145 #if PLATFORM(WIN)
146     virtual bool getHBITMAP(HBITMAP) { return false; }
147     virtual bool getHBITMAPOfSize(HBITMAP, LPSIZE) { return false; }
148 #endif
149
150 #if PLATFORM(GTK)
151     virtual GdkPixbuf* getGdkPixbuf() { return 0; }
152     static PassRefPtr<Image> loadPlatformThemeIcon(const char* name, int size);
153 #endif
154
155 #if PLATFORM(QT)
156     static void setPlatformResource(const char* name, const QImage&);
157 #endif
158
159 #if PLATFORM(EFL)
160 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
161     virtual NativeImagePtr getCairoSurface() { return 0; }
162 #endif
163 #endif
164
165     virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
166                              const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
167
168 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
169     FloatRect adjustSourceRectForDownSampling(const FloatRect& srcRect, const IntSize& scaledSize) const;
170 #endif
171
172 #if !ASSERT_DISABLED
173     virtual bool notSolidColor() { return true; }
174 #endif
175
176 #if ENABLE(TIZEN_JPEGIMAGE_DECODING_THREAD)
177     virtual void cacheFrame(size_t index) { }
178     virtual ImageSource* getBitmapimageSource() { return 0; }
179 #endif
180
181 protected:
182     Image(ImageObserver* = 0);
183
184     static void fillWithSolidColor(GraphicsContext*, const FloatRect& dstRect, const Color&, ColorSpace styleColorSpace, CompositeOperator);
185
186     // The ColorSpace parameter will only be used for untagged images.
187 #if PLATFORM(WIN)
188     virtual void drawFrameMatchingSourceSize(GraphicsContext*, const FloatRect& dstRect, const IntSize& srcSize, ColorSpace styleColorSpace, CompositeOperator) { }
189 #endif
190     virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOperator) = 0;
191     virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOperator, RespectImageOrientationEnum);
192     void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize, ColorSpace styleColorSpace, CompositeOperator);
193     void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, const FloatSize& tileScaleFactor, TileRule hRule, TileRule vRule, ColorSpace styleColorSpace, CompositeOperator);
194
195     // Supporting tiled drawing
196     virtual bool mayFillWithSolidColor() { return false; }
197     virtual Color solidColor() const { return Color(); }
198     
199 private:
200     RefPtr<SharedBuffer> m_data; // The encoded raw data for the image. 
201     ImageObserver* m_imageObserver;
202 };
203
204 }
205
206 #endif