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

Side by Side Diff: webkit/api/src/WebImageSkia.cpp

Issue 155010: Port WebImage to CG and rework the Skia version so that WebImage just has a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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
« no previous file with comments | « webkit/api/src/WebImageCG.cpp ('k') | webkit/glue/image_decoder.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 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "WebImage.h" 32 #include "WebImage.h"
33 33
34 #include <SkBitmap.h> 34 #include "WebData.h"
35 #include "WebSize.h"
36
37 #include "ImageSourceSkia.h"
38 #include "NativeImageSkia.h"
39 #include "SharedBuffer.h"
40 #include <wtf/OwnPtr.h>
41 #include <wtf/PassRefPtr.h>
42
43 using namespace WebCore;
35 44
36 namespace WebKit { 45 namespace WebKit {
37 46
38 class WebImagePrivate : public SkBitmap { 47 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize)
39 public: 48 {
40 WebImagePrivate(const SkBitmap& bitmap) : SkBitmap(bitmap) { } 49 ImageSourceSkia source;
41 }; 50 source.setData(PassRefPtr<SharedBuffer>(data).get(), true, desiredSize);
51 if (!source.isSizeAvailable())
52 return WebImage();
53
54 OwnPtr<NativeImageSkia> frame0(source.createFrameAtIndex(0));
55 if (!frame0.get())
56 return WebImage();
57
58 return WebImage(*frame0);
59 }
42 60
43 void WebImage::reset() 61 void WebImage::reset()
44 { 62 {
45 delete m_private; 63 m_bitmap.reset();
46 m_private = 0; 64 }
65
66 void WebImage::assign(const WebImage& image)
67 {
68 m_bitmap = image.m_bitmap;
69 }
70
71 bool WebImage::isNull() const
72 {
73 return m_bitmap.isNull();
47 } 74 }
48 75
49 WebSize WebImage::size() const 76 WebSize WebImage::size() const
50 { 77 {
51 if (!m_private) 78 return WebSize(m_bitmap.width(), m_bitmap.height());
52 return WebSize();
53
54 return WebSize(m_private->width(), m_private->height());
55 }
56
57 void WebImage::assign(const WebImage& image)
58 {
59 if (m_private)
60 delete m_private;
61
62 if (image.m_private)
63 m_private = new WebImagePrivate(*image.m_private);
64 else
65 m_private = 0;
66 }
67
68 WebImage::operator SkBitmap() const
69 {
70 if (!m_private)
71 return SkBitmap();
72
73 return *m_private;
74 }
75
76 void WebImage::assign(const SkBitmap& bitmap)
77 {
78 if (m_private)
79 delete m_private;
80
81 m_private = new WebImagePrivate(bitmap);
82 }
83
84 const void* WebImage::lockPixels()
85 {
86 m_private->lockPixels();
87 return static_cast<void*>(m_private->getPixels());
88 }
89
90 void WebImage::unlockPixels()
91 {
92 m_private->unlockPixels();
93 } 79 }
94 80
95 } // namespace WebKit 81 } // namespace WebKit
OLDNEW
« no previous file with comments | « webkit/api/src/WebImageCG.cpp ('k') | webkit/glue/image_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698