| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/bitmap_skpicture_content_layer_updater.h" | 5 #include "cc/bitmap_skpicture_content_layer_updater.h" |
| 6 | 6 |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "cc/layer_painter.h" | 8 #include "cc/layer_painter.h" |
| 9 #include "cc/prioritized_resource.h" | 9 #include "cc/prioritized_resource.h" |
| 10 #include "cc/rendering_stats.h" | 10 #include "cc/rendering_stats.h" |
| 11 #include "cc/resource_update_queue.h" | 11 #include "cc/resource_update_queue.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "third_party/skia/include/core/SkDevice.h" | 13 #include "third_party/skia/include/core/SkDevice.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 BitmapSkPictureContentLayerUpdater::Resource::Resource(BitmapSkPictureContentLay
erUpdater* updater, scoped_ptr<PrioritizedResource> texture) | 17 BitmapSkPictureContentLayerUpdater::Resource::Resource(BitmapSkPictureContentLay
erUpdater* updater, scoped_ptr<PrioritizedResource> texture) |
| 18 : ContentLayerUpdater::Resource(texture.Pass()) | 18 : ContentLayerUpdater::Resource(texture.Pass()) |
| 19 , m_updater(updater) | 19 , m_updater(updater) |
| 20 { | 20 { |
| 21 } | 21 } |
| 22 | 22 |
| 23 void BitmapSkPictureContentLayerUpdater::Resource::update(ResourceUpdateQueue& q
ueue, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset, bool partial
Update, RenderingStats& stats) | 23 void BitmapSkPictureContentLayerUpdater::Resource::update(ResourceUpdateQueue& q
ueue, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset, bool partial
Update, RenderingStats* stats) |
| 24 { | 24 { |
| 25 m_bitmap.setConfig(SkBitmap::kARGB_8888_Config, sourceRect.width(), sourceRe
ct.height()); | 25 m_bitmap.setConfig(SkBitmap::kARGB_8888_Config, sourceRect.width(), sourceRe
ct.height()); |
| 26 m_bitmap.allocPixels(); | 26 m_bitmap.allocPixels(); |
| 27 m_bitmap.setIsOpaque(m_updater->layerIsOpaque()); | 27 m_bitmap.setIsOpaque(m_updater->layerIsOpaque()); |
| 28 SkDevice device(m_bitmap); | 28 SkDevice device(m_bitmap); |
| 29 SkCanvas canvas(&device); | 29 SkCanvas canvas(&device); |
| 30 base::TimeTicks paintBeginTime = base::TimeTicks::Now(); | 30 base::TimeTicks paintBeginTime; |
| 31 if (stats) |
| 32 paintBeginTime = base::TimeTicks::Now(); |
| 31 updater()->paintContentsRect(&canvas, sourceRect, stats); | 33 updater()->paintContentsRect(&canvas, sourceRect, stats); |
| 32 stats.totalPaintTime += base::TimeTicks::Now() - paintBeginTime; | 34 if (stats) |
| 35 stats->totalPaintTime += base::TimeTicks::Now() - paintBeginTime; |
| 33 | 36 |
| 34 ResourceUpdate upload = ResourceUpdate::Create( | 37 ResourceUpdate upload = ResourceUpdate::Create( |
| 35 texture(), &m_bitmap, sourceRect, sourceRect, destOffset); | 38 texture(), &m_bitmap, sourceRect, sourceRect, destOffset); |
| 36 if (partialUpdate) | 39 if (partialUpdate) |
| 37 queue.appendPartialUpload(upload); | 40 queue.appendPartialUpload(upload); |
| 38 else | 41 else |
| 39 queue.appendFullUpload(upload); | 42 queue.appendFullUpload(upload); |
| 40 } | 43 } |
| 41 | 44 |
| 42 scoped_refptr<BitmapSkPictureContentLayerUpdater> BitmapSkPictureContentLayerUpd
ater::create(scoped_ptr<LayerPainter> painter) | 45 scoped_refptr<BitmapSkPictureContentLayerUpdater> BitmapSkPictureContentLayerUpd
ater::create(scoped_ptr<LayerPainter> painter) |
| 43 { | 46 { |
| 44 return make_scoped_refptr(new BitmapSkPictureContentLayerUpdater(painter.Pas
s())); | 47 return make_scoped_refptr(new BitmapSkPictureContentLayerUpdater(painter.Pas
s())); |
| 45 } | 48 } |
| 46 | 49 |
| 47 BitmapSkPictureContentLayerUpdater::BitmapSkPictureContentLayerUpdater(scoped_pt
r<LayerPainter> painter) | 50 BitmapSkPictureContentLayerUpdater::BitmapSkPictureContentLayerUpdater(scoped_pt
r<LayerPainter> painter) |
| 48 : SkPictureContentLayerUpdater(painter.Pass()) | 51 : SkPictureContentLayerUpdater(painter.Pass()) |
| 49 { | 52 { |
| 50 } | 53 } |
| 51 | 54 |
| 52 BitmapSkPictureContentLayerUpdater::~BitmapSkPictureContentLayerUpdater() | 55 BitmapSkPictureContentLayerUpdater::~BitmapSkPictureContentLayerUpdater() |
| 53 { | 56 { |
| 54 } | 57 } |
| 55 | 58 |
| 56 scoped_ptr<LayerUpdater::Resource> BitmapSkPictureContentLayerUpdater::createRes
ource(PrioritizedResourceManager* manager) | 59 scoped_ptr<LayerUpdater::Resource> BitmapSkPictureContentLayerUpdater::createRes
ource(PrioritizedResourceManager* manager) |
| 57 { | 60 { |
| 58 return scoped_ptr<LayerUpdater::Resource>(new Resource(this, PrioritizedReso
urce::create(manager))); | 61 return scoped_ptr<LayerUpdater::Resource>(new Resource(this, PrioritizedReso
urce::create(manager))); |
| 59 } | 62 } |
| 60 | 63 |
| 61 void BitmapSkPictureContentLayerUpdater::paintContentsRect(SkCanvas* canvas, con
st gfx::Rect& sourceRect, RenderingStats& stats) | 64 void BitmapSkPictureContentLayerUpdater::paintContentsRect(SkCanvas* canvas, con
st gfx::Rect& sourceRect, RenderingStats* stats) |
| 62 { | 65 { |
| 63 // Translate the origin of contentRect to that of sourceRect. | 66 // Translate the origin of contentRect to that of sourceRect. |
| 64 canvas->translate(contentRect().x() - sourceRect.x(), | 67 canvas->translate(contentRect().x() - sourceRect.x(), |
| 65 contentRect().y() - sourceRect.y()); | 68 contentRect().y() - sourceRect.y()); |
| 66 base::TimeTicks rasterizeBeginTime = base::TimeTicks::Now(); | 69 base::TimeTicks rasterizeBeginTime; |
| 70 if (stats) |
| 71 rasterizeBeginTime = base::TimeTicks::Now(); |
| 67 drawPicture(canvas); | 72 drawPicture(canvas); |
| 68 stats.totalRasterizeTime += base::TimeTicks::Now() - rasterizeBeginTime; | 73 if (stats) { |
| 69 stats.totalPixelsRasterized += sourceRect.width() * sourceRect.height(); | 74 stats->totalRasterizeTime += base::TimeTicks::Now() - rasterizeBeginTime; |
| 75 stats->totalPixelsRasterized += sourceRect.width() * sourceRect.height(); |
| 76 } |
| 70 } | 77 } |
| 71 | 78 |
| 72 } // namespace cc | 79 } // namespace cc |
| OLD | NEW |