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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/skia/ImagePixelLocker.cpp

Issue 1813483002: ImagePixelLocker now manually allocates SkPixmap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "platform/graphics/skia/ImagePixelLocker.h" 5 #include "platform/graphics/skia/ImagePixelLocker.h"
6 6
7 #include "third_party/skia/include/core/SkImage.h" 7 #include "third_party/skia/include/core/SkImage.h"
8 #include "third_party/skia/include/core/SkImageInfo.h" 8 #include "third_party/skia/include/core/SkImageInfo.h"
9 9
10 namespace blink { 10 namespace blink {
(...skipping 11 matching lines...) Expand all
22 return info.alphaType() == alphaType || info.alphaType() == kOpaque_SkAlphaT ype; 22 return info.alphaType() == alphaType || info.alphaType() == kOpaque_SkAlphaT ype;
23 } 23 }
24 24
25 } // anonymous namespace 25 } // anonymous namespace
26 26
27 ImagePixelLocker::ImagePixelLocker(PassRefPtr<const SkImage> image, SkAlphaType alphaType, 27 ImagePixelLocker::ImagePixelLocker(PassRefPtr<const SkImage> image, SkAlphaType alphaType,
28 SkColorType colorType) 28 SkColorType colorType)
29 : m_image(image) 29 : m_image(image)
30 { 30 {
31 SkImageInfo info; 31 SkImageInfo info;
32 size_t imageRowBytes; 32 size_t rowBytes;
33 33
34 // If the image has in-RAM pixels and their format matches, use them directl y. 34 // If the image has in-RAM pixels and their format matches, use them directl y.
35 // TODO(fmalita): All current clients expect packed pixel rows. Maybe we co uld update them 35 // TODO(fmalita): All current clients expect packed pixel rows. Maybe we co uld update them
36 // to support arbitrary rowBytes, and relax the check below. 36 // to support arbitrary rowBytes, and relax the check below.
37 m_pixels = m_image->peekPixels(&info, &imageRowBytes); 37 m_pixels = m_image->peekPixels(&info, &rowBytes);
38 if (m_pixels 38 if (m_pixels
39 && infoIsCompatible(info, alphaType, colorType) 39 && infoIsCompatible(info, alphaType, colorType)
40 && imageRowBytes == info.minRowBytes()) { 40 && rowBytes == info.minRowBytes()) {
41 return; 41 return;
42 } 42 }
43 43
44 m_pixels = nullptr;
45
44 // No luck, we need to read the pixels into our local buffer. 46 // No luck, we need to read the pixels into our local buffer.
45 info = SkImageInfo::Make(m_image->width(), m_image->height(), colorType, alp haType); 47 info = SkImageInfo::Make(m_image->width(), m_image->height(), colorType, alp haType);
46 if (!m_pixelStorage.tryAlloc(info) || !m_image->readPixels(m_pixelStorage, 0 , 0)) { 48 rowBytes = info.minRowBytes();
47 m_pixels = nullptr; 49 size_t size = info.getSafeSize(rowBytes);
50 if (0 == size) {
51 return;
52 }
53
54 void* pixels = sk_malloc_flags(size, 0);
f(malita) 2016/03/16 19:28:29 Would it make sense to use a separate SkAutoMalloc
robertphillips 2016/03/16 19:59:10 Done.
55 if (!pixels) {
56 return;
57 }
58
59 m_pixelStorage.reset(info, pixels, rowBytes);
60
61 if (!m_image->readPixels(m_pixelStorage, 0, 0)) {
62 sk_free(pixels);
63 m_pixelStorage.reset();
48 return; 64 return;
49 } 65 }
50 66
51 m_pixels = m_pixelStorage.addr(); 67 m_pixels = m_pixelStorage.addr();
52 } 68 }
53 69
70 ImagePixelLocker::~ImagePixelLocker()
71 {
72 if (m_pixels == m_pixelStorage.addr()) {
73 // We had to make our own copy in the constructor
74 sk_free(const_cast<void*>(m_pixelStorage.addr()));
75 }
76 }
77
54 } // namespace blink 78 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698