1 | /* |
2 | * Copyright (C) 2015 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "NamedImageGeneratedImage.h" |
28 | |
29 | #include "FloatRect.h" |
30 | #include "GraphicsContext.h" |
31 | #include "ImageBuffer.h" |
32 | #include "Theme.h" |
33 | #include <wtf/text/TextStream.h> |
34 | |
35 | namespace WebCore { |
36 | |
37 | NamedImageGeneratedImage::NamedImageGeneratedImage(String name, const FloatSize& size) |
38 | : m_name(name) |
39 | { |
40 | setContainerSize(size); |
41 | } |
42 | |
43 | ImageDrawResult NamedImageGeneratedImage::draw(GraphicsContext& context, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp, BlendMode blendMode, DecodingMode, ImageOrientationDescription) |
44 | { |
45 | #if USE(NEW_THEME) || PLATFORM(IOS_FAMILY) |
46 | GraphicsContextStateSaver stateSaver(context); |
47 | context.setCompositeOperation(compositeOp, blendMode); |
48 | context.clip(dstRect); |
49 | context.translate(dstRect.location()); |
50 | if (dstRect.size() != srcRect.size()) |
51 | context.scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height())); |
52 | context.translate(-srcRect.location()); |
53 | |
54 | Theme::singleton().drawNamedImage(m_name, context, dstRect); |
55 | return ImageDrawResult::DidDraw; |
56 | #else |
57 | UNUSED_PARAM(context); |
58 | UNUSED_PARAM(dstRect); |
59 | UNUSED_PARAM(srcRect); |
60 | UNUSED_PARAM(compositeOp); |
61 | UNUSED_PARAM(blendMode); |
62 | return ImageDrawResult::DidNothing; |
63 | #endif |
64 | } |
65 | |
66 | void NamedImageGeneratedImage::drawPattern(GraphicsContext& context, const FloatRect& dstRect, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator compositeOp, BlendMode blendMode) |
67 | { |
68 | #if USE(NEW_THEME) |
69 | auto imageBuffer = ImageBuffer::createCompatibleBuffer(size(), context); |
70 | if (!imageBuffer) |
71 | return; |
72 | |
73 | GraphicsContext& graphicsContext = imageBuffer->context(); |
74 | Theme::singleton().drawNamedImage(m_name, graphicsContext, FloatRect(0, 0, size().width(), size().height())); |
75 | |
76 | // Tile the image buffer into the context. |
77 | imageBuffer->drawPattern(context, dstRect, srcRect, patternTransform, phase, spacing, compositeOp, blendMode); |
78 | #else |
79 | UNUSED_PARAM(context); |
80 | UNUSED_PARAM(srcRect); |
81 | UNUSED_PARAM(patternTransform); |
82 | UNUSED_PARAM(phase); |
83 | UNUSED_PARAM(spacing); |
84 | UNUSED_PARAM(dstRect); |
85 | UNUSED_PARAM(compositeOp); |
86 | UNUSED_PARAM(blendMode); |
87 | #endif |
88 | } |
89 | |
90 | void NamedImageGeneratedImage::dump(TextStream& ts) const |
91 | { |
92 | GeneratedImage::dump(ts); |
93 | ts.dumpProperty("name" , m_name); |
94 | } |
95 | |
96 | } |
97 | |