Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: cc/caching_bitmap_canvas_layer_texture_updater.cc

Issue 11044003: Reduce texture uploads during scrollbar invalidations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DEPS for skia/ext access. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2012 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.
4
5 #include "config.h"
6
7 #if USE(ACCELERATED_COMPOSITING)
jamesr 2012/10/02 20:57:54 no
wjmaclean 2012/10/02 21:43:46 Done.
8
9 #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.
10
11 #include "LayerPainterChromium.h"
12 #include "skia/ext/platform_canvas.h"
13
14 namespace cc {
15
16 PassRefPtr<CachingBitmapCanvasLayerTextureUpdater>
17 CachingBitmapCanvasLayerTextureUpdater::Create(
18 PassOwnPtr<LayerPainterChromium> painter)
19 {
20 return adoptRef(new CachingBitmapCanvasLayerTextureUpdater(painter));
21 }
22
23 CachingBitmapCanvasLayerTextureUpdater::CachingBitmapCanvasLayerTextureUpdater(
24 PassOwnPtr<LayerPainterChromium> painter)
25 : BitmapCanvasLayerTextureUpdater(painter),
26 texture_ueeds_upload_(false)
27 {
28 }
29
30 static bool comparePixels(void* src,
31 void* dst,
32 int num_rows,
33 int row_bytes,
34 int pixel_bytes_per_row)
35 {
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.
36 if (src == dst)
37 return true;
38
39 if (!src || !dst)
40 return false;
41
42 bool pixels_match = true;
43
44 unsigned char* src_row = static_cast<unsigned char*>(src);
45 unsigned char* dst_row = static_cast<unsigned char*>(dst);
46 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
47 row++, src_row += row_bytes, dst_row += row_bytes)
48 pixels_match &= memcmp(src_row, dst_row, pixel_bytes_per_row) == 0;
49
50 return pixels_match;
51 }
52
53 void CachingBitmapCanvasLayerTextureUpdater::prepareToUpdate(
54 const IntRect& content_rect,
55 const IntSize& tile_size,
56 float contents_width_scale,
57 float contents_height_scale,
58 IntRect& resulting_opaque_rect,
59 CCRenderingStats& stats)
60 {
61 BitmapCanvasLayerTextureUpdater::prepareToUpdate(content_rect,
62 tile_size,
63 contents_width_scale,
64 contents_height_scale,
65 resulting_opaque_rect,
66 stats);
67
68 const SkBitmap& new_bitmap = m_canvas->getDevice()->accessBitmap(false);
69 SkAutoLockPixels lock(new_bitmap);
70 ASSERT(new_bitmap.bytesPerPixel() > 0);
71 texture_ueeds_upload_ = new_bitmap.config() != cached_bitmap_.config() ||
72 new_bitmap.height() != cached_bitmap_.height() ||
73 new_bitmap.width() != cached_bitmap_.width() ||
74 !comparePixels(new_bitmap.getPixels(),
75 cached_bitmap_.getPixels(),
76 new_bitmap.height(),
77 new_bitmap.rowBytes(),
78 new_bitmap.width() *
79 new_bitmap.bytesPerPixel());
80 }
81
82 void CachingBitmapCanvasLayerTextureUpdater::updateTextureRect(
83 CCResourceProvider* resource_provider,
84 CCPrioritizedTexture* texture,
85 const IntRect& source_rect,
86 const IntSize& dest_offset)
87 {
88 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.
89 BitmapCanvasLayerTextureUpdater::updateTextureRect(
90 resource_provider,
91 texture,
92 source_rect,
93 dest_offset);
94
95 const SkBitmap& new_bitmap = m_canvas->getDevice()->accessBitmap(false);
96 SkAutoLockPixels lock(new_bitmap);
97 // TODO(wjmaclean): check return status here?
98 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
99 }
100 }
101
102 } // namespace cc
103
104 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698