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

Side by Side Diff: ui/gfx/android/java_bitmap.cc

Issue 545513002: tryAllocPixels returns bool, allocPixels requires success (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « skia/ext/skia_utils_mac.mm ('k') | ui/gfx/ipc/gfx_param_traits.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/android/java_bitmap.h" 5 #include "ui/gfx/android/java_bitmap.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 8
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // TODO(jdduke): Convert to DCHECK's when sufficient data has been capture for 110 // TODO(jdduke): Convert to DCHECK's when sufficient data has been capture for
111 // crbug.com/341406. 111 // crbug.com/341406.
112 CHECK_EQ(jbitmap.format(), ANDROID_BITMAP_FORMAT_RGBA_8888); 112 CHECK_EQ(jbitmap.format(), ANDROID_BITMAP_FORMAT_RGBA_8888);
113 CHECK(!jbitmap.size().IsEmpty()); 113 CHECK(!jbitmap.size().IsEmpty());
114 CHECK_GT(jbitmap.stride(), 0U); 114 CHECK_GT(jbitmap.stride(), 0U);
115 CHECK(jbitmap.pixels()); 115 CHECK(jbitmap.pixels());
116 116
117 gfx::Size src_size = jbitmap.size(); 117 gfx::Size src_size = jbitmap.size();
118 118
119 SkBitmap skbitmap; 119 SkBitmap skbitmap;
120 if (!skbitmap.allocPixels(SkImageInfo::MakeN32Premul(src_size.width(), 120 skbitmap.allocPixels(SkImageInfo::MakeN32Premul(src_size.width(),
121 src_size.height()), 121 src_size.height()),
122 jbitmap.stride())) { 122 jbitmap.stride());
123 LOG(FATAL) << " Failed to allocate bitmap of size " << src_size.width()
124 << "x" << src_size.height() << " stride=" << jbitmap.stride();
125 }
126 const void* src_pixels = jbitmap.pixels(); 123 const void* src_pixels = jbitmap.pixels();
127 void* dst_pixels = skbitmap.getPixels(); 124 void* dst_pixels = skbitmap.getPixels();
128 memcpy(dst_pixels, src_pixels, skbitmap.getSize()); 125 memcpy(dst_pixels, src_pixels, skbitmap.getSize());
129 126
130 return skbitmap; 127 return skbitmap;
131 } 128 }
132 129
133 SkColorType ConvertToSkiaColorType(jobject bitmap_config) { 130 SkColorType ConvertToSkiaColorType(jobject bitmap_config) {
134 int jbitmap_config = Java_BitmapHelper_getBitmapFormatForConfig( 131 int jbitmap_config = Java_BitmapHelper_getBitmapFormatForConfig(
135 AttachCurrentThread(), bitmap_config); 132 AttachCurrentThread(), bitmap_config);
136 switch (jbitmap_config) { 133 switch (jbitmap_config) {
137 case BITMAP_FORMAT_ALPHA_8: 134 case BITMAP_FORMAT_ALPHA_8:
138 return kAlpha_8_SkColorType; 135 return kAlpha_8_SkColorType;
139 case BITMAP_FORMAT_ARGB_4444: 136 case BITMAP_FORMAT_ARGB_4444:
140 return kARGB_4444_SkColorType; 137 return kARGB_4444_SkColorType;
141 case BITMAP_FORMAT_ARGB_8888: 138 case BITMAP_FORMAT_ARGB_8888:
142 return kN32_SkColorType; 139 return kN32_SkColorType;
143 case BITMAP_FORMAT_RGB_565: 140 case BITMAP_FORMAT_RGB_565:
144 return kRGB_565_SkColorType; 141 return kRGB_565_SkColorType;
145 case BITMAP_FORMAT_NO_CONFIG: 142 case BITMAP_FORMAT_NO_CONFIG:
146 default: 143 default:
147 return kUnknown_SkColorType; 144 return kUnknown_SkColorType;
148 } 145 }
149 } 146 }
150 147
151 } // namespace gfx 148 } // namespace gfx
OLDNEW
« no previous file with comments | « skia/ext/skia_utils_mac.mm ('k') | ui/gfx/ipc/gfx_param_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698