Changeset 139701 in webkit
- Timestamp:
- Jan 14, 2013 6:44:55 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r139698 r139701 1 2013-01-14 Dean Jackson <dino@apple.com> 2 3 Blur the label background of a snapshotted plugin 4 https://bugs.webkit.org/show_bug.cgi?id=106630 5 6 Reviewed by Simon Fraser. 7 8 When we are showing a label indicating the plugin has been snapshotted, 9 slightly blur the snapshot behind the label so that it is more clear. I expect 10 that if/when other ports pick up this code, we'll need to separate the 11 UI treatment somewhat, but this is ok for a first step. 12 13 * rendering/RenderSnapshottedPlugIn.cpp: 14 (RenderSnapshottedPlugInBlurFilter): Private class to use FEGaussianBlur to blur an image. 15 (WebCore::RenderSnapshottedPlugInBlurFilter::create): 16 (WebCore::RenderSnapshottedPlugInBlurFilter::setSourceImageRect): 17 (WebCore::RenderSnapshottedPlugInBlurFilter::sourceImageRect): 18 (WebCore::RenderSnapshottedPlugInBlurFilter::filterRegion): 19 (WebCore::RenderSnapshottedPlugInBlurFilter::output): 20 (WebCore::RenderSnapshottedPlugInBlurFilter::RenderSnapshottedPlugInBlurFilter): 21 (WebCore::RenderSnapshottedPlugInBlurFilter::apply): 22 (WebCore::RenderSnapshottedPlugIn::RenderSnapshottedPlugIn): New member variable to hold a cached version of a preblurred snapshot. 23 (WebCore::RenderSnapshottedPlugIn::~RenderSnapshottedPlugIn): Remember to remove the preblurred image from the cache. 24 (WebCore::RenderSnapshottedPlugIn::updateSnapshot): Zero the preblurred version if it exists. 25 (WebCore::RenderSnapshottedPlugIn::paintReplaced): Either paint snapshot or blurred snapshot with label. 26 (WebCore::RenderSnapshottedPlugIn::paintSnapshot): New method to paint a full sized snapshot. 27 (WebCore::RenderSnapshottedPlugIn::paintReplacedSnapshot): 28 (WebCore::snapshottedPluginImageForLabelDisplay): Static function to produce the blurred snapshot. 29 (WebCore::RenderSnapshottedPlugIn::paintReplacedSnapshotWithLabel): Calls paintSnapshot with the blurred snapshot on Mac. 30 * rendering/RenderSnapshottedPlugIn.h: 31 1 32 2013-01-14 Mark Pilgrim <pilgrim@chromium.org> 2 33 -
trunk/Source/WebCore/rendering/RenderSnapshottedPlugIn.cpp
r139392 r139701 30 30 #include "ChromeClient.h" 31 31 #include "Cursor.h" 32 #include "FEGaussianBlur.h" 33 #include "Filter.h" 32 34 #include "FrameLoaderClient.h" 33 35 #include "FrameView.h" 34 36 #include "Gradient.h" 35 37 #include "HTMLPlugInImageElement.h" 38 #include "ImageBuffer.h" 36 39 #include "MouseEvent.h" 37 40 #include "Page.h" 38 41 #include "PaintInfo.h" 39 42 #include "Path.h" 43 #include "SourceGraphic.h" 40 44 41 45 namespace WebCore { … … 47 51 static const double showLabelAfterMouseOverDelay = 1; 48 52 static const double showLabelAutomaticallyDelay = 3; 53 static const int snapshotLabelBlurRadius = 5; 54 55 class RenderSnapshottedPlugInBlurFilter : public Filter { 56 WTF_MAKE_FAST_ALLOCATED; 57 public: 58 static PassRefPtr<RenderSnapshottedPlugInBlurFilter> create(int radius) 59 { 60 return adoptRef(new RenderSnapshottedPlugInBlurFilter(radius)); 61 } 62 63 void setSourceImageRect(const FloatRect& r) 64 { 65 m_sourceImageRect = r; 66 m_filterRegion = r; 67 m_sourceGraphic->setMaxEffectRect(r); 68 m_blur->setMaxEffectRect(r); 69 } 70 virtual FloatRect sourceImageRect() const { return m_sourceImageRect; } 71 virtual FloatRect filterRegion() const { return m_filterRegion; } 72 73 void apply(); 74 ImageBuffer* output() const { return m_blur->asImageBuffer(); } 75 76 private: 77 RenderSnapshottedPlugInBlurFilter(int radius); 78 79 FloatRect m_sourceImageRect; 80 FloatRect m_filterRegion; 81 RefPtr<SourceGraphic> m_sourceGraphic; 82 RefPtr<FEGaussianBlur> m_blur; 83 }; 84 85 RenderSnapshottedPlugInBlurFilter::RenderSnapshottedPlugInBlurFilter(int radius) 86 { 87 setFilterResolution(FloatSize(1, 1)); 88 m_sourceGraphic = SourceGraphic::create(this); 89 m_blur = FEGaussianBlur::create(this, radius, radius); 90 m_blur->inputEffects().append(m_sourceGraphic); 91 } 92 93 void RenderSnapshottedPlugInBlurFilter::apply() 94 { 95 m_sourceGraphic->clearResult(); 96 m_blur->clearResult(); 97 m_blur->apply(); 98 } 49 99 50 100 RenderSnapshottedPlugIn::RenderSnapshottedPlugIn(HTMLPlugInImageElement* element) … … 56 106 , m_showReason(UserMousedOver) 57 107 , m_showLabelDelayTimer(this, &RenderSnapshottedPlugIn::showLabelDelayTimerFired) 108 , m_snapshotResourceForLabel(RenderImageResource::create()) 58 109 { 59 110 m_snapshotResource->initialize(this); 111 m_snapshotResourceForLabel->initialize(this); 60 112 } 61 113 … … 64 116 ASSERT(m_snapshotResource); 65 117 m_snapshotResource->shutdown(); 118 ASSERT(m_snapshotResourceForLabel); 119 m_snapshotResourceForLabel->shutdown(); 66 120 } 67 121 … … 76 130 if (!image) 77 131 return; 132 133 // We may have stored a version of this snapshot to use when showing the 134 // label. Invalidate it now and it will be regenerated later. 135 if (m_snapshotResourceForLabel->hasImage()) 136 m_snapshotResourceForLabel->setCachedImage(0); 78 137 79 138 m_snapshotResource->setCachedImage(new CachedImage(image.get())); … … 96 155 { 97 156 if (plugInImageElement()->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) { 98 paintReplacedSnapshot(paintInfo, paintOffset);99 157 if (m_shouldShowLabel) 100 paintLabel(paintInfo, paintOffset); 158 paintReplacedSnapshotWithLabel(paintInfo, paintOffset); 159 else 160 paintReplacedSnapshot(paintInfo, paintOffset); 101 161 return; 102 162 } … … 105 165 } 106 166 107 void RenderSnapshottedPlugIn::paintReplacedSnapshot(PaintInfo& paintInfo, const LayoutPoint& paintOffset) 108 { 109 // This code should be similar to RenderImage::paintReplaced() and RenderImage::paintIntoRect(). 167 void RenderSnapshottedPlugIn::paintSnapshot(Image* image, PaintInfo& paintInfo, const LayoutPoint& paintOffset) 168 { 110 169 LayoutUnit cWidth = contentWidth(); 111 170 LayoutUnit cHeight = contentHeight(); 112 171 if (!cWidth || !cHeight) 113 return;114 115 RefPtr<Image> image = m_snapshotResource->image();116 if (!image || image->isNull())117 172 return; 118 173 … … 132 187 return; 133 188 134 bool useLowQualityScaling = shouldPaintAtLowQuality(context, image.get(), image.get(), alignedRect.size()); 135 context->drawImage(image.get(), style()->colorSpace(), alignedRect, CompositeSourceOver, shouldRespectImageOrientation(), useLowQualityScaling); 189 bool useLowQualityScaling = shouldPaintAtLowQuality(context, image, image, alignedRect.size()); 190 context->drawImage(image, style()->colorSpace(), alignedRect, CompositeSourceOver, shouldRespectImageOrientation(), useLowQualityScaling); 191 } 192 193 void RenderSnapshottedPlugIn::paintReplacedSnapshot(PaintInfo& paintInfo, const LayoutPoint& paintOffset) 194 { 195 RefPtr<Image> image = m_snapshotResource->image(); 196 if (!image || image->isNull()) 197 return; 198 199 paintSnapshot(image.get(), paintInfo, paintOffset); 136 200 } 137 201 … … 154 218 } 155 219 156 void RenderSnapshottedPlugIn::paintLabel(PaintInfo& paintInfo, const LayoutPoint& paintOffset) 220 static PassRefPtr<Image> snapshottedPluginImageForLabelDisplay(PassRefPtr<Image> snapshot, const LayoutRect& blurRegion) 221 { 222 OwnPtr<ImageBuffer> snapshotBuffer = ImageBuffer::create(snapshot->size()); 223 snapshotBuffer->context()->drawImage(snapshot.get(), ColorSpaceDeviceRGB, IntPoint(0, 0)); 224 225 OwnPtr<ImageBuffer> blurBuffer = ImageBuffer::create(roundedIntSize(blurRegion.size())); 226 blurBuffer->context()->drawImage(snapshot.get(), ColorSpaceDeviceRGB, IntPoint(-blurRegion.x(), -blurRegion.y())); 227 228 RefPtr<RenderSnapshottedPlugInBlurFilter> blurFilter = RenderSnapshottedPlugInBlurFilter::create(snapshotLabelBlurRadius); 229 blurFilter->setSourceImage(blurBuffer.release()); 230 blurFilter->setSourceImageRect(FloatRect(FloatPoint(), blurRegion.size())); 231 blurFilter->apply(); 232 233 snapshotBuffer->context()->drawImageBuffer(blurFilter->output(), ColorSpaceDeviceRGB, roundedIntPoint(blurRegion.location())); 234 return snapshotBuffer->copyImage(); 235 } 236 237 void RenderSnapshottedPlugIn::paintReplacedSnapshotWithLabel(PaintInfo& paintInfo, const LayoutPoint& paintOffset) 157 238 { 158 239 if (contentBoxRect().isEmpty()) … … 179 260 if (!labelImage) 180 261 return; 262 263 RefPtr<Image> snapshotImage = m_snapshotResource->image(); 264 if (!snapshotImage || snapshotImage->isNull()) 265 return; 266 267 RefPtr<Image> blurredSnapshotImage = m_snapshotResourceForLabel->image(); 268 if (!blurredSnapshotImage || blurredSnapshotImage->isNull()) { 269 blurredSnapshotImage = snapshottedPluginImageForLabelDisplay(snapshotImage, labelRect); 270 m_snapshotResourceForLabel->setCachedImage(new CachedImage(blurredSnapshotImage.get())); 271 } 272 snapshotImage = blurredSnapshotImage; 273 274 paintSnapshot(snapshotImage.get(), paintInfo, paintOffset); 181 275 182 276 // Remember that the labelRect includes the label inset, so we need to adjust for it. -
trunk/Source/WebCore/rendering/RenderSnapshottedPlugIn.h
r138928 r139701 64 64 65 65 void paintReplacedSnapshot(PaintInfo&, const LayoutPoint&); 66 void paintLabel(PaintInfo&, const LayoutPoint&); 66 void paintReplacedSnapshotWithLabel(PaintInfo&, const LayoutPoint&); 67 void paintSnapshot(Image*, PaintInfo&, const LayoutPoint&); 67 68 void repaintLabel(); 68 69 … … 83 84 ShowReason m_showReason; 84 85 Timer<RenderSnapshottedPlugIn> m_showLabelDelayTimer; 86 OwnPtr<RenderImageResource> m_snapshotResourceForLabel; 85 87 }; 86 88
Note: See TracChangeset
for help on using the changeset viewer.