1 // Copyright 2011 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.
8 #include "BitmapCanvasLayerTextureUpdater.h"
10 #include "CCTextureUpdateQueue.h"
11 #include "LayerPainterChromium.h"
12 #include "PlatformColor.h"
13 #include "skia/ext/platform_canvas.h"
17 BitmapCanvasLayerTextureUpdater::Texture::Texture(BitmapCanvasLayerTextureUpdater
* textureUpdater
, scoped_ptr
<CCPrioritizedTexture
> texture
)
18 : LayerTextureUpdater::Texture(texture
.Pass())
19 , m_textureUpdater(textureUpdater
)
23 BitmapCanvasLayerTextureUpdater::Texture::~Texture()
27 void BitmapCanvasLayerTextureUpdater::Texture::update(CCTextureUpdateQueue
& queue
, const IntRect
& sourceRect
, const IntSize
& destOffset
, bool partialUpdate
, CCRenderingStats
&)
29 textureUpdater()->updateTexture(queue
, texture(), sourceRect
, destOffset
, partialUpdate
);
32 PassRefPtr
<BitmapCanvasLayerTextureUpdater
> BitmapCanvasLayerTextureUpdater::create(scoped_ptr
<LayerPainterChromium
> painter
)
34 return adoptRef(new BitmapCanvasLayerTextureUpdater(painter
.Pass()));
37 BitmapCanvasLayerTextureUpdater::BitmapCanvasLayerTextureUpdater(scoped_ptr
<LayerPainterChromium
> painter
)
38 : CanvasLayerTextureUpdater(painter
.Pass())
43 BitmapCanvasLayerTextureUpdater::~BitmapCanvasLayerTextureUpdater()
47 PassOwnPtr
<LayerTextureUpdater::Texture
> BitmapCanvasLayerTextureUpdater::createTexture(CCPrioritizedTextureManager
* manager
)
49 return adoptPtr(new Texture(this, CCPrioritizedTexture::create(manager
)));
52 LayerTextureUpdater::SampledTexelFormat
BitmapCanvasLayerTextureUpdater::sampledTexelFormat(GC3Denum textureFormat
)
54 // The component order may be bgra if we uploaded bgra pixels to rgba textures.
55 return PlatformColor::sameComponentOrder(textureFormat
) ?
56 LayerTextureUpdater::SampledTexelFormatRGBA
: LayerTextureUpdater::SampledTexelFormatBGRA
;
59 void BitmapCanvasLayerTextureUpdater::prepareToUpdate(const IntRect
& contentRect
, const IntSize
& tileSize
, float contentsWidthScale
, float contentsHeightScale
, IntRect
& resultingOpaqueRect
, CCRenderingStats
& stats
)
61 if (m_canvasSize
!= contentRect
.size()) {
62 m_canvasSize
= contentRect
.size();
63 m_canvas
= adoptPtr(skia::CreateBitmapCanvas(m_canvasSize
.width(), m_canvasSize
.height(), m_opaque
));
66 paintContents(m_canvas
.get(), contentRect
, contentsWidthScale
, contentsHeightScale
, resultingOpaqueRect
, stats
);
69 void BitmapCanvasLayerTextureUpdater::updateTexture(CCTextureUpdateQueue
& queue
, CCPrioritizedTexture
* texture
, const IntRect
& sourceRect
, const IntSize
& destOffset
, bool partialUpdate
)
71 TextureUploader::Parameters upload
= { texture
, &m_canvas
->getDevice()->accessBitmap(false), NULL
, { contentRect(), sourceRect
, destOffset
} };
73 queue
.appendPartialUpload(upload
);
75 queue
.appendFullUpload(upload
);
78 void BitmapCanvasLayerTextureUpdater::setOpaque(bool opaque
)
80 if (opaque
!= m_opaque
) {
82 m_canvasSize
= IntSize();