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

Side by Side Diff: chrome/browser/android/compositor/layer/crushed_sprite_layer.cc

Issue 1939783002: Remove all uses of skia::RefPtr and stale includes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Florin's nits Created 4 years, 7 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/android/compositor/layer/crushed_sprite_layer.h" 5 #include "chrome/browser/android/compositor/layer/crushed_sprite_layer.h"
6 6
7 #include "cc/layers/layer.h" 7 #include "cc/layers/layer.h"
8 #include "cc/layers/ui_resource_layer.h" 8 #include "cc/layers/ui_resource_layer.h"
9 #include "content/public/browser/android/compositor.h" 9 #include "content/public/browser/android/compositor.h"
10 #include "third_party/skia/include/core/SkRefCnt.h"
10 #include "ui/android/resources/crushed_sprite_resource.h" 11 #include "ui/android/resources/crushed_sprite_resource.h"
11 #include "ui/android/resources/resource_manager.h" 12 #include "ui/android/resources/resource_manager.h"
12 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/skia_util.h" 14 #include "ui/gfx/skia_util.h"
14 15
15 namespace chrome { 16 namespace chrome {
16 namespace android { 17 namespace android {
17 18
18 // static 19 // static
19 scoped_refptr<CrushedSpriteLayer> CrushedSpriteLayer::Create() { 20 scoped_refptr<CrushedSpriteLayer> CrushedSpriteLayer::Create() {
(...skipping 26 matching lines...) Expand all
46 47
47 // Reset the previous_frame if the animation is being re-run. 48 // Reset the previous_frame if the animation is being re-run.
48 if (previous_frame_ > sprite_frame) { 49 if (previous_frame_ > sprite_frame) {
49 previous_frame_ = -1; 50 previous_frame_ = -1;
50 } 51 }
51 52
52 // Set up an SkCanvas backed by an SkBitmap to draw into. 53 // Set up an SkCanvas backed by an SkBitmap to draw into.
53 SkBitmap bitmap; 54 SkBitmap bitmap;
54 bitmap.allocN32Pixels(resource->GetUnscaledSpriteSize().width(), 55 bitmap.allocN32Pixels(resource->GetUnscaledSpriteSize().width(),
55 resource->GetUnscaledSpriteSize().height()); 56 resource->GetUnscaledSpriteSize().height());
56 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(new SkCanvas(bitmap)); 57 sk_sp<SkCanvas> canvas = sk_make_sp<SkCanvas>(bitmap);
57 58
58 if (previous_frame_ == -1 || 59 if (previous_frame_ == -1 ||
59 sprite_frame == resource->GetFrameCount() - 1) { 60 sprite_frame == resource->GetFrameCount() - 1) {
60 // The newly allocated pixels for the SkBitmap need to be cleared if this 61 // The newly allocated pixels for the SkBitmap need to be cleared if this
61 // is the first frame being drawn or the last frame. See crbug.com/549453. 62 // is the first frame being drawn or the last frame. See crbug.com/549453.
62 canvas->clear(SK_ColorTRANSPARENT); 63 canvas->clear(SK_ColorTRANSPARENT);
63 } 64 }
64 65
65 // If this isn't the first or last frame, draw the previous frame(s). 66 // If this isn't the first or last frame, draw the previous frame(s).
66 // Note(twellington): This assumes that the last frame in the crushed sprite 67 // Note(twellington): This assumes that the last frame in the crushed sprite
(...skipping 29 matching lines...) Expand all
96 97
97 // Update previous_frame_* variables. 98 // Update previous_frame_* variables.
98 previous_frame_bitmap_ = bitmap; 99 previous_frame_bitmap_ = bitmap;
99 previous_frame_ = sprite_frame; 100 previous_frame_ = sprite_frame;
100 } 101 }
101 } 102 }
102 103
103 void CrushedSpriteLayer::DrawRectanglesForFrame( 104 void CrushedSpriteLayer::DrawRectanglesForFrame(
104 ui::CrushedSpriteResource* resource, 105 ui::CrushedSpriteResource* resource,
105 int frame, 106 int frame,
106 skia::RefPtr<SkCanvas> canvas) { 107 sk_sp<SkCanvas> canvas) {
107 ui::CrushedSpriteResource::FrameSrcDstRects src_dst_rects = 108 ui::CrushedSpriteResource::FrameSrcDstRects src_dst_rects =
108 resource->GetRectanglesForFrame(frame); 109 resource->GetRectanglesForFrame(frame);
109 for (const auto& rect : src_dst_rects) { 110 for (const auto& rect : src_dst_rects) {
110 canvas->drawBitmapRect(resource->GetBitmap(), 111 canvas->drawBitmapRect(resource->GetBitmap(),
111 gfx::RectToSkRect(rect.first), 112 gfx::RectToSkRect(rect.first),
112 gfx::RectToSkRect(rect.second), 113 gfx::RectToSkRect(rect.second),
113 nullptr); 114 nullptr);
114 } 115 }
115 } 116 }
116 117
117 CrushedSpriteLayer::CrushedSpriteLayer() 118 CrushedSpriteLayer::CrushedSpriteLayer()
118 : layer_(cc::UIResourceLayer::Create()), 119 : layer_(cc::UIResourceLayer::Create()),
119 frame_count_(-1), 120 frame_count_(-1),
120 previous_frame_(-1) { 121 previous_frame_(-1) {
121 layer_->SetIsDrawable(true); 122 layer_->SetIsDrawable(true);
122 } 123 }
123 124
124 125
125 CrushedSpriteLayer::~CrushedSpriteLayer() { 126 CrushedSpriteLayer::~CrushedSpriteLayer() {
126 } 127 }
127 128
128 } // namespace android 129 } // namespace android
129 } // namespace chrome 130 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/android/compositor/layer/crushed_sprite_layer.h ('k') | chrome/browser/android/compositor/layer_title_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698