Changeset 79877 in webkit


Ignore:
Timestamp:
Feb 28, 2011 10:03:29 AM (13 years ago)
Author:
enne@google.com
Message:

2011-02-25 Adrienne Walker <enne@google.com>

Reviewed by James Robinson.

[chromium] Abstract "pixels with a graphics context" into its own class
https://bugs.webkit.org/show_bug.cgi?id=55259

This creates new PlatformCanvas/PlatformImage classes which wrap
all of the #ifdef Skia/Cg warts from the compositor. All classes
(LayerTilerChromium, ContentLayerChromium, and ImageLayerChromium) are
modified to use these abstractions.

Tests: LayoutTests/compositing

  • WebCore.gypi:
  • platform/graphics/chromium/ContentLayerChromium.cpp: (WebCore::ContentLayerChromium::updateContentsIfDirty): (WebCore::ContentLayerChromium::resizeUploadBuffer): (WebCore::ContentLayerChromium::updateTextureIfNeeded): (WebCore::ContentLayerChromium::updateTexture): (WebCore::ContentLayerChromium::draw):
  • platform/graphics/chromium/ContentLayerChromium.h:
  • platform/graphics/chromium/ImageLayerChromium.cpp: (WebCore::ImageLayerChromium::updateContentsIfDirty): (WebCore::ImageLayerChromium::updateTextureIfNeeded):
  • platform/graphics/chromium/ImageLayerChromium.h:
  • platform/graphics/chromium/LayerTilerChromium.cpp: (WebCore::LayerTilerChromium::contentRectToTileIndices): (WebCore::LayerTilerChromium::update): (WebCore::LayerTilerChromium::updateFromPixels):
  • platform/graphics/chromium/LayerTilerChromium.h:
  • platform/graphics/chromium/PlatformCanvas.cpp: Added. (WebCore::PlatformCanvas::PlatformCanvas): (WebCore::PlatformCanvas::~PlatformCanvas): (WebCore::PlatformCanvas::resize): (WebCore::PlatformCanvas::AutoLocker::AutoLocker): (WebCore::PlatformCanvas::AutoLocker::~AutoLocker): (WebCore::PlatformCanvas::Painter::Painter): (WebCore::PlatformCanvas::Painter::~Painter):
  • platform/graphics/chromium/PlatformCanvas.h: Added. (WebCore::PlatformCanvas::AutoLocker::pixels): (WebCore::PlatformCanvas::Painter::context): (WebCore::PlatformCanvas::size):
  • platform/graphics/chromium/PlatformImage.cpp: Copied from Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp. (WebCore::PlatformImage::PlatformImage): (WebCore::PlatformImage::updateFromImage):
  • platform/graphics/chromium/PlatformImage.h: Added. (WebCore::PlatformImage::pixels): (WebCore::PlatformImage::size):
Location:
trunk/Source/WebCore
Files:
3 added
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r79876 r79877  
     12011-02-25  Adrienne Walker  <enne@google.com>
     2
     3        Reviewed by James Robinson.
     4
     5        [chromium] Abstract "pixels with a graphics context" into its own class
     6        https://bugs.webkit.org/show_bug.cgi?id=55259
     7
     8        This creates new PlatformCanvas/PlatformImage classes which wrap
     9        all of the #ifdef Skia/Cg warts from the compositor.  All classes
     10        (LayerTilerChromium, ContentLayerChromium, and ImageLayerChromium) are
     11        modified to use these abstractions.
     12
     13        Tests: LayoutTests/compositing
     14
     15        * WebCore.gypi:
     16        * platform/graphics/chromium/ContentLayerChromium.cpp:
     17        (WebCore::ContentLayerChromium::updateContentsIfDirty):
     18        (WebCore::ContentLayerChromium::resizeUploadBuffer):
     19        (WebCore::ContentLayerChromium::updateTextureIfNeeded):
     20        (WebCore::ContentLayerChromium::updateTexture):
     21        (WebCore::ContentLayerChromium::draw):
     22        * platform/graphics/chromium/ContentLayerChromium.h:
     23        * platform/graphics/chromium/ImageLayerChromium.cpp:
     24        (WebCore::ImageLayerChromium::updateContentsIfDirty):
     25        (WebCore::ImageLayerChromium::updateTextureIfNeeded):
     26        * platform/graphics/chromium/ImageLayerChromium.h:
     27        * platform/graphics/chromium/LayerTilerChromium.cpp:
     28        (WebCore::LayerTilerChromium::contentRectToTileIndices):
     29        (WebCore::LayerTilerChromium::update):
     30        (WebCore::LayerTilerChromium::updateFromPixels):
     31        * platform/graphics/chromium/LayerTilerChromium.h:
     32        * platform/graphics/chromium/PlatformCanvas.cpp: Added.
     33        (WebCore::PlatformCanvas::PlatformCanvas):
     34        (WebCore::PlatformCanvas::~PlatformCanvas):
     35        (WebCore::PlatformCanvas::resize):
     36        (WebCore::PlatformCanvas::AutoLocker::AutoLocker):
     37        (WebCore::PlatformCanvas::AutoLocker::~AutoLocker):
     38        (WebCore::PlatformCanvas::Painter::Painter):
     39        (WebCore::PlatformCanvas::Painter::~Painter):
     40        * platform/graphics/chromium/PlatformCanvas.h: Added.
     41        (WebCore::PlatformCanvas::AutoLocker::pixels):
     42        (WebCore::PlatformCanvas::Painter::context):
     43        (WebCore::PlatformCanvas::size):
     44        * platform/graphics/chromium/PlatformImage.cpp: Copied from Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp.
     45        (WebCore::PlatformImage::PlatformImage):
     46        (WebCore::PlatformImage::updateFromImage):
     47        * platform/graphics/chromium/PlatformImage.h: Added.
     48        (WebCore::PlatformImage::pixels):
     49        (WebCore::PlatformImage::size):
     50
    1512011-02-28  Sheriff Bot  <webkit.review.bot@gmail.com>
    252
  • trunk/Source/WebCore/WebCore.gypi

    r79861 r79877  
    26232623            'platform/graphics/chromium/MediaPlayerPrivateChromium.h',
    26242624            'platform/graphics/chromium/PlatformIcon.h',
     2625            'platform/graphics/chromium/PlatformCanvas.cpp',
     2626            'platform/graphics/chromium/PlatformCanvas.h',
     2627            'platform/graphics/chromium/PlatformImage.cpp',
     2628            'platform/graphics/chromium/PlatformImage.h',
    26252629            'platform/graphics/chromium/PluginLayerChromium.cpp',
    26262630            'platform/graphics/chromium/PluginLayerChromium.h',
  • trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp

    r79659 r79877  
    4141#include "RenderLayerBacking.h"
    4242
    43 #if USE(SKIA)
    44 #include "NativeImageSkia.h"
    45 #include "PlatformContextSkia.h"
    46 #include "SkColorPriv.h"
    47 #include "skia/ext/platform_canvas.h"
    48 #elif PLATFORM(CG)
    49 #include <CoreGraphics/CGBitmapContext.h>
    50 #endif
    51 
    5243namespace WebCore {
    5344
     
    137128
    138129        // If we need to resize the upload buffer we have to repaint everything.
    139         if (m_uploadBufferSize != visibleRectInLayerCoords.size()) {
     130        if (m_canvas.size() != visibleRectInLayerCoords.size()) {
    140131            resizeUploadBuffer(visibleRectInLayerCoords.size());
    141132            m_dirtyRect = boundsRect;
     
    162153        // If the texture needs to be reallocated then we must redraw the entire
    163154        // contents of the layer.
    164         if (m_uploadBufferSize != bounds()) {
     155        if (m_canvas.size() != bounds()) {
    165156            resizeUploadBuffer(bounds());
    166157            dirtyRect = boundsRect;
     
    176167        return;
    177168
    178 #if USE(SKIA)
    179     OwnPtr<PlatformContextSkia> skiaContext;
    180 
    181     skiaContext.set(new PlatformContextSkia(m_uploadPixelCanvas.get()));
    182 
    183     // This is needed to get text to show up correctly.
    184     skiaContext->setDrawingToImageBuffer(true);
    185 
    186     GraphicsContext graphicsContext(reinterpret_cast<PlatformGraphicsContext*>(skiaContext.get()));
    187 
    188 #elif PLATFORM(CG)
    189     // FIXME: Do we need to clear the dirty rectangle in the upload buffer?
    190     RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
    191     size_t rowBytes = m_uploadBufferSize.width() * 4;
    192     RetainPtr<CGContextRef> contextCG(AdoptCF, CGBitmapContextCreate(m_uploadPixelData->data(),
    193                                                                      m_uploadBufferSize.width(), m_uploadBufferSize.height(), 8, rowBytes,
    194                                                                      colorSpace.get(),
    195                                                                      kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
    196     CGContextTranslateCTM(contextCG.get(), 0, m_uploadBufferSize.height());
    197     CGContextScaleCTM(contextCG.get(), 1, -1);
    198 
    199     GraphicsContext graphicsContext(contextCG.get());
    200 #else
    201 #error "Need to implement for your platform."
    202 #endif
    203 
    204     graphicsContext.save();
    205     graphicsContext.translate(-paintingOffset.x(), -paintingOffset.y());
    206     graphicsContext.clearRect(dirtyRect);
    207     graphicsContext.clip(dirtyRect);
    208 
    209     m_owner->paintGraphicsLayerContents(graphicsContext, dirtyRect);
    210     graphicsContext.restore();
    211 }
    212 
    213 void ContentLayerChromium::resizeUploadBufferForImage(const IntSize& size)
    214 {
    215     size_t bufferSize = size.width() * size.height() * 4;
    216     m_uploadPixelData = new Vector<uint8_t>(bufferSize);
    217 #if PLATFORM(CG)
    218     memset(m_uploadPixelData->data(), 0, bufferSize);
    219 #endif
    220     m_uploadBufferSize = size;
    221 }
     169    PlatformCanvas::Painter painter(&m_canvas);
     170    painter.context()->save();
     171    painter.context()->translate(-paintingOffset.x(), -paintingOffset.y());
     172    painter.context()->clearRect(dirtyRect);
     173    painter.context()->clip(dirtyRect);
     174
     175    m_owner->paintGraphicsLayerContents(*painter.context(), dirtyRect);
     176    painter.context()->restore();
     177}
     178
    222179void ContentLayerChromium::resizeUploadBuffer(const IntSize& size)
    223180{
    224 #if USE(SKIA)
    225     m_uploadPixelCanvas = new skia::PlatformCanvas(size.width(), size.height(), false);
    226     m_uploadBufferSize = size;
    227 #else
    228     resizeUploadBufferForImage(size);
    229 #endif
    230 }
    231 
    232 #if USE(SKIA)
    233 class SkBitmapConditionalAutoLockerPixels {
    234     WTF_MAKE_NONCOPYABLE(SkBitmapConditionalAutoLockerPixels);
    235 public:
    236     SkBitmapConditionalAutoLockerPixels()
    237         : m_bitmap(0)
    238     {
    239     }
    240 
    241     ~SkBitmapConditionalAutoLockerPixels()
    242     {
    243         if (m_bitmap)
    244             m_bitmap->unlockPixels();
    245     }
    246 
    247     void lockPixels(const SkBitmap* bitmap)
    248     {
    249         bitmap->lockPixels();
    250         m_bitmap = bitmap;
    251     }
    252 
    253 private:
    254     const SkBitmap* m_bitmap;
    255 };
    256 #endif
     181    m_canvas.resize(size);
     182}
    257183
    258184void ContentLayerChromium::updateTextureIfNeeded()
    259185{
    260     uint8_t* pixels = 0;
    261 #if USE(SKIA)
    262     SkBitmapConditionalAutoLockerPixels locker;
    263 #endif
    264     if (!m_uploadUpdateRect.isEmpty()) {
    265 #if USE(SKIA)
    266         if (m_uploadPixelCanvas) {
    267             const SkBitmap& bitmap = m_uploadPixelCanvas->getDevice()->accessBitmap(false);
    268             locker.lockPixels(&bitmap);
    269             // FIXME: do we need to support more image configurations?
    270             if (bitmap.config() == SkBitmap::kARGB_8888_Config)
    271                 pixels = static_cast<uint8_t*>(bitmap.getPixels());
    272         }
    273 #endif
    274         if (m_uploadPixelData)
    275             pixels = m_uploadPixelData->data();
    276     }
    277 
     186    PlatformCanvas::AutoLocker locker(&m_canvas);
     187    updateTexture(locker.pixels(), m_canvas.size());
     188}
     189
     190void ContentLayerChromium::updateTexture(const uint8_t* pixels, const IntSize& size)
     191{
    278192    if (!pixels)
    279193        return;
     
    284198
    285199    // If we have to allocate a new texture we have to upload the full contents.
    286     if (!m_contentsTexture->isValid(m_uploadBufferSize, GraphicsContext3D::RGBA))
    287         m_uploadUpdateRect = IntRect(IntPoint(0, 0), m_uploadBufferSize);
    288 
    289     if (!m_contentsTexture->reserve(m_uploadBufferSize, GraphicsContext3D::RGBA)) {
     200    if (!m_contentsTexture->isValid(size, GraphicsContext3D::RGBA))
     201        m_uploadUpdateRect = IntRect(IntPoint(0, 0), size);
     202
     203    if (!m_contentsTexture->reserve(size, GraphicsContext3D::RGBA)) {
    290204        m_skipsDraw = true;
    291205        return;
    292206    }
    293207
    294     IntRect srcRect = IntRect(IntPoint(0, 0), m_uploadBufferSize);
     208    IntRect srcRect = IntRect(IntPoint(0, 0), size);
    295209    if (requiresClippedUpdateRect())
    296210        srcRect = m_visibleRectInLayerCoords;
    297211
    298     const size_t destStride = m_uploadUpdateRect.width() * 4;
     212    const size_t destStride = size.width() * 4;
    299213    const size_t srcStride = srcRect.width() * 4;
    300214
    301     uint8_t* uploadPixels = pixels + srcStride * m_uploadUpdateRect.x();
     215    const uint8_t* uploadPixels = pixels + srcStride * m_uploadUpdateRect.x();
    302216    Vector<uint8_t> uploadBuffer;
    303217    if (srcStride != destStride) {
     
    305219        for (int row = 0; row < m_uploadUpdateRect.height(); ++row) {
    306220            size_t srcOffset = (m_uploadUpdateRect.y() + row) * srcStride + m_uploadUpdateRect.x() * 4;
    307             ASSERT(srcOffset + destStride <= static_cast<size_t>(m_uploadBufferSize.width() * m_uploadBufferSize.height() * 4));
     221            ASSERT(srcOffset + destStride <= static_cast<size_t>(size.width() * size.height() * 4));
    308222            size_t destOffset = row * destStride;
    309223            ASSERT(destOffset  + destStride <= uploadBuffer.size());
     
    327241void ContentLayerChromium::draw()
    328242{
    329     updateTextureIfNeeded();
    330 
    331243    if (m_skipsDraw)
    332244        return;
  • trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.h

    r79578 r79877  
    3636
    3737#include "LayerChromium.h"
     38#include "PlatformCanvas.h"
    3839#include "TextureManager.h"
    3940
     
    6566    bool requiresClippedUpdateRect() const;
    6667    void resizeUploadBuffer(const IntSize&);
    67     void resizeUploadBufferForImage(const IntSize&);
    6868
    6969    OwnPtr<LayerTexture> m_contentsTexture;
    7070    bool m_skipsDraw;
    7171
    72     // The size of the upload buffer (also the size of our backing texture).
    73     IntSize m_uploadBufferSize;
    7472    // The portion of the upload buffer that has a pending update, in the coordinates of the texture.
    7573    IntRect m_uploadUpdateRect;
    76     // On platforms using Skia, we use the skia::PlatformCanvas for content layers
    77     // and the m_uploadPixelData buffer for image layers.
    78     // FIXME: We should be using memory we control for all uploads.
    79 #if USE(SKIA)
    80     OwnPtr<skia::PlatformCanvas> m_uploadPixelCanvas;
    81 #endif
    82     OwnPtr<Vector<uint8_t> > m_uploadPixelData;
     74
     75    virtual void updateTextureIfNeeded();
     76    void updateTexture(const uint8_t* pixels, const IntSize&);
    8377
    8478private:
    85     void updateTextureIfNeeded();
     79    PlatformCanvas m_canvas;
    8680
    8781    IntRect m_visibleRectInLayerCoords;
  • trunk/Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp

    r79578 r79877  
    3939#include "LayerTexture.h"
    4040
    41 #if USE(SKIA)
    42 #include "NativeImageSkia.h"
    43 #include "PlatformContextSkia.h"
    44 #endif
    45 
    46 #if PLATFORM(CG)
    47 #include <CoreGraphics/CGBitmapContext.h>
    48 #include <CoreGraphics/CGContext.h>
    49 #include <CoreGraphics/CGImage.h>
    50 #include <wtf/RetainPtr.h>
    51 #endif
    52 
    5341namespace WebCore {
    5442
     
    8573    }
    8674
    87     NativeImagePtr nativeImage = m_contents->nativeImageForCurrentFrame();
     75    m_decodedImage.updateFromImage(m_contents->nativeImageForCurrentFrame());
     76}
    8877
    89 #if USE(SKIA)
    90     // The layer contains an Image.
    91     NativeImageSkia* skiaImage = static_cast<NativeImageSkia*>(nativeImage);
    92     const SkBitmap* skiaBitmap = skiaImage;
    93     IntSize bitmapSize(skiaBitmap->width(), skiaBitmap->height());
    94     ASSERT(skiaBitmap);
    95 #elif PLATFORM(CG)
    96     // NativeImagePtr is a CGImageRef on Mac OS X.
    97     int width = CGImageGetWidth(nativeImage);
    98     int height = CGImageGetHeight(nativeImage);
    99     IntSize bitmapSize(width, height);
    100 #endif
    101 
    102     if (m_uploadBufferSize != bitmapSize)
    103         resizeUploadBufferForImage(bitmapSize);
    104     m_uploadUpdateRect = IntRect(IntPoint(0, 0), bitmapSize);
    105 
    106 #if USE(SKIA)
    107     SkAutoLockPixels lock(*skiaBitmap);
    108     // FIXME: do we need to support more image configurations?
    109     ASSERT(skiaBitmap->config()== SkBitmap::kARGB_8888_Config);
    110     skiaBitmap->copyPixelsTo(m_uploadPixelData->data(), m_uploadPixelData->size());
    111 #elif PLATFORM(CG)
    112     // FIXME: we should get rid of this temporary copy where possible.
    113     int tempRowBytes = width * 4;
    114     // Note we do not zero this vector since we are going to
    115     // completely overwrite its contents with the image below.
    116     // Try to reuse the color space from the image to preserve its colors.
    117     // Some images use a color space (such as indexed) unsupported by the bitmap context.
    118     RetainPtr<CGColorSpaceRef> colorSpaceReleaser;
    119     CGColorSpaceRef colorSpace = CGImageGetColorSpace(nativeImage);
    120     CGColorSpaceModel colorSpaceModel = CGColorSpaceGetModel(colorSpace);
    121     switch (colorSpaceModel) {
    122     case kCGColorSpaceModelMonochrome:
    123     case kCGColorSpaceModelRGB:
    124     case kCGColorSpaceModelCMYK:
    125     case kCGColorSpaceModelLab:
    126     case kCGColorSpaceModelDeviceN:
    127         break;
    128     default:
    129         colorSpaceReleaser.adoptCF(CGColorSpaceCreateDeviceRGB());
    130         colorSpace = colorSpaceReleaser.get();
    131         break;
    132     }
    133     RetainPtr<CGContextRef> tempContext(AdoptCF, CGBitmapContextCreate(m_uploadPixelData->data(),
    134                                                                        width, height, 8, tempRowBytes,
    135                                                                        colorSpace,
    136                                                                        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
    137     CGContextSetBlendMode(tempContext.get(), kCGBlendModeCopy);
    138     CGContextDrawImage(tempContext.get(),
    139                        CGRectMake(0, 0, static_cast<CGFloat>(width), static_cast<CGFloat>(height)),
    140                        nativeImage);
    141 #else
    142 #error "Need to implement for your platform."
    143 #endif
     78void ImageLayerChromium::updateTextureIfNeeded()
     79{
     80    updateTexture(m_decodedImage.pixels(), m_decodedImage.size());
    14481}
    14582
  • trunk/Source/WebCore/platform/graphics/chromium/ImageLayerChromium.h

    r73663 r79877  
    3636
    3737#include "ContentLayerChromium.h"
     38#include "PlatformImage.h"
    3839
    3940#if PLATFORM(CG)
     
    5657
    5758private:
     59    virtual void updateTextureIfNeeded();
     60
    5861    ImageLayerChromium(GraphicsLayerChromium* owner);
    5962
     63    PlatformImage m_decodedImage;
    6064    RefPtr<Image> m_contents;
    6165};
  • trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.cpp

    r79578 r79877  
    3636#include "LayerTexture.h"
    3737
    38 #if USE(SKIA)
    39 #include "NativeImageSkia.h"
    40 #include "PlatformContextSkia.h"
    41 #elif PLATFORM(CG)
    42 #include <CoreGraphics/CGBitmapContext.h>
    43 #endif
    44 
    4538#include <wtf/PassOwnArrayPtr.h>
    4639
     
    149142    left = m_tilingData.tileXIndexFromSrcCoord(layerRect.x());
    150143    top = m_tilingData.tileYIndexFromSrcCoord(layerRect.y());
    151     right = m_tilingData.tileXIndexFromSrcCoord(layerRect.maxX());
    152     bottom = m_tilingData.tileYIndexFromSrcCoord(layerRect.maxY());
     144    right = m_tilingData.tileXIndexFromSrcCoord(layerRect.maxX() - 1);
     145    bottom = m_tilingData.tileYIndexFromSrcCoord(layerRect.maxY() - 1);
    153146}
    154147
     
    271264
    272265    const IntRect paintRect = layerRectToContentRect(dirtyLayerRect);
    273     GraphicsContext3D* context = layerRendererContext();
    274 #if USE(SKIA)
    275     OwnPtr<skia::PlatformCanvas> canvas(new skia::PlatformCanvas(paintRect.width(), paintRect.height(), false));
    276     OwnPtr<PlatformContextSkia> skiaContext(new PlatformContextSkia(canvas.get()));
    277     OwnPtr<GraphicsContext> graphicsContext(new GraphicsContext(reinterpret_cast<PlatformGraphicsContext*>(skiaContext.get())));
    278 
    279     // Bring the canvas into the coordinate system of the paint rect.
    280     canvas->translate(static_cast<SkScalar>(-paintRect.x()), static_cast<SkScalar>(-paintRect.y()));
    281 
    282     painter.paint(*graphicsContext, paintRect);
    283 
    284     // Get the contents of the updated rect.
    285     const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(false);
    286     ASSERT(bitmap.width() == paintRect.width() && bitmap.height() == paintRect.height());
    287     if (bitmap.width() != paintRect.width() || bitmap.height() != paintRect.height())
    288         CRASH();
    289     uint8_t* paintPixels = static_cast<uint8_t*>(bitmap.getPixels());
    290     if (!paintPixels)
    291         CRASH();
    292 #elif PLATFORM(CG)
    293     Vector<uint8_t> canvasPixels;
    294     int rowBytes = 4 * paintRect.width();
    295     canvasPixels.resize(rowBytes * paintRect.height());
    296     memset(canvasPixels.data(), 0, canvasPixels.size());
    297     RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
    298     RetainPtr<CGContextRef> m_cgContext;
    299     m_cgContext.adoptCF(CGBitmapContextCreate(canvasPixels.data(),
    300                                                        paintRect.width(), paintRect.height(), 8, rowBytes,
    301                                                        colorSpace.get(),
    302                                                        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
    303     CGContextTranslateCTM(m_cgContext.get(), 0, paintRect.height());
    304     CGContextScaleCTM(m_cgContext.get(), 1, -1);
    305     OwnPtr<GraphicsContext> m_graphicsContext(new GraphicsContext(m_cgContext.get()));
    306 
    307     // Bring the CoreGraphics context into the coordinate system of the paint rect.
    308     CGContextTranslateCTM(m_cgContext.get(), -paintRect.x(), -paintRect.y());
    309     painter.paint(*m_graphicsContext, paintRect);
    310 
    311     // Get the contents of the updated rect.
    312     ASSERT(static_cast<int>(CGBitmapContextGetWidth(m_cgContext.get())) == paintRect.width() && static_cast<int>(CGBitmapContextGetHeight(m_cgContext.get())) == paintRect.height());
    313     uint8_t* paintPixels = static_cast<uint8_t*>(canvasPixels.data());
    314 #else
    315 #error "Need to implement for your platform."
    316 #endif
    317 
     266
     267    m_canvas.resize(paintRect.size());
     268    PlatformCanvas::Painter canvasPainter(&m_canvas);
     269    canvasPainter.context()->translate(-paintRect.x(), -paintRect.y());
     270    painter.paint(*canvasPainter.context(), paintRect);
     271
     272    PlatformCanvas::AutoLocker locker(&m_canvas);
     273    updateFromPixels(paintRect, locker.pixels());
     274}
     275
     276void LayerTilerChromium::updateFromPixels(const IntRect& paintRect, const uint8_t* paintPixels)
     277{
    318278    // Painting could cause compositing to get turned off, which may cause the tiler to become invalidated mid-update.
    319279    if (!m_tiles.size())
    320280        return;
    321281
     282    GraphicsContext3D* context = layerRendererContext();
     283
     284    int left, top, right, bottom;
     285    contentRectToTileIndices(paintRect, left, top, right, bottom);
    322286    for (int j = top; j <= bottom; ++j) {
    323287        for (int i = left; i <= right; ++i) {
     
    359323                CRASH();
    360324
    361             uint8_t* pixelSource;
     325            const uint8_t* pixelSource;
    362326            if (paintRect.width() == sourceRect.width() && !paintOffset.x())
    363327                pixelSource = &paintPixels[4 * paintOffset.y() * paintRect.width()];
  • trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.h

    r79043 r79877  
    3232#include "LayerChromium.h"
    3333#include "LayerTexture.h"
     34#include "PlatformCanvas.h"
    3435#include "TilingData.h"
    3536#include <wtf/OwnArrayPtr.h>
     
    5758    void invalidateEntireLayer();
    5859    void update(TilePaintInterface& painter, const IntRect& contentRect);
     60    void updateFromPixels(const IntRect& paintRect, const uint8_t* pixels);
    5961    void draw(const IntRect& contentRect);
    6062
     
    126128    Vector<OwnPtr<Tile> > m_unusedTiles;
    127129
     130    PlatformCanvas m_canvas;
     131
    128132    // Cache a tile-sized pixel buffer to draw into.
    129133    OwnArrayPtr<uint8_t> m_tilePixels;
  • trunk/Source/WebCore/platform/graphics/chromium/PlatformImage.cpp

    r79876 r79877  
    11/*
    2  * Copyright (C) 2010 Google Inc. All rights reserved.
     2 * Copyright (C) 2011 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions are
    6  * met:
     5 * modification, are permitted provided that the following conditions
     6 * are met:
    77 *
    8  *     * Redistributions of source code must retain the above copyright
    9  * notice, this list of conditions and the following disclaimer.
    10  *     * Redistributions in binary form must reproduce the above
    11  * copyright notice, this list of conditions and the following disclaimer
    12  * in the documentation and/or other materials provided with the
    13  * distribution.
    14  *     * Neither the name of Google Inc. nor the names of its
    15  * contributors may be used to endorse or promote products derived from
    16  * this software without specific prior written permission.
     8 * 1.  Redistributions of source code must retain the above copyright
     9 *     notice, this list of conditions and the following disclaimer.
     10 * 2.  Redistributions in binary form must reproduce the above copyright
     11 *     notice, this list of conditions and the following disclaimer in the
     12 *     documentation and/or other materials provided with the distribution.
    1713 *
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2924 */
    3025
    3126#include "config.h"
    3227
    33 #if USE(ACCELERATED_COMPOSITING)
    34 
    35 #include "ImageLayerChromium.h"
    36 
    37 #include "Image.h"
    38 #include "LayerRendererChromium.h"
    39 #include "LayerTexture.h"
     28#include "PlatformImage.h"
    4029
    4130#if USE(SKIA)
    4231#include "NativeImageSkia.h"
    4332#include "PlatformContextSkia.h"
    44 #endif
    45 
    46 #if PLATFORM(CG)
     33#elif PLATFORM(CG)
    4734#include <CoreGraphics/CGBitmapContext.h>
    4835#include <CoreGraphics/CGContext.h>
    4936#include <CoreGraphics/CGImage.h>
    5037#include <wtf/RetainPtr.h>
     38#else
     39#error "Need to implement for your platform"
    5140#endif
    5241
    5342namespace WebCore {
    5443
    55 PassRefPtr<ImageLayerChromium> ImageLayerChromium::create(GraphicsLayerChromium* owner)
    56 {
    57     return adoptRef(new ImageLayerChromium(owner));
    58 }
    59 
    60 ImageLayerChromium::ImageLayerChromium(GraphicsLayerChromium* owner)
    61     : ContentLayerChromium(owner)
    62     , m_contents(0)
     44PlatformImage::PlatformImage()
    6345{
    6446}
    6547
    66 void ImageLayerChromium::setContents(Image* contents)
     48void PlatformImage::updateFromImage(NativeImagePtr nativeImage)
    6749{
    68     // Check if the image has changed.
    69     if (m_contents == contents)
    70         return;
    71     m_contents = contents;
    72     setNeedsDisplay();
    73 }
    74 
    75 void ImageLayerChromium::updateContentsIfDirty()
    76 {
    77     ASSERT(layerRenderer());
    78 
    79     // FIXME: Remove this test when tiled layers are implemented.
    80     if (requiresClippedUpdateRect()) {
    81         // Use the base version of updateContents which draws a subset of the
    82         // image to a bitmap, as the pixel contents can't be uploaded directly.
    83         ContentLayerChromium::updateContentsIfDirty();
    84         return;
    85     }
    86 
    87     NativeImagePtr nativeImage = m_contents->nativeImageForCurrentFrame();
    88 
    8950#if USE(SKIA)
    9051    // The layer contains an Image.
    9152    NativeImageSkia* skiaImage = static_cast<NativeImageSkia*>(nativeImage);
    9253    const SkBitmap* skiaBitmap = skiaImage;
     54
    9355    IntSize bitmapSize(skiaBitmap->width(), skiaBitmap->height());
    9456    ASSERT(skiaBitmap);
     
    10062#endif
    10163
    102     if (m_uploadBufferSize != bitmapSize)
    103         resizeUploadBufferForImage(bitmapSize);
    104     m_uploadUpdateRect = IntRect(IntPoint(0, 0), bitmapSize);
     64    size_t bufferSize = bitmapSize.width() * bitmapSize.height() * 4;
     65    if (m_size != bitmapSize) {
     66        m_pixelData = adoptArrayPtr(new uint8_t[bufferSize]);
     67        memset(m_pixelData.get(), 0, bufferSize);
     68        m_size = bitmapSize;
     69    }
    10570
    10671#if USE(SKIA)
     
    10873    // FIXME: do we need to support more image configurations?
    10974    ASSERT(skiaBitmap->config()== SkBitmap::kARGB_8888_Config);
    110     skiaBitmap->copyPixelsTo(m_uploadPixelData->data(), m_uploadPixelData->size());
     75    skiaBitmap->copyPixelsTo(m_pixelData.get(), bufferSize);
    11176#elif PLATFORM(CG)
    11277    // FIXME: we should get rid of this temporary copy where possible.
     
    13196        break;
    13297    }
    133     RetainPtr<CGContextRef> tempContext(AdoptCF, CGBitmapContextCreate(m_uploadPixelData->data(),
     98    RetainPtr<CGContextRef> tempContext(AdoptCF, CGBitmapContextCreate(m_pixelData.get(),
    13499                                                                       width, height, 8, tempRowBytes,
    135100                                                                       colorSpace,
     
    144109}
    145110
    146 }
    147 #endif // USE(ACCELERATED_COMPOSITING)
     111} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.