Changeset 139701 in webkit


Ignore:
Timestamp:
Jan 14, 2013 6:44:55 PM (11 years ago)
Author:
dino@apple.com
Message:

Blur the label background of a snapshotted plugin
https://bugs.webkit.org/show_bug.cgi?id=106630

Reviewed by Simon Fraser.

When we are showing a label indicating the plugin has been snapshotted,
slightly blur the snapshot behind the label so that it is more clear. I expect
that if/when other ports pick up this code, we'll need to separate the
UI treatment somewhat, but this is ok for a first step.

  • rendering/RenderSnapshottedPlugIn.cpp:

(RenderSnapshottedPlugInBlurFilter): Private class to use FEGaussianBlur to blur an image.
(WebCore::RenderSnapshottedPlugInBlurFilter::create):
(WebCore::RenderSnapshottedPlugInBlurFilter::setSourceImageRect):
(WebCore::RenderSnapshottedPlugInBlurFilter::sourceImageRect):
(WebCore::RenderSnapshottedPlugInBlurFilter::filterRegion):
(WebCore::RenderSnapshottedPlugInBlurFilter::output):
(WebCore::RenderSnapshottedPlugInBlurFilter::RenderSnapshottedPlugInBlurFilter):
(WebCore::RenderSnapshottedPlugInBlurFilter::apply):
(WebCore::RenderSnapshottedPlugIn::RenderSnapshottedPlugIn): New member variable to hold a cached version of a preblurred snapshot.
(WebCore::RenderSnapshottedPlugIn::~RenderSnapshottedPlugIn): Remember to remove the preblurred image from the cache.
(WebCore::RenderSnapshottedPlugIn::updateSnapshot): Zero the preblurred version if it exists.
(WebCore::RenderSnapshottedPlugIn::paintReplaced): Either paint snapshot or blurred snapshot with label.
(WebCore::RenderSnapshottedPlugIn::paintSnapshot): New method to paint a full sized snapshot.
(WebCore::RenderSnapshottedPlugIn::paintReplacedSnapshot):
(WebCore::snapshottedPluginImageForLabelDisplay): Static function to produce the blurred snapshot.
(WebCore::RenderSnapshottedPlugIn::paintReplacedSnapshotWithLabel): Calls paintSnapshot with the blurred snapshot on Mac.

  • rendering/RenderSnapshottedPlugIn.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r139698 r139701  
     12013-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
    1322013-01-14  Mark Pilgrim  <pilgrim@chromium.org>
    233
  • trunk/Source/WebCore/rendering/RenderSnapshottedPlugIn.cpp

    r139392 r139701  
    3030#include "ChromeClient.h"
    3131#include "Cursor.h"
     32#include "FEGaussianBlur.h"
     33#include "Filter.h"
    3234#include "FrameLoaderClient.h"
    3335#include "FrameView.h"
    3436#include "Gradient.h"
    3537#include "HTMLPlugInImageElement.h"
     38#include "ImageBuffer.h"
    3639#include "MouseEvent.h"
    3740#include "Page.h"
    3841#include "PaintInfo.h"
    3942#include "Path.h"
     43#include "SourceGraphic.h"
    4044
    4145namespace WebCore {
     
    4751static const double showLabelAfterMouseOverDelay = 1;
    4852static const double showLabelAutomaticallyDelay = 3;
     53static const int snapshotLabelBlurRadius = 5;
     54
     55class RenderSnapshottedPlugInBlurFilter : public Filter {
     56    WTF_MAKE_FAST_ALLOCATED;
     57public:
     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
     76private:
     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
     85RenderSnapshottedPlugInBlurFilter::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
     93void RenderSnapshottedPlugInBlurFilter::apply()
     94{
     95    m_sourceGraphic->clearResult();
     96    m_blur->clearResult();
     97    m_blur->apply();
     98}
    4999
    50100RenderSnapshottedPlugIn::RenderSnapshottedPlugIn(HTMLPlugInImageElement* element)
     
    56106    , m_showReason(UserMousedOver)
    57107    , m_showLabelDelayTimer(this, &RenderSnapshottedPlugIn::showLabelDelayTimerFired)
     108    , m_snapshotResourceForLabel(RenderImageResource::create())
    58109{
    59110    m_snapshotResource->initialize(this);
     111    m_snapshotResourceForLabel->initialize(this);
    60112}
    61113
     
    64116    ASSERT(m_snapshotResource);
    65117    m_snapshotResource->shutdown();
     118    ASSERT(m_snapshotResourceForLabel);
     119    m_snapshotResourceForLabel->shutdown();
    66120}
    67121
     
    76130    if (!image)
    77131        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);
    78137
    79138    m_snapshotResource->setCachedImage(new CachedImage(image.get()));
     
    96155{
    97156    if (plugInImageElement()->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) {
    98         paintReplacedSnapshot(paintInfo, paintOffset);
    99157        if (m_shouldShowLabel)
    100             paintLabel(paintInfo, paintOffset);
     158            paintReplacedSnapshotWithLabel(paintInfo, paintOffset);
     159        else
     160            paintReplacedSnapshot(paintInfo, paintOffset);
    101161        return;
    102162    }
     
    105165}
    106166
    107 void RenderSnapshottedPlugIn::paintReplacedSnapshot(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
    108 {
    109     // This code should be similar to RenderImage::paintReplaced() and RenderImage::paintIntoRect().
     167void RenderSnapshottedPlugIn::paintSnapshot(Image* image, PaintInfo& paintInfo, const LayoutPoint& paintOffset)
     168{
    110169    LayoutUnit cWidth = contentWidth();
    111170    LayoutUnit cHeight = contentHeight();
    112171    if (!cWidth || !cHeight)
    113         return;
    114 
    115     RefPtr<Image> image = m_snapshotResource->image();
    116     if (!image || image->isNull())
    117172        return;
    118173
     
    132187        return;
    133188
    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
     193void 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);
    136200}
    137201
     
    154218}
    155219
    156 void RenderSnapshottedPlugIn::paintLabel(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
     220static 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
     237void RenderSnapshottedPlugIn::paintReplacedSnapshotWithLabel(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
    157238{
    158239    if (contentBoxRect().isEmpty())
     
    179260    if (!labelImage)
    180261        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);
    181275
    182276    // Remember that the labelRect includes the label inset, so we need to adjust for it.
  • trunk/Source/WebCore/rendering/RenderSnapshottedPlugIn.h

    r138928 r139701  
    6464
    6565    void paintReplacedSnapshot(PaintInfo&, const LayoutPoint&);
    66     void paintLabel(PaintInfo&, const LayoutPoint&);
     66    void paintReplacedSnapshotWithLabel(PaintInfo&, const LayoutPoint&);
     67    void paintSnapshot(Image*, PaintInfo&, const LayoutPoint&);
    6768    void repaintLabel();
    6869
     
    8384    ShowReason m_showReason;
    8485    Timer<RenderSnapshottedPlugIn> m_showLabelDelayTimer;
     86    OwnPtr<RenderImageResource> m_snapshotResourceForLabel;
    8587};
    8688
Note: See TracChangeset for help on using the changeset viewer.