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

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

Issue 2257513002: Refactor ImageDecoder factories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 4 years, 3 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 namespace blink { 54 namespace blink {
55 55
56 PictureSnapshot::PictureSnapshot(PassRefPtr<const SkPicture> picture) 56 PictureSnapshot::PictureSnapshot(PassRefPtr<const SkPicture> picture)
57 : m_picture(picture) 57 : m_picture(picture)
58 { 58 {
59 } 59 }
60 60
61 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result) 61 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result)
62 { 62 {
63 std::unique_ptr<ImageDecoder> imageDecoder = ImageDecoder::create(ImageDecod er::determineImageType(static_cast<const char*>(data), length), 63 // No need to copy the data; this decodes immediately.
64 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(SkData ::MakeWithoutCopy(data, length));
65 std::unique_ptr<ImageDecoder> imageDecoder = ImageDecoder::create(segmentRea der.release(), true,
64 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno red); 66 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno red);
65 if (!imageDecoder) 67 if (!imageDecoder)
66 return false; 68 return false;
67 69
68 // No need to copy the data; this decodes immediately.
69 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(SkData ::MakeWithoutCopy(data, length));
70 imageDecoder->setData(segmentReader.release(), true);
71 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); 70 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0);
72 if (!frame) 71 if (!frame)
73 return true; 72 return true;
74 *result = frame->bitmap(); 73 *result = frame->bitmap();
75 return true; 74 return true;
76 } 75 }
77 76
78 PassRefPtr<PictureSnapshot> PictureSnapshot::load(const Vector<RefPtr<TilePictur eStream>>& tiles) 77 PassRefPtr<PictureSnapshot> PictureSnapshot::load(const Vector<RefPtr<TilePictur eStream>>& tiles)
79 { 78 {
80 ASSERT(!tiles.isEmpty()); 79 ASSERT(!tiles.isEmpty());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 175
177 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const 176 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const
178 { 177 {
179 const SkIRect bounds = m_picture->cullRect().roundOut(); 178 const SkIRect bounds = m_picture->cullRect().roundOut();
180 LoggingCanvas canvas(bounds.width(), bounds.height()); 179 LoggingCanvas canvas(bounds.width(), bounds.height());
181 m_picture->playback(&canvas); 180 m_picture->playback(&canvas);
182 return canvas.log(); 181 return canvas.log();
183 } 182 }
184 183
185 } // namespace blink 184 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698