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

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

Issue 197883017: SkColorType instead of (deprecated) SkBitmap::Config (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 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 | Annotate | Revision Log
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/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 #include "third_party/skia/include/core/SkMallocPixelRef.h" 10 #include "third_party/skia/include/core/SkMallocPixelRef.h"
(...skipping 11 matching lines...) Expand all
22 format_ = format; 22 format_ = format;
23 size_ = size; 23 size_ = size;
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.colorType(), kPMColor_SkColorType);
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 const SkImageInfo& info = pixel_ref->info(); 37 const SkImageInfo& info = pixel_ref->info();
38 Create( 38 Create(
39 pixel_ref, gfx::Size(info.fWidth, info.fHeight), UIResourceBitmap::RGBA8); 39 pixel_ref, gfx::Size(info.fWidth, info.fHeight), UIResourceBitmap::RGBA8);
40 40
41 SetOpaque(skbitmap.isOpaque()); 41 SetOpaque(skbitmap.isOpaque());
42 } 42 }
43 43
44 UIResourceBitmap::UIResourceBitmap(int width, int height, bool isOpaque) {
45 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
danakj 2014/03/25 16:13:59 alpha_type
46 SkImageInfo info = SkImageInfo::MakeN32(width, height, alphaType);
47 skia::RefPtr<SkPixelRef> pixel_ref = skia::AdoptRef(
48 SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), NULL));
49 pixel_ref->setImmutable();
50 Create(pixel_ref,
51 gfx::Size(info.width(), info.height()),
52 UIResourceBitmap::RGBA8);
53 SetOpaque(isOpaque);
54 }
55
44 UIResourceBitmap::UIResourceBitmap(const skia::RefPtr<SkPixelRef>& pixel_ref, 56 UIResourceBitmap::UIResourceBitmap(const skia::RefPtr<SkPixelRef>& pixel_ref,
45 gfx::Size size) { 57 gfx::Size size) {
46 Create(pixel_ref, size, UIResourceBitmap::ETC1); 58 Create(pixel_ref, size, UIResourceBitmap::ETC1);
47 } 59 }
48 60
49 UIResourceBitmap::~UIResourceBitmap() {} 61 UIResourceBitmap::~UIResourceBitmap() {}
50 62
51 AutoLockUIResourceBitmap::AutoLockUIResourceBitmap( 63 AutoLockUIResourceBitmap::AutoLockUIResourceBitmap(
52 const UIResourceBitmap& bitmap) : bitmap_(bitmap) { 64 const UIResourceBitmap& bitmap) : bitmap_(bitmap) {
53 bitmap_.pixel_ref_->lockPixels(); 65 bitmap_.pixel_ref_->lockPixels();
54 } 66 }
55 67
56 AutoLockUIResourceBitmap::~AutoLockUIResourceBitmap() { 68 AutoLockUIResourceBitmap::~AutoLockUIResourceBitmap() {
57 bitmap_.pixel_ref_->unlockPixels(); 69 bitmap_.pixel_ref_->unlockPixels();
58 } 70 }
59 71
60 const uint8_t* AutoLockUIResourceBitmap::GetPixels() const { 72 const uint8_t* AutoLockUIResourceBitmap::GetPixels() const {
61 return static_cast<const uint8_t*>(bitmap_.pixel_ref_->pixels()); 73 return static_cast<const uint8_t*>(bitmap_.pixel_ref_->pixels());
62 } 74 }
63 75
64 } // namespace cc 76 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698