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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkImageInfo.h" |
13 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 13 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
14 #include "third_party/skia/include/core/SkPixelRef.h" | 14 #include "third_party/skia/include/core/SkPixelRef.h" |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 namespace { | 17 namespace { |
18 | 18 |
19 UIResourceBitmap::UIResourceFormat SkColorTypeToUIResourceFormat( | 19 UIResourceBitmap::UIResourceFormat SkColorTypeToUIResourceFormat( |
20 SkColorType sk_type) { | 20 SkColorType sk_type) { |
21 UIResourceBitmap::UIResourceFormat format = UIResourceBitmap::RGBA8; | 21 UIResourceBitmap::UIResourceFormat format = UIResourceBitmap::RGBA8; |
22 switch (sk_type) { | 22 switch (sk_type) { |
(...skipping 20 matching lines...) Expand all Loading... |
43 DCHECK(pixel_ref); | 43 DCHECK(pixel_ref); |
44 DCHECK(pixel_ref->isImmutable()); | 44 DCHECK(pixel_ref->isImmutable()); |
45 format_ = format; | 45 format_ = format; |
46 size_ = size; | 46 size_ = size; |
47 pixel_ref_ = std::move(pixel_ref); | 47 pixel_ref_ = std::move(pixel_ref); |
48 | 48 |
49 // Default values for secondary parameters. | 49 // Default values for secondary parameters. |
50 opaque_ = (format == ETC1); | 50 opaque_ = (format == ETC1); |
51 } | 51 } |
52 | 52 |
| 53 void UIResourceBitmap::Draw(SkCanvas& canvas, SkPaint& paint) { |
| 54 SkBitmap bitmap; |
| 55 bitmap.setInfo(pixel_ref_.get()->info(), pixel_ref_.get()->rowBytes()); |
| 56 bitmap.setPixelRef(pixel_ref_.get()); |
| 57 canvas.drawBitmap(bitmap, 0, 0, &paint); |
| 58 canvas.flush(); |
| 59 } |
| 60 |
53 UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) { | 61 UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) { |
54 DCHECK_EQ(skbitmap.width(), skbitmap.rowBytesAsPixels()); | 62 DCHECK_EQ(skbitmap.width(), skbitmap.rowBytesAsPixels()); |
55 DCHECK(skbitmap.isImmutable()); | 63 DCHECK(skbitmap.isImmutable()); |
56 | 64 |
57 sk_sp<SkPixelRef> pixel_ref = sk_ref_sp(skbitmap.pixelRef()); | 65 sk_sp<SkPixelRef> pixel_ref = sk_ref_sp(skbitmap.pixelRef()); |
58 const SkImageInfo& info = pixel_ref->info(); | 66 const SkImageInfo& info = pixel_ref->info(); |
59 Create(std::move(pixel_ref), gfx::Size(info.width(), info.height()), | 67 Create(std::move(pixel_ref), gfx::Size(info.width(), info.height()), |
60 SkColorTypeToUIResourceFormat(skbitmap.colorType())); | 68 SkColorTypeToUIResourceFormat(skbitmap.colorType())); |
61 | 69 |
62 SetOpaque(skbitmap.isOpaque()); | 70 SetOpaque(skbitmap.isOpaque()); |
(...skipping 26 matching lines...) Expand all Loading... |
89 | 97 |
90 AutoLockUIResourceBitmap::~AutoLockUIResourceBitmap() { | 98 AutoLockUIResourceBitmap::~AutoLockUIResourceBitmap() { |
91 bitmap_.pixel_ref_->unlockPixels(); | 99 bitmap_.pixel_ref_->unlockPixels(); |
92 } | 100 } |
93 | 101 |
94 const uint8_t* AutoLockUIResourceBitmap::GetPixels() const { | 102 const uint8_t* AutoLockUIResourceBitmap::GetPixels() const { |
95 return static_cast<const uint8_t*>(bitmap_.pixel_ref_->pixels()); | 103 return static_cast<const uint8_t*>(bitmap_.pixel_ref_->pixels()); |
96 } | 104 } |
97 | 105 |
98 } // namespace cc | 106 } // namespace cc |
OLD | NEW |