OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009, 2010, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2010, 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "GeneratorGeneratedImage.h" | 27 #include "GeneratorGeneratedImage.h" |
28 | 28 |
29 #include "FloatRect.h" | 29 #include "FloatRect.h" |
30 #include "GraphicsContext.h" | 30 #include "GraphicsContext.h" |
31 #include "Length.h" | 31 #include "Length.h" |
32 | 32 |
33 namespace WebCore { | 33 namespace WebCore { |
34 | 34 |
35 void GeneratorGeneratedImage::draw(GraphicsContext* destContext, const FloatRect
& destRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOpera
tor compositeOp) | 35 void GeneratorGeneratedImage::draw(GraphicsContext* destContext, const FloatRect
& destRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp) |
36 { | 36 { |
37 unsigned generatorHash = m_generator->hash(); | 37 GraphicsContextStateSaver stateSaver(*destContext); |
38 if (!m_cachedImageBuffer || m_cachedGeneratorHash != generatorHash || m_cach
edAdjustedSize != m_size || !destContext->isCompatibleWithBuffer(m_cachedImageBu
ffer.get())) { | 38 destContext->setCompositeOperation(compositeOp); |
39 // Create a BitmapImage and call draw on it. | 39 destContext->clip(destRect); |
40 m_cachedImageBuffer = destContext->createCompatibleBuffer(m_size); | 40 destContext->translate(destRect.x(), destRect.y()); |
41 if (!m_cachedImageBuffer) | 41 if (destRect.size() != srcRect.size()) |
42 return; | 42 destContext->scale(FloatSize(destRect.width() / srcRect.width(), destRec
t.height() / srcRect.height())); |
43 | 43 destContext->translate(-srcRect.x(), -srcRect.y()); |
44 // Fill with the generated image. | 44 destContext->fillRect(FloatRect(FloatPoint(), m_size), *m_generator.get()); |
45 m_cachedImageBuffer->context()->fillRect(FloatRect(FloatPoint(), m_size)
, *m_generator); | |
46 | |
47 m_cachedGeneratorHash = generatorHash; | |
48 m_cachedAdjustedSize = m_size; | |
49 } | |
50 | |
51 // Draw the image buffer to the destination | |
52 m_cachedImageBuffer->draw(destContext, styleColorSpace, destRect, srcRect, c
ompositeOp); | |
53 m_cacheTimer.restart(); | |
54 } | 45 } |
55 | 46 |
56 void GeneratorGeneratedImage::drawPattern(GraphicsContext* destContext, const Fl
oatRect& srcRect, const AffineTransform& patternTransform, | 47 void GeneratorGeneratedImage::drawPattern(GraphicsContext* destContext, const Fl
oatRect& srcRect, const AffineTransform& patternTransform, |
57 const FloatPoint& phase, ColorSpace styleColorS
pace, CompositeOperator compositeOp, const FloatRect& destRect) | 48 const FloatPoint& phase, ColorSpace styleColorS
pace, CompositeOperator compositeOp, const FloatRect& destRect) |
58 { | 49 { |
59 // Allow the generator to provide visually-equivalent tiling parameters for
better performance. | 50 // Allow the generator to provide visually-equivalent tiling parameters for
better performance. |
60 IntSize adjustedSize = m_size; | 51 IntSize adjustedSize = m_size; |
61 FloatRect adjustedSrcRect = srcRect; | 52 FloatRect adjustedSrcRect = srcRect; |
62 m_generator->adjustParametersForTiledDrawing(adjustedSize, adjustedSrcRect); | 53 m_generator->adjustParametersForTiledDrawing(adjustedSize, adjustedSrcRect); |
63 | 54 |
(...skipping 30 matching lines...) Expand all Loading... |
94 intrinsicRatio = FloatSize(); | 85 intrinsicRatio = FloatSize(); |
95 } | 86 } |
96 | 87 |
97 void GeneratorGeneratedImage::invalidateCacheTimerFired(DeferrableOneShotTimer<G
eneratorGeneratedImage>*) | 88 void GeneratorGeneratedImage::invalidateCacheTimerFired(DeferrableOneShotTimer<G
eneratorGeneratedImage>*) |
98 { | 89 { |
99 m_cachedImageBuffer.clear(); | 90 m_cachedImageBuffer.clear(); |
100 m_cachedAdjustedSize = IntSize(); | 91 m_cachedAdjustedSize = IntSize(); |
101 } | 92 } |
102 | 93 |
103 } | 94 } |
OLD | NEW |