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/resources/bitmap_skpicture_content_layer_updater.h" | |
6 | |
7 #include "base/time/time.h" | |
8 #include "cc/debug/rendering_stats_instrumentation.h" | |
9 #include "cc/resources/layer_painter.h" | |
10 #include "cc/resources/prioritized_resource.h" | |
11 #include "cc/resources/resource_update_queue.h" | |
12 #include "third_party/skia/include/core/SkCanvas.h" | |
13 | |
14 namespace cc { | |
15 | |
16 BitmapSkPictureContentLayerUpdater::Resource::Resource( | |
17 BitmapSkPictureContentLayerUpdater* updater, | |
18 scoped_ptr<PrioritizedResource> texture) | |
19 : ContentLayerUpdater::Resource(texture.Pass()), updater_(updater) {} | |
20 | |
21 void BitmapSkPictureContentLayerUpdater::Resource::Update( | |
22 ResourceUpdateQueue* queue, | |
23 const gfx::Rect& source_rect, | |
24 const gfx::Vector2d& dest_offset, | |
25 bool partial_update) { | |
26 SkAlphaType at = | |
27 updater_->layer_is_opaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | |
28 bitmap_.allocPixels(SkImageInfo::Make( | |
29 source_rect.width(), source_rect.height(), kN32_SkColorType, at)); | |
30 SkCanvas canvas(bitmap_); | |
31 updater_->PaintContentsRect(&canvas, source_rect); | |
32 | |
33 ResourceUpdate upload = ResourceUpdate::Create( | |
34 texture(), &bitmap_, source_rect, source_rect, dest_offset); | |
35 if (partial_update) | |
36 queue->AppendPartialUpload(upload); | |
37 else | |
38 queue->AppendFullUpload(upload); | |
39 } | |
40 | |
41 scoped_refptr<BitmapSkPictureContentLayerUpdater> | |
42 BitmapSkPictureContentLayerUpdater::Create( | |
43 scoped_ptr<LayerPainter> painter, | |
44 RenderingStatsInstrumentation* stats_instrumentation, | |
45 int layer_id) { | |
46 return make_scoped_refptr( | |
47 new BitmapSkPictureContentLayerUpdater(painter.Pass(), | |
48 stats_instrumentation, | |
49 layer_id)); | |
50 } | |
51 | |
52 BitmapSkPictureContentLayerUpdater::BitmapSkPictureContentLayerUpdater( | |
53 scoped_ptr<LayerPainter> painter, | |
54 RenderingStatsInstrumentation* stats_instrumentation, | |
55 int layer_id) | |
56 : SkPictureContentLayerUpdater(painter.Pass(), layer_id) { | |
57 } | |
58 | |
59 BitmapSkPictureContentLayerUpdater::~BitmapSkPictureContentLayerUpdater() {} | |
60 | |
61 scoped_ptr<LayerUpdater::Resource> | |
62 BitmapSkPictureContentLayerUpdater::CreateResource( | |
63 PrioritizedResourceManager* manager) { | |
64 return make_scoped_ptr( | |
65 new Resource(this, PrioritizedResource::Create(manager))); | |
66 } | |
67 | |
68 void BitmapSkPictureContentLayerUpdater::PaintContentsRect( | |
69 SkCanvas* canvas, | |
70 const gfx::Rect& source_rect) { | |
71 if (!canvas) | |
72 return; | |
73 // Translate the origin of content_rect to that of source_rect. | |
74 canvas->translate(paint_rect().x() - source_rect.x(), | |
75 paint_rect().y() - source_rect.y()); | |
76 DrawPicture(canvas); | |
77 } | |
78 | |
79 } // namespace cc | |
OLD | NEW |