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 "BitmapCanvasLayerTextureUpdater.h" |
| 32 |
| 33 #include "LayerPainterChromium.h" |
| 34 #include "PlatformColor.h" |
| 35 #include "skia/ext/platform_canvas.h" |
| 36 |
| 37 namespace WebCore { |
| 38 |
| 39 BitmapCanvasLayerTextureUpdater::Texture::Texture(BitmapCanvasLayerTextureUpdate
r* textureUpdater, PassOwnPtr<ManagedTexture> texture) |
| 40 : LayerTextureUpdater::Texture(texture) |
| 41 , m_textureUpdater(textureUpdater) |
| 42 { |
| 43 } |
| 44 |
| 45 BitmapCanvasLayerTextureUpdater::Texture::~Texture() |
| 46 { |
| 47 } |
| 48 |
| 49 void BitmapCanvasLayerTextureUpdater::Texture::updateRect(CCGraphicsContext* con
text, TextureAllocator* allocator, const IntRect& sourceRect, const IntRect& des
tRect) |
| 50 { |
| 51 textureUpdater()->updateTextureRect(context, allocator, texture(), sourceRec
t, destRect); |
| 52 } |
| 53 |
| 54 PassRefPtr<BitmapCanvasLayerTextureUpdater> BitmapCanvasLayerTextureUpdater::cre
ate(PassOwnPtr<LayerPainterChromium> painter, bool useMapTexSubImage) |
| 55 { |
| 56 return adoptRef(new BitmapCanvasLayerTextureUpdater(painter, useMapTexSubIma
ge)); |
| 57 } |
| 58 |
| 59 BitmapCanvasLayerTextureUpdater::BitmapCanvasLayerTextureUpdater(PassOwnPtr<Laye
rPainterChromium> painter, bool useMapTexSubImage) |
| 60 : CanvasLayerTextureUpdater(painter) |
| 61 , m_opaque(false) |
| 62 , m_texSubImage(useMapTexSubImage) |
| 63 { |
| 64 } |
| 65 |
| 66 BitmapCanvasLayerTextureUpdater::~BitmapCanvasLayerTextureUpdater() |
| 67 { |
| 68 } |
| 69 |
| 70 PassOwnPtr<LayerTextureUpdater::Texture> BitmapCanvasLayerTextureUpdater::create
Texture(TextureManager* manager) |
| 71 { |
| 72 return adoptPtr(new Texture(this, ManagedTexture::create(manager))); |
| 73 } |
| 74 |
| 75 LayerTextureUpdater::SampledTexelFormat BitmapCanvasLayerTextureUpdater::sampled
TexelFormat(GC3Denum textureFormat) |
| 76 { |
| 77 // The component order may be bgra if we uploaded bgra pixels to rgba textur
es. |
| 78 return PlatformColor::sameComponentOrder(textureFormat) ? |
| 79 LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdater::S
ampledTexelFormatBGRA; |
| 80 } |
| 81 |
| 82 void BitmapCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect
, const IntSize& tileSize, float contentsScale, IntRect& resultingOpaqueRect) |
| 83 { |
| 84 m_texSubImage.setSubImageSize(tileSize); |
| 85 |
| 86 if (m_canvasSize != contentRect.size()) { |
| 87 m_canvasSize = contentRect.size(); |
| 88 m_canvas = adoptPtr(skia::CreateBitmapCanvas(m_canvasSize.width(), m_can
vasSize.height(), m_opaque)); |
| 89 } |
| 90 |
| 91 paintContents(m_canvas.get(), contentRect, contentsScale, resultingOpaqueRec
t); |
| 92 } |
| 93 |
| 94 void BitmapCanvasLayerTextureUpdater::updateTextureRect(CCGraphicsContext* conte
xt, TextureAllocator* allocator, ManagedTexture* texture, const IntRect& sourceR
ect, const IntRect& destRect) |
| 95 { |
| 96 const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(false); |
| 97 bitmap.lockPixels(); |
| 98 |
| 99 texture->bindTexture(context, allocator); |
| 100 m_texSubImage.upload(static_cast<const uint8_t*>(bitmap.getPixels()), conten
tRect(), sourceRect, destRect, texture->format(), context); |
| 101 bitmap.unlockPixels(); |
| 102 } |
| 103 |
| 104 void BitmapCanvasLayerTextureUpdater::setOpaque(bool opaque) |
| 105 { |
| 106 if (opaque != m_opaque) { |
| 107 m_canvas.clear(); |
| 108 m_canvasSize = IntSize(); |
| 109 } |
| 110 m_opaque = opaque; |
| 111 } |
| 112 |
| 113 } // namespace WebCore |
| 114 #endif // USE(ACCELERATED_COMPOSITING) |
OLD | NEW |