Implement android_webview url intercepting.
[chromium-blink-merge.git] / cc / image_layer.cc
blob286ee8bc92f07befcaf42f37c1c57cca51a70ad8
1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "config.h"
7 #include "ImageLayerChromium.h"
9 #include "base/compiler_specific.h"
10 #include "CCLayerTreeHost.h"
11 #include "CCTextureUpdateQueue.h"
12 #include "LayerTextureUpdater.h"
13 #include "PlatformColor.h"
15 namespace cc {
17 class ImageLayerTextureUpdater : public LayerTextureUpdater {
18 public:
19 class Texture : public LayerTextureUpdater::Texture {
20 public:
21 Texture(ImageLayerTextureUpdater* textureUpdater, scoped_ptr<CCPrioritizedTexture> texture)
22 : LayerTextureUpdater::Texture(texture.Pass())
23 , m_textureUpdater(textureUpdater)
27 virtual void update(CCTextureUpdateQueue& queue, const IntRect& sourceRect, const IntSize& destOffset, bool partialUpdate, CCRenderingStats&) OVERRIDE
29 textureUpdater()->updateTexture(queue, texture(), sourceRect, destOffset, partialUpdate);
32 private:
33 ImageLayerTextureUpdater* textureUpdater() { return m_textureUpdater; }
35 ImageLayerTextureUpdater* m_textureUpdater;
38 static PassRefPtr<ImageLayerTextureUpdater> create()
40 return adoptRef(new ImageLayerTextureUpdater());
43 virtual ~ImageLayerTextureUpdater() { }
45 virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(
46 CCPrioritizedTextureManager* manager) OVERRIDE
48 return adoptPtr(new Texture(this, CCPrioritizedTexture::create(manager)));
51 virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) OVERRIDE
53 return PlatformColor::sameComponentOrder(textureFormat) ?
54 LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdater::SampledTexelFormatBGRA;
57 void updateTexture(CCTextureUpdateQueue& queue, CCPrioritizedTexture* texture, const IntRect& sourceRect, const IntSize& destOffset, bool partialUpdate)
59 // Source rect should never go outside the image pixels, even if this
60 // is requested because the texture extends outside the image.
61 IntRect clippedSourceRect = sourceRect;
62 IntRect imageRect = IntRect(0, 0, m_bitmap.width(), m_bitmap.height());
63 clippedSourceRect.intersect(imageRect);
65 IntSize clippedDestOffset = destOffset + IntSize(clippedSourceRect.location() - sourceRect.location());
67 TextureUploader::Parameters upload = { texture, &m_bitmap, NULL, { imageRect, clippedSourceRect, clippedDestOffset } };
68 if (partialUpdate)
69 queue.appendPartialUpload(upload);
70 else
71 queue.appendFullUpload(upload);
74 void setBitmap(const SkBitmap& bitmap)
76 m_bitmap = bitmap;
79 private:
80 ImageLayerTextureUpdater() { }
82 SkBitmap m_bitmap;
85 scoped_refptr<ImageLayerChromium> ImageLayerChromium::create()
87 return make_scoped_refptr(new ImageLayerChromium());
90 ImageLayerChromium::ImageLayerChromium()
91 : TiledLayerChromium()
95 ImageLayerChromium::~ImageLayerChromium()
99 void ImageLayerChromium::setBitmap(const SkBitmap& bitmap)
101 // setBitmap() currently gets called whenever there is any
102 // style change that affects the layer even if that change doesn't
103 // affect the actual contents of the image (e.g. a CSS animation).
104 // With this check in place we avoid unecessary texture uploads.
105 if (bitmap.pixelRef() && bitmap.pixelRef() == m_bitmap.pixelRef())
106 return;
108 m_bitmap = bitmap;
109 setNeedsDisplay();
112 void ImageLayerChromium::setTexturePriorities(const CCPriorityCalculator& priorityCalc)
114 // Update the tile data before creating all the layer's tiles.
115 updateTileSizeAndTilingOption();
117 TiledLayerChromium::setTexturePriorities(priorityCalc);
120 void ImageLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclusionTracker* occlusion, CCRenderingStats& stats)
122 createTextureUpdaterIfNeeded();
123 if (m_needsDisplay) {
124 m_textureUpdater->setBitmap(m_bitmap);
125 updateTileSizeAndTilingOption();
126 invalidateContentRect(IntRect(IntPoint(), contentBounds()));
127 m_needsDisplay = false;
129 TiledLayerChromium::update(queue, occlusion, stats);
132 void ImageLayerChromium::createTextureUpdaterIfNeeded()
134 if (m_textureUpdater)
135 return;
137 m_textureUpdater = ImageLayerTextureUpdater::create();
138 GC3Denum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
139 setTextureFormat(textureFormat);
140 setSampledTexelFormat(textureUpdater()->sampledTexelFormat(textureFormat));
143 LayerTextureUpdater* ImageLayerChromium::textureUpdater() const
145 return m_textureUpdater.get();
148 IntSize ImageLayerChromium::contentBounds() const
150 return IntSize(m_bitmap.width(), m_bitmap.height());
153 bool ImageLayerChromium::drawsContent() const
155 return !m_bitmap.isNull() && TiledLayerChromium::drawsContent();
158 bool ImageLayerChromium::needsContentsScale() const
160 // Contents scale is not need for image layer because this can be done in compositor more efficiently.
161 return false;