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

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

Issue 22870016: Update the nine patch layer to use UI resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor format change and changed initial value for fill_center_ in nine patch layer Created 7 years, 4 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
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/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "ui/gfx/android/java_bitmap.h"
8 11
9 namespace cc { 12 namespace cc {
10 13
11 scoped_refptr<UIResourceBitmap> 14 scoped_refptr<UIResourceBitmap>
12 UIResourceBitmap::Create(uint8_t* pixels, 15 UIResourceBitmap::Create(uint8_t* pixels,
13 UIResourceFormat format, 16 UIResourceFormat format,
14 gfx::Size size) { 17 gfx::Size size) {
15 scoped_refptr<UIResourceBitmap> ret = new UIResourceBitmap(); 18 scoped_refptr<UIResourceBitmap> ret = new UIResourceBitmap();
16 ret->pixels_ = scoped_ptr<uint8_t[]>(pixels); 19 ret->pixels_ = scoped_ptr<uint8_t[]>(pixels);
17 ret->format_ = format; 20 ret->format_ = format;
18 ret->size_ = size; 21 ret->size_ = size;
19 22
20 return ret; 23 return ret;
21 } 24 }
22 25
23 UIResourceBitmap::UIResourceBitmap() {} 26 UIResourceBitmap::UIResourceBitmap() {}
27
24 UIResourceBitmap::~UIResourceBitmap() {} 28 UIResourceBitmap::~UIResourceBitmap() {}
25 29
30 scoped_refptr<UIResourceBitmap> CreateUIResourceBitmapFromSkBitmap(
31 const SkBitmap& skbitmap) {
32 DCHECK_EQ(skbitmap.config(), SkBitmap::kARGB_8888_Config);
33
34 gfx::Size size(skbitmap.width(), skbitmap.height());
35 uint8_t* dst_pixels = new uint8_t[size.GetArea() * 4];
36 uint8_t* src_pixels = static_cast<uint8_t*>(skbitmap.getPixels());
37 memcpy(dst_pixels, src_pixels, size.GetArea() * 4);
38 return UIResourceBitmap::Create(dst_pixels, UIResourceBitmap::RGBA8, size);
39 }
40
41 scoped_refptr<UIResourceBitmap> CreateUIResourceBitmapFromJavaBitmap(
42 gfx::JavaBitmap& bitmap) {
43 void* src_pixels = bitmap.pixels();
44 gfx::Size size = bitmap.size();
45 uint8_t* dst_pixels = new uint8_t[size.GetArea() * 4];
46 memcpy(dst_pixels, src_pixels, size.GetArea() * 4);
47 return cc::UIResourceBitmap::Create(
48 dst_pixels, cc::UIResourceBitmap::RGBA8, size);
49 }
50
26 } // namespace cc 51 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698