Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / layers / picture_image_layer.cc
blobf9d13d7225d3a45880e3fc871b77845b04d53b8b
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.
5 #include "cc/layers/picture_image_layer.h"
7 #include "cc/layers/picture_image_layer_impl.h"
8 #include "cc/playback/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"
13 namespace cc {
15 scoped_refptr<PictureImageLayer> PictureImageLayer::Create(
16 const LayerSettings& settings) {
17 return make_scoped_refptr(new PictureImageLayer(settings));
20 PictureImageLayer::PictureImageLayer(const LayerSettings& settings)
21 : PictureLayer(settings, this) {
24 PictureImageLayer::~PictureImageLayer() {
25 ClearClient();
28 scoped_ptr<LayerImpl> PictureImageLayer::CreateLayerImpl(
29 LayerTreeImpl* tree_impl) {
30 return PictureImageLayerImpl::Create(tree_impl, id(), is_mask());
33 bool PictureImageLayer::HasDrawableContent() const {
34 return !bitmap_.isNull() && PictureLayer::HasDrawableContent();
37 void PictureImageLayer::SetBitmap(const SkBitmap& bitmap) {
38 // SetBitmap() currently gets called whenever there is any
39 // style change that affects the layer even if that change doesn't
40 // affect the actual contents of the image (e.g. a CSS animation).
41 // With this check in place we avoid unecessary texture uploads.
42 if (bitmap.pixelRef() && bitmap.pixelRef() == bitmap_.pixelRef())
43 return;
45 bitmap_ = bitmap;
46 UpdateDrawsContent(HasDrawableContent());
47 SetNeedsDisplay();
50 void PictureImageLayer::PaintContents(
51 SkCanvas* canvas,
52 const gfx::Rect& clip,
53 ContentLayerClient::PaintingControlSetting painting_control) {
54 if (!bitmap_.width() || !bitmap_.height())
55 return;
57 SkScalar content_to_layer_scale_x =
58 SkFloatToScalar(static_cast<float>(bounds().width()) / bitmap_.width());
59 SkScalar content_to_layer_scale_y =
60 SkFloatToScalar(static_cast<float>(bounds().height()) / bitmap_.height());
61 canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y);
63 // Because Android WebView resourceless software draw mode rasters directly
64 // to the root canvas, this draw must use the kSrcOver_Mode so that
65 // transparent images blend correctly.
66 canvas->drawBitmap(bitmap_, 0, 0);
69 void PictureImageLayer::PaintContentsToDisplayList(
70 DisplayItemList* display_list,
71 const gfx::Rect& clip,
72 ContentLayerClient::PaintingControlSetting painting_control) {
73 SkPictureRecorder recorder;
74 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(clip));
75 PaintContents(canvas, clip, painting_control);
77 skia::RefPtr<SkPicture> picture =
78 skia::AdoptRef(recorder.endRecordingAsPicture());
79 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>();
80 item->SetNew(picture.Pass());
83 bool PictureImageLayer::FillsBoundsCompletely() const {
84 return false;
87 } // namespace cc