| 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 "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
| 10 | 10 |
| 11 namespace cc { | 11 namespace cc { |
| 12 | 12 |
| 13 void UIResourceBitmap::Create(const skia::RefPtr<SkPixelRef>& pixel_ref, | 13 void UIResourceBitmap::Create(const skia::RefPtr<SkPixelRef>& pixel_ref, |
| 14 UIResourceFormat format, | 14 UIResourceFormat format, |
| 15 UIResourceWrapMode wrap_mode, | |
| 16 gfx::Size size) { | 15 gfx::Size size) { |
| 17 DCHECK(size.width()); | 16 DCHECK(size.width()); |
| 18 DCHECK(size.height()); | 17 DCHECK(size.height()); |
| 19 DCHECK(pixel_ref); | 18 DCHECK(pixel_ref); |
| 20 DCHECK(pixel_ref->isImmutable()); | 19 DCHECK(pixel_ref->isImmutable()); |
| 21 format_ = format; | 20 format_ = format; |
| 22 wrap_mode_ = wrap_mode; | |
| 23 size_ = size; | 21 size_ = size; |
| 24 pixel_ref_ = pixel_ref; | 22 pixel_ref_ = pixel_ref; |
| 23 |
| 24 // Wrap mode defaults to CLAMP_TO_EDGE. |
| 25 wrap_mode_ = CLAMP_TO_EDGE; |
| 25 } | 26 } |
| 26 | 27 |
| 27 UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap, | 28 UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) { |
| 28 UIResourceWrapMode wrap_mode) { | |
| 29 DCHECK_EQ(skbitmap.config(), SkBitmap::kARGB_8888_Config); | 29 DCHECK_EQ(skbitmap.config(), SkBitmap::kARGB_8888_Config); |
| 30 DCHECK_EQ(skbitmap.width(), skbitmap.rowBytesAsPixels()); | 30 DCHECK_EQ(skbitmap.width(), skbitmap.rowBytesAsPixels()); |
| 31 DCHECK(skbitmap.isImmutable()); | 31 DCHECK(skbitmap.isImmutable()); |
| 32 | 32 |
| 33 skia::RefPtr<SkPixelRef> pixel_ref = skia::SharePtr(skbitmap.pixelRef()); | 33 skia::RefPtr<SkPixelRef> pixel_ref = skia::SharePtr(skbitmap.pixelRef()); |
| 34 Create(pixel_ref, | 34 Create(pixel_ref, |
| 35 UIResourceBitmap::RGBA8, | 35 UIResourceBitmap::RGBA8, |
| 36 wrap_mode, | |
| 37 gfx::Size(skbitmap.width(), skbitmap.height())); | 36 gfx::Size(skbitmap.width(), skbitmap.height())); |
| 38 } | 37 } |
| 39 | 38 |
| 39 UIResourceBitmap::UIResourceBitmap(const skia::RefPtr<SkPixelRef>& pixel_ref, |
| 40 UIResourceFormat format, |
| 41 gfx::Size size) { |
| 42 Create(pixel_ref, format, size); |
| 43 } |
| 44 |
| 40 UIResourceBitmap::~UIResourceBitmap() {} | 45 UIResourceBitmap::~UIResourceBitmap() {} |
| 41 | 46 |
| 42 AutoLockUIResourceBitmap::AutoLockUIResourceBitmap( | 47 AutoLockUIResourceBitmap::AutoLockUIResourceBitmap( |
| 43 const UIResourceBitmap& bitmap) : bitmap_(bitmap) { | 48 const UIResourceBitmap& bitmap) : bitmap_(bitmap) { |
| 44 bitmap_.pixel_ref_->lockPixels(); | 49 bitmap_.pixel_ref_->lockPixels(); |
| 45 } | 50 } |
| 46 | 51 |
| 47 AutoLockUIResourceBitmap::~AutoLockUIResourceBitmap() { | 52 AutoLockUIResourceBitmap::~AutoLockUIResourceBitmap() { |
| 48 bitmap_.pixel_ref_->unlockPixels(); | 53 bitmap_.pixel_ref_->unlockPixels(); |
| 49 } | 54 } |
| 50 | 55 |
| 51 const uint8_t* AutoLockUIResourceBitmap::GetPixels() const { | 56 const uint8_t* AutoLockUIResourceBitmap::GetPixels() const { |
| 52 return static_cast<const uint8_t*>(bitmap_.pixel_ref_->pixels()); | 57 return static_cast<const uint8_t*>(bitmap_.pixel_ref_->pixels()); |
| 53 } | 58 } |
| 54 | 59 |
| 55 } // namespace cc | 60 } // namespace cc |
| OLD | NEW |