OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2011 Google 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 * |
| 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. |
| 13 * |
| 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. |
| 24 */ |
| 25 |
| 26 |
| 27 #include "config.h" |
| 28 |
| 29 #if USE(ACCELERATED_COMPOSITING) |
| 30 |
| 31 #include "BitmapSkPictureCanvasLayerTextureUpdater.h" |
| 32 |
| 33 #include "LayerPainterChromium.h" |
| 34 #include "PlatformColor.h" |
| 35 #include "SkCanvas.h" |
| 36 #include "SkDevice.h" |
| 37 |
| 38 namespace WebCore { |
| 39 |
| 40 BitmapSkPictureCanvasLayerTextureUpdater::Texture::Texture(BitmapSkPictureCanvas
LayerTextureUpdater* textureUpdater, PassOwnPtr<ManagedTexture> texture) |
| 41 : CanvasLayerTextureUpdater::Texture(texture) |
| 42 , m_textureUpdater(textureUpdater) |
| 43 { |
| 44 } |
| 45 |
| 46 void BitmapSkPictureCanvasLayerTextureUpdater::Texture::prepareRect(const IntRec
t& sourceRect) |
| 47 { |
| 48 m_bitmap.setConfig(SkBitmap::kARGB_8888_Config, sourceRect.width(), sourceRe
ct.height()); |
| 49 m_bitmap.allocPixels(); |
| 50 m_bitmap.setIsOpaque(m_textureUpdater->layerIsOpaque()); |
| 51 SkDevice device(m_bitmap); |
| 52 SkCanvas canvas(&device); |
| 53 textureUpdater()->paintContentsRect(&canvas, sourceRect); |
| 54 } |
| 55 |
| 56 void BitmapSkPictureCanvasLayerTextureUpdater::Texture::updateRect(CCGraphicsCon
text* context, TextureAllocator* allocator, const IntRect& sourceRect, const Int
Rect& destRect) |
| 57 { |
| 58 texture()->bindTexture(context, allocator); |
| 59 |
| 60 m_bitmap.lockPixels(); |
| 61 textureUpdater()->updateTextureRect(context, texture()->format(), destRect,
static_cast<uint8_t*>(m_bitmap.getPixels())); |
| 62 m_bitmap.unlockPixels(); |
| 63 m_bitmap.reset(); |
| 64 } |
| 65 |
| 66 PassRefPtr<BitmapSkPictureCanvasLayerTextureUpdater> BitmapSkPictureCanvasLayerT
extureUpdater::create(PassOwnPtr<LayerPainterChromium> painter, bool useMapTexSu
bImage) |
| 67 { |
| 68 return adoptRef(new BitmapSkPictureCanvasLayerTextureUpdater(painter, useMap
TexSubImage)); |
| 69 } |
| 70 |
| 71 BitmapSkPictureCanvasLayerTextureUpdater::BitmapSkPictureCanvasLayerTextureUpdat
er(PassOwnPtr<LayerPainterChromium> painter, bool useMapTexSubImage) |
| 72 : SkPictureCanvasLayerTextureUpdater(painter) |
| 73 , m_texSubImage(useMapTexSubImage) |
| 74 { |
| 75 } |
| 76 |
| 77 BitmapSkPictureCanvasLayerTextureUpdater::~BitmapSkPictureCanvasLayerTextureUpda
ter() |
| 78 { |
| 79 } |
| 80 |
| 81 PassOwnPtr<LayerTextureUpdater::Texture> BitmapSkPictureCanvasLayerTextureUpdate
r::createTexture(TextureManager* manager) |
| 82 { |
| 83 return adoptPtr(new Texture(this, ManagedTexture::create(manager))); |
| 84 } |
| 85 |
| 86 LayerTextureUpdater::SampledTexelFormat BitmapSkPictureCanvasLayerTextureUpdater
::sampledTexelFormat(GC3Denum textureFormat) |
| 87 { |
| 88 // The component order may be bgra if we uploaded bgra pixels to rgba textur
es. |
| 89 return PlatformColor::sameComponentOrder(textureFormat) ? |
| 90 LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdater::S
ampledTexelFormatBGRA; |
| 91 } |
| 92 |
| 93 void BitmapSkPictureCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& co
ntentRect, const IntSize& tileSize, float contentsScale, IntRect& resultingOpaqu
eRect) |
| 94 { |
| 95 m_texSubImage.setSubImageSize(tileSize); |
| 96 SkPictureCanvasLayerTextureUpdater::prepareToUpdate(contentRect, tileSize, c
ontentsScale, resultingOpaqueRect); |
| 97 } |
| 98 |
| 99 void BitmapSkPictureCanvasLayerTextureUpdater::paintContentsRect(SkCanvas* canva
s, const IntRect& sourceRect) |
| 100 { |
| 101 // Translate the origin of contentRect to that of sourceRect. |
| 102 canvas->translate(contentRect().x() - sourceRect.x(), |
| 103 contentRect().y() - sourceRect.y()); |
| 104 drawPicture(canvas); |
| 105 } |
| 106 |
| 107 void BitmapSkPictureCanvasLayerTextureUpdater::updateTextureRect(CCGraphicsConte
xt* context, GC3Denum format, const IntRect& destRect, const uint8_t* pixels) |
| 108 { |
| 109 m_texSubImage.upload(pixels, destRect, destRect, destRect, format, context); |
| 110 } |
| 111 |
| 112 } // namespace WebCore |
| 113 #endif // USE(ACCELERATED_COMPOSITING) |
OLD | NEW |