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

Side by Side Diff: cc/layers/picture_image_layer.cc

Issue 1057283003: Remove parts of //cc we aren't using (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « cc/layers/picture_image_layer.h ('k') | cc/layers/picture_image_layer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2010 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/layers/picture_image_layer.h"
6
7 #include "cc/layers/picture_image_layer_impl.h"
8 #include "cc/resources/drawing_display_item.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkPictureRecorder.h"
11 #include "ui/gfx/skia_util.h"
12
13 namespace cc {
14
15 scoped_refptr<PictureImageLayer> PictureImageLayer::Create() {
16 return make_scoped_refptr(new PictureImageLayer());
17 }
18
19 PictureImageLayer::PictureImageLayer() : PictureLayer(this) {}
20
21 PictureImageLayer::~PictureImageLayer() {
22 ClearClient();
23 }
24
25 scoped_ptr<LayerImpl> PictureImageLayer::CreateLayerImpl(
26 LayerTreeImpl* tree_impl) {
27 return PictureImageLayerImpl::Create(tree_impl, id(), is_mask());
28 }
29
30 bool PictureImageLayer::HasDrawableContent() const {
31 return !bitmap_.isNull() && PictureLayer::HasDrawableContent();
32 }
33
34 void PictureImageLayer::SetBitmap(const SkBitmap& bitmap) {
35 // SetBitmap() currently gets called whenever there is any
36 // style change that affects the layer even if that change doesn't
37 // affect the actual contents of the image (e.g. a CSS animation).
38 // With this check in place we avoid unecessary texture uploads.
39 if (bitmap.pixelRef() && bitmap.pixelRef() == bitmap_.pixelRef())
40 return;
41
42 bitmap_ = bitmap;
43 UpdateDrawsContent(HasDrawableContent());
44 SetNeedsDisplay();
45 }
46
47 void PictureImageLayer::PaintContents(
48 SkCanvas* canvas,
49 const gfx::Rect& clip,
50 ContentLayerClient::PaintingControlSetting painting_control) {
51 if (!bitmap_.width() || !bitmap_.height())
52 return;
53
54 SkScalar content_to_layer_scale_x =
55 SkFloatToScalar(static_cast<float>(bounds().width()) / bitmap_.width());
56 SkScalar content_to_layer_scale_y =
57 SkFloatToScalar(static_cast<float>(bounds().height()) / bitmap_.height());
58 canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y);
59
60 // Because Android WebView resourceless software draw mode rasters directly
61 // to the root canvas, this draw must use the kSrcOver_Mode so that
62 // transparent images blend correctly.
63 canvas->drawBitmap(bitmap_, 0, 0);
64 }
65
66 scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList(
67 const gfx::Rect& clip,
68 ContentLayerClient::PaintingControlSetting painting_control) {
69 scoped_refptr<DisplayItemList> display_item_list = DisplayItemList::Create();
70
71 SkPictureRecorder recorder;
72 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(clip));
73 PaintContents(canvas, clip, painting_control);
74
75 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
76 display_item_list->AppendItem(DrawingDisplayItem::Create(picture));
77 return display_item_list;
78 }
79
80 bool PictureImageLayer::FillsBoundsCompletely() const {
81 return false;
82 }
83
84 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_image_layer.h ('k') | cc/layers/picture_image_layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698