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

Side by Side Diff: Source/platform/graphics/ImageBuffer.cpp

Issue 203443004: use new readPixels, as old version using Config8888 is deprecated (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: return the image buffer, even if readPixels fails Created 6 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
« no previous file with comments | « Source/platform/graphics/GraphicsContext.cpp ('k') | no next file » | 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) 2008, Google Inc. All rights reserved. 2 * Copyright (c) 2008, Google Inc. All rights reserved.
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 293
294 template <Multiply multiplied> 294 template <Multiply multiplied>
295 PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, GraphicsContext* context, const IntSize& size) 295 PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, GraphicsContext* context, const IntSize& size)
296 { 296 {
297 float area = 4.0f * rect.width() * rect.height(); 297 float area = 4.0f * rect.width() * rect.height();
298 if (area > static_cast<float>(std::numeric_limits<int>::max())) 298 if (area > static_cast<float>(std::numeric_limits<int>::max()))
299 return nullptr; 299 return nullptr;
300 300
301 RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::createUninitialized(re ct.width() * rect.height() * 4); 301 RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::createUninitialized(re ct.width() * rect.height() * 4);
302 302
303 unsigned char* data = result->data();
304
305 if (rect.x() < 0 303 if (rect.x() < 0
306 || rect.y() < 0 304 || rect.y() < 0
307 || rect.maxX() > size.width() 305 || rect.maxX() > size.width()
308 || rect.maxY() > size.height()) 306 || rect.maxY() > size.height())
309 result->zeroFill(); 307 result->zeroFill();
310 308
311 unsigned destBytesPerRow = 4 * rect.width(); 309 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
312 SkBitmap destBitmap; 310 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888 _SkColorType, alphaType);
313 destBitmap.installPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.heigh t()), data, destBytesPerRow);
314 311
315 SkCanvas::Config8888 config8888; 312 context->readPixels(info, result->data(), 4 * rect.width(), rect.x(), rect.y ());
316 if (multiplied == Premultiplied)
317 config8888 = SkCanvas::kRGBA_Premul_Config8888;
318 else
319 config8888 = SkCanvas::kRGBA_Unpremul_Config8888;
320
321 context->readPixels(&destBitmap, rect.x(), rect.y(), config8888);
322 return result.release(); 313 return result.release();
323 } 314 }
324 315
325 PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRec t& rect) const 316 PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRec t& rect) const
326 { 317 {
327 if (!isValid()) 318 if (!isValid())
328 return Uint8ClampedArray::create(rect.width() * rect.height() * 4); 319 return Uint8ClampedArray::create(rect.width() * rect.height() * 4);
329 return getImageData<Unmultiplied>(rect, context(), m_surface->size()); 320 return getImageData<Unmultiplied>(rect, context(), m_surface->size());
330 } 321 }
331 322
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) 404 if (!encodeImage(imageData, mimeType, quality, &encodedImage))
414 return "data:,"; 405 return "data:,";
415 406
416 Vector<char> base64Data; 407 Vector<char> base64Data;
417 base64Encode(encodedImage, base64Data); 408 base64Encode(encodedImage, base64Data);
418 409
419 return "data:" + mimeType + ";base64," + base64Data; 410 return "data:" + mimeType + ";base64," + base64Data;
420 } 411 }
421 412
422 } // namespace WebCore 413 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/graphics/GraphicsContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698