Index: cc/caching_bitmap_canvas_layer_texture_updater.cc |
diff --git a/cc/caching_bitmap_canvas_layer_texture_updater.cc b/cc/caching_bitmap_canvas_layer_texture_updater.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0a6ba0692db5c786fad7b5a4d5917f64f9c1c516 |
--- /dev/null |
+++ b/cc/caching_bitmap_canvas_layer_texture_updater.cc |
@@ -0,0 +1,104 @@ |
+// Copyright 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+ |
+#if USE(ACCELERATED_COMPOSITING) |
jamesr
2012/10/02 20:57:54
no
wjmaclean
2012/10/02 21:43:46
Done.
|
+ |
+#include "caching_bitmap_canvas_layer_texture_updater.h" |
jamesr
2012/10/02 20:57:54
use full path for chromium-style includes
wjmaclean
2012/10/02 21:43:46
Done.
|
+ |
+#include "LayerPainterChromium.h" |
+#include "skia/ext/platform_canvas.h" |
+ |
+namespace cc { |
+ |
+PassRefPtr<CachingBitmapCanvasLayerTextureUpdater> |
+CachingBitmapCanvasLayerTextureUpdater::Create( |
+ PassOwnPtr<LayerPainterChromium> painter) |
+{ |
+ return adoptRef(new CachingBitmapCanvasLayerTextureUpdater(painter)); |
+} |
+ |
+CachingBitmapCanvasLayerTextureUpdater::CachingBitmapCanvasLayerTextureUpdater( |
+ PassOwnPtr<LayerPainterChromium> painter) |
+ : BitmapCanvasLayerTextureUpdater(painter), |
+ texture_ueeds_upload_(false) |
+{ |
+} |
+ |
+static bool comparePixels(void* src, |
+ void* dst, |
+ int num_rows, |
+ int row_bytes, |
+ int pixel_bytes_per_row) |
+{ |
jamesr
2012/10/02 20:57:54
if you want this to be chromium style, the { goes
wjmaclean
2012/10/02 21:43:46
Done.
|
+ if (src == dst) |
+ return true; |
+ |
+ if (!src || !dst) |
+ return false; |
+ |
+ bool pixels_match = true; |
+ |
+ unsigned char* src_row = static_cast<unsigned char*>(src); |
+ unsigned char* dst_row = static_cast<unsigned char*>(dst); |
+ for (unsigned row = 0; pixels_match && row < num_rows; |
jamesr
2012/10/02 21:02:01
we know the stride will always match for scrollbar
wjmaclean
2012/10/02 21:43:46
You mean rowBytes() = width() * bytesPerPixel() al
|
+ row++, src_row += row_bytes, dst_row += row_bytes) |
+ pixels_match &= memcmp(src_row, dst_row, pixel_bytes_per_row) == 0; |
+ |
+ return pixels_match; |
+} |
+ |
+void CachingBitmapCanvasLayerTextureUpdater::prepareToUpdate( |
+ const IntRect& content_rect, |
+ const IntSize& tile_size, |
+ float contents_width_scale, |
+ float contents_height_scale, |
+ IntRect& resulting_opaque_rect, |
+ CCRenderingStats& stats) |
+{ |
+ BitmapCanvasLayerTextureUpdater::prepareToUpdate(content_rect, |
+ tile_size, |
+ contents_width_scale, |
+ contents_height_scale, |
+ resulting_opaque_rect, |
+ stats); |
+ |
+ const SkBitmap& new_bitmap = m_canvas->getDevice()->accessBitmap(false); |
+ SkAutoLockPixels lock(new_bitmap); |
+ ASSERT(new_bitmap.bytesPerPixel() > 0); |
+ texture_ueeds_upload_ = new_bitmap.config() != cached_bitmap_.config() || |
+ new_bitmap.height() != cached_bitmap_.height() || |
+ new_bitmap.width() != cached_bitmap_.width() || |
+ !comparePixels(new_bitmap.getPixels(), |
+ cached_bitmap_.getPixels(), |
+ new_bitmap.height(), |
+ new_bitmap.rowBytes(), |
+ new_bitmap.width() * |
+ new_bitmap.bytesPerPixel()); |
+} |
+ |
+void CachingBitmapCanvasLayerTextureUpdater::updateTextureRect( |
+ CCResourceProvider* resource_provider, |
+ CCPrioritizedTexture* texture, |
+ const IntRect& source_rect, |
+ const IntSize& dest_offset) |
+{ |
+ if (texture_ueeds_upload_) { |
enne (OOO)
2012/10/02 21:07:18
style nit: just early out here.
wjmaclean
2012/10/02 21:43:46
Done.
|
+ BitmapCanvasLayerTextureUpdater::updateTextureRect( |
+ resource_provider, |
+ texture, |
+ source_rect, |
+ dest_offset); |
+ |
+ const SkBitmap& new_bitmap = m_canvas->getDevice()->accessBitmap(false); |
+ SkAutoLockPixels lock(new_bitmap); |
+ // TODO(wjmaclean): check return status here? |
+ new_bitmap.deepCopyTo(&cached_bitmap_, new_bitmap.config()); |
enne (OOO)
2012/10/02 21:07:18
Is there some Skia-specific way to just swap rathe
wjmaclean
2012/10/02 21:43:46
No, as the SkCanvas will only give me a const ref
|
+ } |
+} |
+ |
+} // namespace cc |
+ |
+#endif // USE(ACCELERATED_COMPOSITING) |