]>
git.saurik.com Git - iphone-api.git/blob - WebCore/Image.h
2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
31 #include "GraphicsTypes.h"
32 #include "ImageSource.h"
34 #include <wtf/RefPtr.h>
35 #include <wtf/PassRefPtr.h>
36 #include "SharedBuffer.h"
51 typedef struct tagSIZE SIZE
;
53 typedef struct HBITMAP__
*HBITMAP
;
57 class NativeImageSkia
;
66 class TransformationMatrix
;
70 class GraphicsContext
;
74 // This class gets notified when an image creates or destroys decoded frames and when it advances animation frames.
77 class Image
: public RefCounted
<Image
> {
78 friend class GeneratedImage
;
79 friend class GraphicsContext
;
83 static PassRefPtr
<Image
> create(ImageObserver
* = 0);
84 static PassRefPtr
<Image
> loadPlatformResource(const char* name
);
85 static bool supportsType(const String
&);
87 virtual bool isBitmapImage() const { return false; }
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; }
93 static Image
* nullImage();
94 bool isNull() const { return size().isEmpty(); }
96 // These are only used for SVGImage right now
97 virtual void setContainerSize(const IntSize
&) { }
98 virtual bool usesContainerSize() const { return false; }
99 virtual bool hasRelativeWidth() const { return false; }
100 virtual bool hasRelativeHeight() const { return false; }
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(); }
107 bool setData(PassRefPtr
<SharedBuffer
> data
, bool allDataReceived
);
108 virtual bool dataChanged(bool /*allDataReceived*/) { return false; }
110 virtual String
filenameExtension() const { return String(); } // null string if unknown
112 virtual void destroyDecodedData(bool destroyAll
= true) = 0;
113 virtual unsigned decodedSize() const = 0;
115 SharedBuffer
* data() { return m_data
.get(); }
117 // Animation begins whenever someone draws the image, so startAnimation() is not normally called.
118 // It will automatically pause once all observers no longer want to render the image anywhere.
119 virtual void startAnimation(bool /*catchUpIfNecessary*/ = true) { }
120 virtual void stopAnimation() {}
121 virtual void resetAnimation() {}
123 // Typically the CachedImage that owns us.
124 ImageObserver
* imageObserver() const { return m_imageObserver
; }
126 enum TileRule
{ StretchTile
, RoundTile
, RepeatTile
};
128 virtual NativeImagePtr
nativeImageForCurrentFrame() { return 0; }
131 // Accessors for native image formats.
132 virtual NSImage
* getNSImage() { return 0; }
133 virtual CFDataRef
getTIFFRepresentation() { return 0; }
137 virtual CGImageRef
getCGImageRef() { return 0; }
141 virtual bool getHBITMAP(HBITMAP
) { return false; }
142 virtual bool getHBITMAPOfSize(HBITMAP
, LPSIZE
) { return false; }
145 virtual unsigned animatedImageSize() { return 0; }
146 virtual void disableImageAnimation() { }
149 Image(ImageObserver
* = 0);
151 static void fillWithSolidColor(GraphicsContext
* ctxt
, const FloatRect
& dstRect
, const Color
& color
, CompositeOperator op
);
154 virtual void drawFrameMatchingSourceSize(GraphicsContext
*, const FloatRect
& dstRect
, const IntSize
& srcSize
, CompositeOperator
) { }
156 virtual void draw(GraphicsContext
*, const FloatRect
& dstRect
, const FloatRect
& srcRect
, CompositeOperator
) = 0;
157 void drawTiled(GraphicsContext
*, const FloatRect
& dstRect
, const FloatPoint
& srcPoint
, const FloatSize
& tileSize
, CompositeOperator
);
158 void drawTiled(GraphicsContext
*, const FloatRect
& dstRect
, const FloatRect
& srcRect
, TileRule hRule
, TileRule vRule
, CompositeOperator
);
160 // Supporting tiled drawing
161 virtual bool mayFillWithSolidColor() const { return false; }
162 virtual Color
solidColor() const { return Color(); }
164 virtual void drawPattern(GraphicsContext
*, const FloatRect
& srcRect
, const TransformationMatrix
& patternTransform
,
165 const FloatPoint
& phase
, CompositeOperator
, const FloatRect
& destRect
);
167 // These are private to CG. Ideally they would be only in the .cpp file, but the callback requires access
168 // to the private function nativeImageForCurrentFrame()
169 static void drawPatternCallback(void* info
, CGContext
*);
173 RefPtr
<SharedBuffer
> m_data
; // The encoded raw data for the image.
174 ImageObserver
* m_imageObserver
;