OLD | NEW |
---|---|
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/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "cc/resources/etc1_pixel_ref.h" | |
10 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
10 #include "third_party/skia/include/core/SkMallocPixelRef.h" | |
11 #include "third_party/skia/include/core/SkPixelRef.h" | 11 #include "third_party/skia/include/core/SkPixelRef.h" |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 | 14 |
15 void UIResourceBitmap::Create(const skia::RefPtr<SkPixelRef>& pixel_ref, | 15 void UIResourceBitmap::Create(const skia::RefPtr<SkPixelRef>& pixel_ref, |
16 UIResourceFormat format, | 16 UIResourceFormat format) { |
17 gfx::Size size) { | 17 const SkImageInfo& info = pixel_ref->info(); |
18 DCHECK(size.width()); | 18 DCHECK(info.fWidth); |
19 DCHECK(size.height()); | 19 DCHECK(info.fHeight); |
20 DCHECK(pixel_ref); | 20 DCHECK(pixel_ref); |
21 DCHECK(pixel_ref->isImmutable()); | 21 DCHECK(pixel_ref->isImmutable()); |
22 format_ = format; | 22 format_ = format; |
23 size_ = size; | 23 size_ = gfx::Size(info.fWidth, info.fHeight); |
24 pixel_ref_ = pixel_ref; | 24 pixel_ref_ = pixel_ref; |
25 | 25 |
26 // Default values for secondary parameters. | 26 // Default values for secondary parameters. |
27 wrap_mode_ = CLAMP_TO_EDGE; | 27 wrap_mode_ = CLAMP_TO_EDGE; |
28 opaque_ = (format == ETC1); | 28 opaque_ = (format == ETC1); |
29 } | 29 } |
30 | 30 |
31 UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) { | 31 UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) { |
32 DCHECK_EQ(skbitmap.config(), SkBitmap::kARGB_8888_Config); | 32 DCHECK_EQ(skbitmap.config(), SkBitmap::kARGB_8888_Config); |
33 DCHECK_EQ(skbitmap.width(), skbitmap.rowBytesAsPixels()); | 33 DCHECK_EQ(skbitmap.width(), skbitmap.rowBytesAsPixels()); |
34 DCHECK(skbitmap.isImmutable()); | 34 DCHECK(skbitmap.isImmutable()); |
35 | 35 |
36 skia::RefPtr<SkPixelRef> pixel_ref = skia::SharePtr(skbitmap.pixelRef()); | 36 skia::RefPtr<SkPixelRef> pixel_ref = skia::SharePtr(skbitmap.pixelRef()); |
37 Create(pixel_ref, | 37 Create(pixel_ref, UIResourceBitmap::RGBA8); |
38 UIResourceBitmap::RGBA8, | |
39 gfx::Size(skbitmap.width(), skbitmap.height())); | |
40 | 38 |
41 SetOpaque(skbitmap.isOpaque()); | 39 SetOpaque(skbitmap.isOpaque()); |
42 } | 40 } |
43 | 41 |
44 UIResourceBitmap::UIResourceBitmap( | 42 UIResourceBitmap::UIResourceBitmap(const SkImageInfo& info) { |
45 const skia::RefPtr<ETC1PixelRef>& etc1_pixel_ref, | 43 SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, 0, 0); |
ccameron
2014/01/15 20:10:51
nit (optional): maybe call this one pixel_ref and
enne (OOO)
2014/01/15 20:20:38
No unwrapped raw Skia pointers, please. Can you s
reed1
2014/01/15 20:46:21
Done.
reed1
2014/01/15 20:46:21
Done.
| |
46 gfx::Size size) { | 44 pr->setImmutable(); |
47 Create(etc1_pixel_ref, ETC1, size); | 45 skia::RefPtr<SkPixelRef> pixel_ref = skia::AdoptRef(pr); |
46 Create(pixel_ref, UIResourceBitmap::ETC1); | |
48 } | 47 } |
49 | 48 |
50 UIResourceBitmap::~UIResourceBitmap() {} | 49 UIResourceBitmap::~UIResourceBitmap() {} |
51 | 50 |
52 AutoLockUIResourceBitmap::AutoLockUIResourceBitmap( | 51 AutoLockUIResourceBitmap::AutoLockUIResourceBitmap( |
53 const UIResourceBitmap& bitmap) : bitmap_(bitmap) { | 52 const UIResourceBitmap& bitmap) : bitmap_(bitmap) { |
ccameron
2014/01/15 20:10:51
nit: indent 4 spaces
reed1
2014/01/15 20:46:21
Done.
| |
54 bitmap_.pixel_ref_->lockPixels(); | 53 bitmap_.pixel_ref_->lockPixels(); |
55 } | 54 } |
56 | 55 |
57 AutoLockUIResourceBitmap::~AutoLockUIResourceBitmap() { | 56 AutoLockUIResourceBitmap::~AutoLockUIResourceBitmap() { |
58 bitmap_.pixel_ref_->unlockPixels(); | 57 bitmap_.pixel_ref_->unlockPixels(); |
59 } | 58 } |
60 | 59 |
61 const uint8_t* AutoLockUIResourceBitmap::GetPixels() const { | 60 const uint8_t* AutoLockUIResourceBitmap::GetPixels() const { |
62 return static_cast<const uint8_t*>(bitmap_.pixel_ref_->pixels()); | 61 return static_cast<const uint8_t*>(bitmap_.pixel_ref_->pixels()); |
63 } | 62 } |
64 | 63 |
65 } // namespace cc | 64 } // namespace cc |
OLD | NEW |