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

Side by Side Diff: webkit/glue/image_decoder.cc

Issue 19535: Cleanup in webkit/glue/ (Closed)
Patch Set: Created 11 years, 10 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 | « webkit/glue/image_decoder.h ('k') | webkit/glue/resource_fetcher.h » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "config.h" 5 #include "config.h"
6 #include "webkit/glue/image_decoder.h" 6 #include "webkit/glue/image_decoder.h"
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 9
10 MSVC_PUSH_WARNING_LEVEL(0); 10 MSVC_PUSH_WARNING_LEVEL(0);
(...skipping 15 matching lines...) Expand all
26 ImageDecoder::ImageDecoder() : desired_icon_size_(0, 0) { 26 ImageDecoder::ImageDecoder() : desired_icon_size_(0, 0) {
27 } 27 }
28 28
29 ImageDecoder::ImageDecoder(const gfx::Size& desired_icon_size) 29 ImageDecoder::ImageDecoder(const gfx::Size& desired_icon_size)
30 : desired_icon_size_(desired_icon_size) { 30 : desired_icon_size_(desired_icon_size) {
31 } 31 }
32 32
33 ImageDecoder::~ImageDecoder() { 33 ImageDecoder::~ImageDecoder() {
34 } 34 }
35 35
36 SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) { 36 SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) const {
37 37
38 // What's going on here? ImageDecoder is only used by ImageResourceFetcher, 38 // What's going on here? ImageDecoder is only used by ImageResourceFetcher,
39 // which is only used (but extensively) by WebViewImpl. On the Mac we're using 39 // which is only used (but extensively) by WebViewImpl. On the Mac we're using
40 // CoreGraphics, but right now WebViewImpl uses SkBitmaps everywhere. For now, 40 // CoreGraphics, but right now WebViewImpl uses SkBitmaps everywhere. For now,
41 // this is a convenient bottleneck to convert from CGImageRefs to SkBitmaps, 41 // this is a convenient bottleneck to convert from CGImageRefs to SkBitmaps,
42 // but in the future we will need to replumb to get CGImageRefs (or whatever 42 // but in the future we will need to replumb to get CGImageRefs (or whatever
43 // the native type is) everywhere, directly. 43 // the native type is) everywhere, directly.
44 44
45 #if defined(OS_WIN) || defined(OS_LINUX) 45 #if defined(OS_WIN) || defined(OS_LINUX)
46 WebCore::ImageSourceSkia source; 46 WebCore::ImageSourceSkia source;
47 #elif defined(OS_MACOSX) 47 #elif defined(OS_MACOSX)
48 WebCore::ImageSource source; 48 WebCore::ImageSource source;
49 #endif 49 #endif
50 WTF::RefPtr<WebCore::SharedBuffer> buffer(WebCore::SharedBuffer::create( 50 WTF::RefPtr<WebCore::SharedBuffer> buffer(WebCore::SharedBuffer::create(
51 data, static_cast<int>(size))); 51 data, static_cast<int>(size)));
52 #if defined(OS_WIN) 52 #if defined(OS_WIN)
53 source.setData(buffer.get(), true, 53 source.setData(buffer.get(), true,
54 WebCore::IntSize(desired_icon_size_.width(), 54 WebCore::IntSize(desired_icon_size_.width(),
55 desired_icon_size_.height())); 55 desired_icon_size_.height()));
56 #elif defined(OS_MACOSX) 56 #elif defined(OS_MACOSX)
57 source.setData(buffer.get(), true); 57 source.setData(buffer.get(), true);
58 #endif 58 #endif
59 59
60 if (!source.isSizeAvailable()) 60 if (!source.isSizeAvailable())
61 return SkBitmap(); 61 return SkBitmap();
62 62
63 WebCore::NativeImagePtr frame0 = source.createFrameAtIndex(0); 63 WebCore::NativeImagePtr frame0 = source.createFrameAtIndex(0);
64 if (!frame0) 64 if (!frame0)
65 return SkBitmap(); 65 return SkBitmap();
66 66
67 #if defined(OS_WIN) || defined(OS_LINUX) 67 #if defined(OS_WIN) || defined(OS_LINUX)
68 return *reinterpret_cast<SkBitmap*>(frame0); 68 return *reinterpret_cast<SkBitmap*>(frame0);
69 #elif defined(OS_MACOSX) 69 #elif defined(OS_MACOSX)
70 // BitmapImage releases automatically, but we're bypassing it so we'll need 70 // BitmapImage releases automatically, but we're bypassing it so we'll need
71 // to do the releasing. 71 // to do the releasing.
72 RetainPtr<CGImageRef> image(AdoptCF, frame0); 72 RetainPtr<CGImageRef> image(AdoptCF, frame0);
73 73
74 SkBitmap result; 74 SkBitmap result;
75 result.setConfig(SkBitmap::kARGB_8888_Config, CGImageGetWidth(image.get()), 75 result.setConfig(SkBitmap::kARGB_8888_Config, CGImageGetWidth(image.get()),
76 CGImageGetHeight(image.get())); 76 CGImageGetHeight(image.get()));
77 77
78 RetainPtr<CGColorSpace> cg_color(AdoptCF, CGColorSpaceCreateDeviceRGB()); 78 RetainPtr<CGColorSpace> cg_color(AdoptCF, CGColorSpaceCreateDeviceRGB());
79 // The last parameter is a total guess. Feel free to adjust it if images draw 79 // The last parameter is a total guess. Feel free to adjust it if images draw
80 // incorrectly. TODO(avi): Verify byte ordering; it should be possible to 80 // incorrectly. TODO(avi): Verify byte ordering; it should be possible to
81 // swizzle bytes with various combinations of the byte order and alpha 81 // swizzle bytes with various combinations of the byte order and alpha
82 // constants. 82 // constants.
83 RetainPtr<CGContextRef> context(AdoptCF, CGBitmapContextCreate( 83 RetainPtr<CGContextRef> context(AdoptCF, CGBitmapContextCreate(
84 result.getPixels(), 84 result.getPixels(),
85 result.width(), 85 result.width(),
86 result.height(), 86 result.height(),
87 result.bytesPerPixel() * 8 / 4, 87 result.bytesPerPixel() * 8 / 4,
88 result.rowBytes(), 88 result.rowBytes(),
89 cg_color.get(), 89 cg_color.get(),
90 kCGImageAlphaPremultipliedFirst | 90 kCGImageAlphaPremultipliedFirst |
91 kCGBitmapByteOrder32Host)); 91 kCGBitmapByteOrder32Host));
92 CGRect rect = CGRectMake(0, 0, 92 CGRect rect = CGRectMake(0, 0,
93 CGImageGetWidth(image.get()), 93 CGImageGetWidth(image.get()),
94 CGImageGetHeight(image.get())); 94 CGImageGetHeight(image.get()));
95 CGContextDrawImage(context.get(), rect, image.get()); 95 CGContextDrawImage(context.get(), rect, image.get());
96 96
97 return result; 97 return result;
98 #endif 98 #endif
99 } 99 }
100 100
101 } // namespace webkit_glue 101 } // namespace webkit_glue
102 102
OLDNEW
« no previous file with comments | « webkit/glue/image_decoder.h ('k') | webkit/glue/resource_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698