1 /* 2 * Copyright (C) 2006 Dirk Mueller <mueller (at) kde.org> 3 * Copyright (C) 2006 Zack Rusin <zack (at) kde.org> 4 * Copyright (C) 2006 George Staikos <staikos (at) kde.org> 5 * Copyright (C) 2006 Simon Hausmann <hausmann (at) kde.org> 6 * Copyright (C) 2006 Allan Sandfeld Jensen <sandfeld (at) kde.org> 7 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann (at) kde.org> 8 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 9 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). 10 * Copyright (C) 2008 Dirk Schulze <vbs85 (at) gmx.de> 11 * 12 * All rights reserved. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 23 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 31 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #ifndef TransparencyLayer_h 37 #define TransparencyLayer_h 38 39 #include <QPaintEngine> 40 #include <QPainter> 41 #include <QPixmap> 42 43 namespace WebCore { 44 45 struct TransparencyLayer { 46 WTF_MAKE_FAST_ALLOCATED; 47 public: 48 TransparencyLayer(const QPainter* p, const QRect &rect, qreal opacity, QPixmap& alphaMask) 49 : pixmap(rect.width(), rect.height()) 50 , opacity(opacity) 51 , alphaMask(alphaMask) 52 , saveCounter(1) // see the comment for saveCounter 53 { 54 offset = rect.topLeft(); 55 pixmap.fill(Qt::transparent); 56 painter.begin(&pixmap); 57 painter.setRenderHints(p->renderHints()); 58 painter.translate(-offset); 59 painter.setPen(p->pen()); 60 painter.setBrush(p->brush()); 61 painter.setTransform(p->transform(), true); 62 painter.setFont(p->font()); 63 painter.setOpacity(1); 64 } 65 66 TransparencyLayer() 67 { 68 } 69 70 QPixmap pixmap; 71 QPoint offset; 72 QPainter painter; 73 qreal opacity; 74 // for clipToImageBuffer 75 QPixmap alphaMask; 76 // saveCounter is only used in combination with alphaMask 77 // otherwise, its value is unspecified 78 int saveCounter; 79 private: 80 TransparencyLayer(const TransparencyLayer &) {} 81 TransparencyLayer & operator=(const TransparencyLayer &) { return *this; } 82 }; 83 84 } // namespace WebCore 85 86 #endif // TransparencyLayer_h 87