| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 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 | 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/layers/picture_image_layer.h" | 5 #include "cc/layers/picture_image_layer.h" |
| 6 | 6 |
| 7 #include "cc/layers/picture_image_layer_impl.h" | 7 #include "cc/layers/picture_image_layer_impl.h" |
| 8 #include "cc/playback/display_item_list_settings.h" | 8 #include "cc/playback/display_item_list_settings.h" |
| 9 #include "cc/playback/drawing_display_item.h" | 9 #include "cc/playback/drawing_display_item.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 image_ = std::move(image); | 47 image_ = std::move(image); |
| 48 UpdateDrawsContent(HasDrawableContent()); | 48 UpdateDrawsContent(HasDrawableContent()); |
| 49 SetNeedsDisplay(); | 49 SetNeedsDisplay(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 gfx::Rect PictureImageLayer::PaintableRegion() { | 52 gfx::Rect PictureImageLayer::PaintableRegion() { |
| 53 return gfx::Rect(bounds()); | 53 return gfx::Rect(bounds()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList( | 56 scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList( |
| 57 const gfx::Rect& clip, | |
| 58 ContentLayerClient::PaintingControlSetting painting_control) { | 57 ContentLayerClient::PaintingControlSetting painting_control) { |
| 59 DCHECK(image_); | 58 DCHECK(image_); |
| 60 DCHECK_GT(image_->width(), 0); | 59 DCHECK_GT(image_->width(), 0); |
| 61 DCHECK_GT(image_->height(), 0); | 60 DCHECK_GT(image_->height(), 0); |
| 62 | 61 |
| 63 // Picture image layers can be used with GatherPixelRefs, so cached SkPictures | 62 // Picture image layers can be used with GatherPixelRefs, so cached SkPictures |
| 64 // are currently required. | 63 // are currently required. |
| 65 DisplayItemListSettings settings; | 64 DisplayItemListSettings settings; |
| 66 settings.use_cached_picture = true; | 65 settings.use_cached_picture = true; |
| 67 scoped_refptr<DisplayItemList> display_list = | 66 scoped_refptr<DisplayItemList> display_list = |
| 68 DisplayItemList::Create(clip, settings); | 67 DisplayItemList::Create(PaintableRegion(), settings); |
| 69 | 68 |
| 70 SkPictureRecorder recorder; | 69 SkPictureRecorder recorder; |
| 71 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(clip)); | 70 SkCanvas* canvas = |
| 71 recorder.beginRecording(gfx::RectToSkRect(PaintableRegion())); |
| 72 | 72 |
| 73 SkScalar content_to_layer_scale_x = | 73 SkScalar content_to_layer_scale_x = |
| 74 SkFloatToScalar(static_cast<float>(bounds().width()) / image_->width()); | 74 SkFloatToScalar(static_cast<float>(bounds().width()) / image_->width()); |
| 75 SkScalar content_to_layer_scale_y = | 75 SkScalar content_to_layer_scale_y = |
| 76 SkFloatToScalar(static_cast<float>(bounds().height()) / image_->height()); | 76 SkFloatToScalar(static_cast<float>(bounds().height()) / image_->height()); |
| 77 canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y); | 77 canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y); |
| 78 | 78 |
| 79 // Because Android WebView resourceless software draw mode rasters directly | 79 // Because Android WebView resourceless software draw mode rasters directly |
| 80 // to the root canvas, this draw must use the kSrcOver_Mode so that | 80 // to the root canvas, this draw must use the kSrcOver_Mode so that |
| 81 // transparent images blend correctly. | 81 // transparent images blend correctly. |
| 82 canvas->drawImage(image_.get(), 0, 0); | 82 canvas->drawImage(image_.get(), 0, 0); |
| 83 | 83 |
| 84 skia::RefPtr<SkPicture> picture = | 84 skia::RefPtr<SkPicture> picture = |
| 85 skia::AdoptRef(recorder.endRecordingAsPicture()); | 85 skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 86 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(clip); | 86 auto* item = |
| 87 display_list->CreateAndAppendItem<DrawingDisplayItem>(PaintableRegion()); |
| 87 item->SetNew(std::move(picture)); | 88 item->SetNew(std::move(picture)); |
| 88 | 89 |
| 89 display_list->Finalize(); | 90 display_list->Finalize(); |
| 90 return display_list; | 91 return display_list; |
| 91 } | 92 } |
| 92 | 93 |
| 93 bool PictureImageLayer::FillsBoundsCompletely() const { | 94 bool PictureImageLayer::FillsBoundsCompletely() const { |
| 94 return false; | 95 return false; |
| 95 } | 96 } |
| 96 | 97 |
| 97 size_t PictureImageLayer::GetApproximateUnsharedMemoryUsage() const { | 98 size_t PictureImageLayer::GetApproximateUnsharedMemoryUsage() const { |
| 98 return 0; | 99 return 0; |
| 99 } | 100 } |
| 100 | 101 |
| 101 } // namespace cc | 102 } // namespace cc |
| OLD | NEW |