| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "cc/bitmap_skpicture_content_layer_updater.h" | |
| 6 | |
| 7 #include "base/time.h" | |
| 8 #include "cc/debug/rendering_stats.h" | |
| 9 #include "cc/layer_painter.h" | |
| 10 #include "cc/prioritized_resource.h" | |
| 11 #include "cc/resource_update_queue.h" | |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | |
| 13 #include "third_party/skia/include/core/SkDevice.h" | |
| 14 | |
| 15 namespace cc { | |
| 16 | |
| 17 BitmapSkPictureContentLayerUpdater::Resource::Resource( | |
| 18 BitmapSkPictureContentLayerUpdater* updater, | |
| 19 scoped_ptr<PrioritizedResource> texture) | |
| 20 : ContentLayerUpdater::Resource(texture.Pass()), updater_(updater) {} | |
| 21 | |
| 22 void BitmapSkPictureContentLayerUpdater::Resource::Update( | |
| 23 ResourceUpdateQueue* queue, | |
| 24 gfx::Rect source_rect, | |
| 25 gfx::Vector2d dest_offset, | |
| 26 bool partial_update, | |
| 27 RenderingStats* stats) { | |
| 28 bitmap_.setConfig( | |
| 29 SkBitmap::kARGB_8888_Config, source_rect.width(), source_rect.height()); | |
| 30 bitmap_.allocPixels(); | |
| 31 bitmap_.setIsOpaque(updater_->layer_is_opaque()); | |
| 32 SkDevice device(bitmap_); | |
| 33 SkCanvas canvas(&device); | |
| 34 base::TimeTicks paint_begin_time; | |
| 35 if (stats) | |
| 36 paint_begin_time = base::TimeTicks::Now(); | |
| 37 updater_->PaintContentsRect(&canvas, source_rect, stats); | |
| 38 if (stats) | |
| 39 stats->totalPaintTime += base::TimeTicks::Now() - paint_begin_time; | |
| 40 | |
| 41 ResourceUpdate upload = ResourceUpdate::Create( | |
| 42 texture(), &bitmap_, source_rect, source_rect, dest_offset); | |
| 43 if (partial_update) | |
| 44 queue->appendPartialUpload(upload); | |
| 45 else | |
| 46 queue->appendFullUpload(upload); | |
| 47 } | |
| 48 | |
| 49 scoped_refptr<BitmapSkPictureContentLayerUpdater> | |
| 50 BitmapSkPictureContentLayerUpdater::Create(scoped_ptr<LayerPainter> painter) { | |
| 51 return make_scoped_refptr( | |
| 52 new BitmapSkPictureContentLayerUpdater(painter.Pass())); | |
| 53 } | |
| 54 | |
| 55 BitmapSkPictureContentLayerUpdater::BitmapSkPictureContentLayerUpdater( | |
| 56 scoped_ptr<LayerPainter> painter) | |
| 57 : SkPictureContentLayerUpdater(painter.Pass()) {} | |
| 58 | |
| 59 BitmapSkPictureContentLayerUpdater::~BitmapSkPictureContentLayerUpdater() {} | |
| 60 | |
| 61 scoped_ptr<LayerUpdater::Resource> | |
| 62 BitmapSkPictureContentLayerUpdater::CreateResource( | |
| 63 PrioritizedResourceManager* manager) { | |
| 64 return scoped_ptr<LayerUpdater::Resource>( | |
| 65 new Resource(this, PrioritizedResource::create(manager))); | |
| 66 } | |
| 67 | |
| 68 void BitmapSkPictureContentLayerUpdater::PaintContentsRect( | |
| 69 SkCanvas* canvas, | |
| 70 gfx::Rect source_rect, | |
| 71 RenderingStats* stats) { | |
| 72 // Translate the origin of content_rect to that of source_rect. | |
| 73 canvas->translate(content_rect().x() - source_rect.x(), | |
| 74 content_rect().y() - source_rect.y()); | |
| 75 base::TimeTicks rasterize_begin_time; | |
| 76 if (stats) | |
| 77 rasterize_begin_time = base::TimeTicks::Now(); | |
| 78 DrawPicture(canvas); | |
| 79 if (stats) { | |
| 80 stats->totalRasterizeTime += base::TimeTicks::Now() - rasterize_begin_time; | |
| 81 stats->totalPixelsRasterized += source_rect.width() * source_rect.height(); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 } // namespace cc | |
| OLD | NEW |