blob: 7ed5c0f47a149810180c0a8f6d4be0c3388802a9 [file] [log] [blame]
eric@webkit.orgf0124f62008-08-14 00:29:50 +00001/*
2 * Copyright (C) 2006, 2007, 2008 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
staikos@webkit.org128215972009-07-30 18:08:23 +00004 * Copyright (C) 2007-2008 Torch Mobile, Inc.
eric@webkit.orgf0124f62008-08-14 00:29:50 +00005 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef Pattern_h
29#define Pattern_h
30
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000031#include "AffineTransform.h"
hyatt@apple.comffec3a42010-08-16 20:44:01 +000032#include "Image.h"
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000033
eric@webkit.org22794fd2008-08-28 12:04:40 +000034#include <wtf/PassRefPtr.h>
35#include <wtf/RefCounted.h>
eric@webkit.orgf0124f62008-08-14 00:29:50 +000036#include <wtf/RefPtr.h>
37
paroga@webkit.orgf226d9f2011-04-17 10:04:48 +000038#if USE(CG)
eric@webkit.orgf0124f62008-08-14 00:29:50 +000039typedef struct CGPattern* CGPatternRef;
40typedef CGPatternRef PlatformPatternPtr;
paroga@webkit.org411b4762011-04-16 10:37:01 +000041#elif USE(CAIRO)
eric@webkit.orgf0124f62008-08-14 00:29:50 +000042#include <cairo.h>
43typedef cairo_pattern_t* PlatformPatternPtr;
paroga@webkit.orgcb73e5d2011-02-24 17:33:43 +000044#elif USE(SKIA)
eric@webkit.orgbac93762008-08-19 23:33:07 +000045class SkShader;
46typedef SkShader* PlatformPatternPtr;
eric@webkit.orgf0124f62008-08-14 00:29:50 +000047#elif PLATFORM(QT)
48#include <QBrush>
hausmann@webkit.orgf5864402008-08-29 12:35:59 +000049typedef QBrush PlatformPatternPtr;
kevino@webkit.org141c4602008-08-14 22:52:55 +000050#elif PLATFORM(WX)
51#if USE(WXGC)
52class wxGraphicsBrush;
53typedef wxGraphicsBrush* PlatformPatternPtr;
54#else
55class wxBrush;
56typedef wxBrush* PlatformPatternPtr;
57#endif // USE(WXGC)
mjs@apple.comacbcc282010-01-05 08:58:28 +000058#elif OS(WINCE)
staikos@webkit.org128215972009-07-30 18:08:23 +000059typedef void* PlatformPatternPtr;
eric@webkit.orgf0124f62008-08-14 00:29:50 +000060#endif
61
62namespace WebCore {
eric@webkit.orgf0124f62008-08-14 00:29:50 +000063
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000064class AffineTransform;
eric@webkit.org22794fd2008-08-28 12:04:40 +000065
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000066class Pattern : public RefCounted<Pattern> {
67public:
hyatt@apple.comffec3a42010-08-16 20:44:01 +000068 static PassRefPtr<Pattern> create(PassRefPtr<Image> tileImage, bool repeatX, bool repeatY)
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000069 {
70 return adoptRef(new Pattern(tileImage, repeatX, repeatY));
71 }
72 virtual ~Pattern();
eric@webkit.orgf0124f62008-08-14 00:29:50 +000073
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000074 Image* tileImage() const { return m_tileImage.get(); }
eric@webkit.org1afdbee2010-02-02 05:36:40 +000075
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000076 void platformDestroy();
77
78 // Pattern space is an abstract space that maps to the default user space by the transformation 'userSpaceTransformation'
paroga@webkit.orgcb73e5d2011-02-24 17:33:43 +000079#if USE(SKIA)
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000080 PlatformPatternPtr platformPattern(const AffineTransform& userSpaceTransformation);
eric@webkit.org1afdbee2010-02-02 05:36:40 +000081#else
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000082 PlatformPatternPtr createPlatformPattern(const AffineTransform& userSpaceTransformation) const;
eric@webkit.org1afdbee2010-02-02 05:36:40 +000083#endif
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000084 void setPatternSpaceTransform(const AffineTransform& patternSpaceTransformation);
85 void setPlatformPatternSpaceTransform();
eric@webkit.orgf0124f62008-08-14 00:29:50 +000086
laszlo.1.gombos@nokia.comfe651e32010-03-23 14:37:02 +000087 bool repeatX() const { return m_repeatX; }
88 bool repeatY() const { return m_repeatY; }
89
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000090private:
hyatt@apple.comffec3a42010-08-16 20:44:01 +000091 Pattern(PassRefPtr<Image>, bool repeatX, bool repeatY);
eric@webkit.org22794fd2008-08-28 12:04:40 +000092
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000093 RefPtr<Image> m_tileImage;
94 bool m_repeatX;
95 bool m_repeatY;
96 AffineTransform m_patternSpaceTransformation;
97 PlatformPatternPtr m_pattern;
enne@google.comaf4e7a22012-02-29 01:12:57 +000098#if USE(SKIA)
enne@google.comd89c65e2012-04-11 06:26:39 +000099 int m_externalMemoryAllocated;
enne@google.comaf4e7a22012-02-29 01:12:57 +0000100#endif
krit@webkit.org2b95a9a2010-02-08 20:30:42 +0000101};
eric@webkit.orgf0124f62008-08-14 00:29:50 +0000102
103} //namespace
104
105#endif