pleyo.com

/src/trunk2/BAL/Interfaces/graphics/Image.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
00003  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.  All rights reserved.
00004  * Copyright (C) 2007 Pleyo.  All rights reserved.
00005  * 
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
00016  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00018  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
00019  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00021  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00022  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00023  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00026  */
00027 
00028 #ifndef Image_h
00029 #define Image_h
00030 
00031 #include "Color.h"
00032 #ifdef __OWB__
00033 #include "AffineTransform.h"
00034 namespace BAL { class BIGraphicsContext; }
00035 #define GraphicsContext BIGraphicsContext
00036 namespace WebCore { using ::BAL::BIGraphicsContext; }
00037 #endif
00038 #include "GraphicsTypes.h"
00039 #include "ImageSource.h"
00040 #include <wtf/RefPtr.h>
00041 #include <wtf/PassRefPtr.h>
00042 #include "SharedBuffer.h"
00043 
00044 #if PLATFORM(MAC)
00045 #ifdef __OBJC__
00046 @class NSImage;
00047 #else
00048 class NSImage;
00049 #endif
00050 #endif
00051 
00052 #if PLATFORM(CG)
00053 struct CGContext;
00054 #endif
00055 
00056 #if PLATFORM(WIN)
00057 typedef struct HBITMAP__ *HBITMAP;
00058 #endif
00059 
00060 #if PLATFORM(QT)
00061 #include <QPixmap>
00062 #endif
00063 
00064 namespace WebCore {
00065 
00066 class AffineTransform;
00067 class FloatPoint;
00068 class FloatRect;
00069 class FloatSize;
00070 class GraphicsContext;
00071 class IntRect;
00072 class IntSize;
00073 class SharedBuffer;
00074 class String;
00075 
00076 // This class gets notified when an image creates or destroys decoded frames and when it advances animation frames.
00077 class ImageObserver;
00078 
00079 class Image : Noncopyable {
00080     friend class GraphicsContext;
00081 public:
00082     Image(ImageObserver* = 0);
00083     virtual ~Image();
00084     
00085     static Image* loadPlatformResource(const char* name);
00086     static bool supportsType(const String&); 
00087 
00088     bool isNull() const;
00089 
00090     virtual IntSize size() const = 0;
00091     IntRect rect() const;
00092     int width() const;
00093     int height() const;
00094 
00095     bool setData(PassRefPtr<SharedBuffer> data, bool allDataReceived);
00096     virtual bool dataChanged(bool allDataReceived) { return false; }
00097     
00098     // FIXME: PDF/SVG will be underreporting decoded sizes and will be unable to prune because these functions are not
00099     // implemented yet for those image types.
00100     virtual void destroyDecodedData(bool incremental = false) {};
00101     virtual unsigned decodedSize() const { return 0; }
00102 
00103     SharedBuffer* data() { return m_data.get(); }
00104 
00105     // It may look unusual that there is no start animation call as public API.  This is because
00106     // we start and stop animating lazily.  Animation begins whenever someone draws the image.  It will
00107     // automatically pause once all observers no longer want to render the image anywhere.
00108     virtual void stopAnimation() {}
00109     virtual void resetAnimation() {}
00110     
00111     // Typically the CachedImage that owns us.
00112     ImageObserver* imageObserver() const { return m_imageObserver; }
00113 
00114     enum TileRule { StretchTile, RoundTile, RepeatTile };
00115     
00116 #if PLATFORM(MAC)
00117     // Accessors for native image formats.
00118     virtual NSImage* getNSImage() { return 0; }
00119     virtual CFDataRef getTIFFRepresentation() { return 0; }
00120 #endif
00121 
00122 #if PLATFORM(CG)
00123     virtual CGImageRef getCGImageRef() { return 0; }
00124 #endif
00125 
00126 #if PLATFORM(QT)
00127     virtual QPixmap* getPixmap() const { return 0; }
00128 #endif
00129 
00130 #if PLATFORM(WIN)
00131     virtual bool getHBITMAP(HBITMAP) { return false; }
00132     virtual bool getHBITMAPOfSize(HBITMAP, LPSIZE) { return false; }
00133 #endif
00134 
00135 #ifdef __OWB__
00136     virtual NativeImagePtr nativeImageForCurrentFrame() { return 0; }
00137     virtual void startAnimation() { }
00138 #endif
00139 
00140 protected:
00141     static void fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect, const Color& color, CompositeOperator op);
00142 
00143 private:
00144 #if PLATFORM(WIN)
00145     virtual void drawFrameMatchingSourceSize(GraphicsContext*, const FloatRect& dstRect, const IntSize& srcSize, CompositeOperator) { }
00146 #endif
00147 
00148 #ifndef __OWB__
00149     virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator) = 0;
00150     void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize, CompositeOperator);
00151     void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule, CompositeOperator);
00152 #endif //__OWB__
00153 
00154     // Supporting tiled drawing
00155     virtual bool mayFillWithSolidColor() const { return false; }
00156     virtual Color solidColor() const { return Color(); }
00157 
00158 #ifndef __OWB__
00159     virtual NativeImagePtr nativeImageForCurrentFrame() { return 0; }
00160     
00161     virtual void startAnimation() { }
00162 
00163     
00164     virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
00165                              const FloatPoint& phase, CompositeOperator, const FloatRect& destRect);
00166 #endif //__OWB__
00167 #if PLATFORM(CG)
00168     // These are private to CG.  Ideally they would be only in the .cpp file, but the callback requires access
00169     // to the private function nativeImageForCurrentFrame()
00170     static void drawPatternCallback(void* info, CGContext*);
00171 #endif
00172     
00173 protected:
00174     RefPtr<SharedBuffer> m_data; // The encoded raw data for the image. 
00175     ImageObserver* m_imageObserver;
00176 };
00177 
00178 }
00179 
00180 #endif

Generated on Wed Nov 21 20:04:17 2007 for Origyn Web Browser by Doxygen 1.5.3

pleyo.com
pleyo.com