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

Side by Side Diff: cc/resources/ui_resource_bitmap.cc

Issue 22870016: Update the nine patch layer to use UI resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: UIResourceBitmap holds SkPixelRef* instead of uint8_t* Created 7 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/resources/ui_resource_bitmap.h" 5 #include "cc/resources/ui_resource_bitmap.h"
6 6
7 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "third_party/skia/include/core/SkBitmap.h"
8 10
9 namespace cc { 11 namespace cc {
10 12
11 scoped_refptr<UIResourceBitmap> 13 uint8_t* UIResourceBitmap::GetPixels() const {
12 UIResourceBitmap::Create(uint8_t* pixels, 14 if (!pixel_ref_)
13 UIResourceFormat format, 15 return NULL;
14 gfx::Size size) { 16 return static_cast<uint8_t*>(pixel_ref_->pixels());
15 scoped_refptr<UIResourceBitmap> ret = new UIResourceBitmap();
16 ret->pixels_ = scoped_ptr<uint8_t[]>(pixels);
17 ret->format_ = format;
18 ret->size_ = size;
19
20 return ret;
21 } 17 }
22 18
23 UIResourceBitmap::UIResourceBitmap() {} 19 void UIResourceBitmap::Create(SkPixelRef* pixel_ref,
24 UIResourceBitmap::~UIResourceBitmap() {} 20 UIResourceFormat format,
21 gfx::Size size) {
22 DCHECK(size.width() && size.height());
23 DCHECK(pixel_ref && pixel_ref->isImmutable());
24 format_ = format;
25 size_ = size;
26 pixel_ref_ = pixel_ref;
27 SkSafeRef(pixel_ref_);
28 }
29
30 UIResourceBitmap::UIResourceBitmap(SkPixelRef* pixel_ref,
31 UIResourceFormat format,
32 gfx::Size size) {
33 Create(pixel_ref, format, size);
34 }
35
36 UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) {
37 DCHECK_EQ(skbitmap.config(), SkBitmap::kARGB_8888_Config);
aelias_OOO_until_Jul13 2013/09/06 04:17:37 Please also DCHECK(skbitmap.width(), skbitmap.rowB
powei 2013/09/10 00:42:44 Done.
38 SkPixelRef* pixel_ref = NULL;
39 SkBitmap skbitmap_copy;
40 if (skbitmap.isImmutable()) {
41 pixel_ref = skbitmap.pixelRef();
42 } else {
43 skbitmap.copyTo(&skbitmap_copy, skbitmap.config());
aelias_OOO_until_Jul13 2013/09/06 04:17:37 Please DCHECK that the SkBitmap is immutable inste
powei 2013/09/10 00:42:44 Done.
44 skbitmap_copy.setImmutable();
45 pixel_ref = skbitmap_copy.pixelRef();
46 }
47
48 Create(pixel_ref,
49 UIResourceBitmap::RGBA8,
50 gfx::Size(skbitmap.width(), skbitmap.height()));
51 }
52
53 UIResourceBitmap::UIResourceBitmap(const UIResourceBitmap& src)
54 : pixel_ref_(NULL), format_(INVALID_FORMAT), size_(gfx::Size()) {
55 (*this) = src;
56 }
57
58 UIResourceBitmap& UIResourceBitmap::operator=(const UIResourceBitmap& src) {
59 SkSafeUnref(pixel_ref_);
60
61 pixel_ref_ = src.pixel_ref_;
62 format_ = src.format_;
63 size_ = src.size_;
64
65 SkSafeRef(pixel_ref_);
66 return *this;
67 }
68
69 UIResourceBitmap::UIResourceBitmap()
70 : pixel_ref_(NULL), format_(INVALID_FORMAT), size_(gfx::Size()) {
71 }
72
73 UIResourceBitmap::~UIResourceBitmap() {
74 SkSafeUnref(pixel_ref_);
75 }
25 76
26 } // namespace cc 77 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698