OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2010 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 are |
| 6 * met: |
| 7 * |
| 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. |
| 17 * |
| 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. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 |
| 33 #if USE(ACCELERATED_COMPOSITING) |
| 34 |
| 35 #include "ImageLayerChromium.h" |
| 36 |
| 37 #include "LayerTextureSubImage.h" |
| 38 #include "LayerTextureUpdater.h" |
| 39 #include "ManagedTexture.h" |
| 40 #include "PlatformColor.h" |
| 41 #include "cc/CCLayerTreeHost.h" |
| 42 |
| 43 namespace WebCore { |
| 44 |
| 45 class ImageLayerTextureUpdater : public LayerTextureUpdater { |
| 46 public: |
| 47 class Texture : public LayerTextureUpdater::Texture { |
| 48 public: |
| 49 Texture(ImageLayerTextureUpdater* textureUpdater, PassOwnPtr<ManagedText
ure> texture) |
| 50 : LayerTextureUpdater::Texture(texture) |
| 51 , m_textureUpdater(textureUpdater) |
| 52 { |
| 53 } |
| 54 |
| 55 virtual void updateRect(CCGraphicsContext* context, TextureAllocator* al
locator, const IntRect& sourceRect, const IntRect& destRect) OVERRIDE |
| 56 { |
| 57 textureUpdater()->updateTextureRect(context, allocator, texture(), s
ourceRect, destRect); |
| 58 } |
| 59 |
| 60 private: |
| 61 ImageLayerTextureUpdater* textureUpdater() { return m_textureUpdater; } |
| 62 |
| 63 ImageLayerTextureUpdater* m_textureUpdater; |
| 64 }; |
| 65 |
| 66 static PassRefPtr<ImageLayerTextureUpdater> create(bool useMapTexSubImage) |
| 67 { |
| 68 return adoptRef(new ImageLayerTextureUpdater(useMapTexSubImage)); |
| 69 } |
| 70 |
| 71 virtual ~ImageLayerTextureUpdater() { } |
| 72 |
| 73 virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(TextureManage
r* manager) |
| 74 { |
| 75 return adoptPtr(new Texture(this, ManagedTexture::create(manager))); |
| 76 } |
| 77 |
| 78 virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) OVERRI
DE |
| 79 { |
| 80 return PlatformColor::sameComponentOrder(textureFormat) ? |
| 81 LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdate
r::SampledTexelFormatBGRA; |
| 82 } |
| 83 |
| 84 void updateTextureRect(CCGraphicsContext* context, TextureAllocator* allocat
or, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect) |
| 85 { |
| 86 texture->bindTexture(context, allocator); |
| 87 |
| 88 // Source rect should never go outside the image pixels, even if this |
| 89 // is requested because the texture extends outside the image. |
| 90 IntRect clippedSourceRect = sourceRect; |
| 91 IntRect imageRect = IntRect(0, 0, m_bitmap.width(), m_bitmap.height()); |
| 92 clippedSourceRect.intersect(imageRect); |
| 93 |
| 94 IntRect clippedDestRect = destRect; |
| 95 clippedDestRect.move(clippedSourceRect.location() - sourceRect.location(
)); |
| 96 clippedDestRect.setSize(clippedSourceRect.size()); |
| 97 |
| 98 SkAutoLockPixels lock(m_bitmap); |
| 99 m_texSubImage.upload(static_cast<const uint8_t*>(m_bitmap.getPixels()),
imageRect, clippedSourceRect, clippedDestRect, texture->format(), context); |
| 100 } |
| 101 |
| 102 void setBitmap(const SkBitmap& bitmap) |
| 103 { |
| 104 m_bitmap = bitmap; |
| 105 } |
| 106 |
| 107 private: |
| 108 explicit ImageLayerTextureUpdater(bool useMapTexSubImage) |
| 109 : m_texSubImage(useMapTexSubImage) |
| 110 { |
| 111 } |
| 112 |
| 113 SkBitmap m_bitmap; |
| 114 LayerTextureSubImage m_texSubImage; |
| 115 }; |
| 116 |
| 117 PassRefPtr<ImageLayerChromium> ImageLayerChromium::create() |
| 118 { |
| 119 return adoptRef(new ImageLayerChromium()); |
| 120 } |
| 121 |
| 122 ImageLayerChromium::ImageLayerChromium() |
| 123 : TiledLayerChromium() |
| 124 { |
| 125 } |
| 126 |
| 127 ImageLayerChromium::~ImageLayerChromium() |
| 128 { |
| 129 } |
| 130 |
| 131 void ImageLayerChromium::setBitmap(const SkBitmap& bitmap) |
| 132 { |
| 133 // setBitmap() currently gets called whenever there is any |
| 134 // style change that affects the layer even if that change doesn't |
| 135 // affect the actual contents of the image (e.g. a CSS animation). |
| 136 // With this check in place we avoid unecessary texture uploads. |
| 137 if (bitmap.pixelRef() && bitmap.pixelRef() == m_bitmap.pixelRef()) |
| 138 return; |
| 139 |
| 140 m_bitmap = bitmap; |
| 141 setNeedsDisplay(); |
| 142 } |
| 143 |
| 144 void ImageLayerChromium::update(CCTextureUpdater& updater, const CCOcclusionTrac
ker* occlusion) |
| 145 { |
| 146 createTextureUpdaterIfNeeded(); |
| 147 if (m_needsDisplay) { |
| 148 m_textureUpdater->setBitmap(m_bitmap); |
| 149 updateTileSizeAndTilingOption(); |
| 150 invalidateRect(IntRect(IntPoint(), contentBounds())); |
| 151 m_needsDisplay = false; |
| 152 } |
| 153 |
| 154 updateLayerRect(updater, visibleLayerRect(), occlusion); |
| 155 } |
| 156 |
| 157 void ImageLayerChromium::createTextureUpdaterIfNeeded() |
| 158 { |
| 159 if (m_textureUpdater) |
| 160 return; |
| 161 |
| 162 m_textureUpdater = ImageLayerTextureUpdater::create(layerTreeHost()->layerRe
ndererCapabilities().usingMapSub); |
| 163 GC3Denum textureFormat = layerTreeHost()->layerRendererCapabilities().bestTe
xtureFormat; |
| 164 setTextureFormat(textureFormat); |
| 165 setSampledTexelFormat(textureUpdater()->sampledTexelFormat(textureFormat)); |
| 166 } |
| 167 |
| 168 LayerTextureUpdater* ImageLayerChromium::textureUpdater() const |
| 169 { |
| 170 return m_textureUpdater.get(); |
| 171 } |
| 172 |
| 173 IntSize ImageLayerChromium::contentBounds() const |
| 174 { |
| 175 return IntSize(m_bitmap.width(), m_bitmap.height()); |
| 176 } |
| 177 |
| 178 bool ImageLayerChromium::drawsContent() const |
| 179 { |
| 180 return !m_bitmap.isNull() && TiledLayerChromium::drawsContent(); |
| 181 } |
| 182 |
| 183 bool ImageLayerChromium::needsContentsScale() const |
| 184 { |
| 185 // Contents scale is not need for image layer because this can be done in co
mpositor more efficiently. |
| 186 return false; |
| 187 } |
| 188 |
| 189 } |
| 190 #endif // USE(ACCELERATED_COMPOSITING) |
OLD | NEW |