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

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

Issue 1812273003: Eliminate copies of encoded image data (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 /* 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 20 matching lines...) Expand all
31 #include "platform/graphics/PictureSnapshot.h" 31 #include "platform/graphics/PictureSnapshot.h"
32 32
33 #include "platform/geometry/IntSize.h" 33 #include "platform/geometry/IntSize.h"
34 #include "platform/graphics/ImageBuffer.h" 34 #include "platform/graphics/ImageBuffer.h"
35 #include "platform/graphics/LoggingCanvas.h" 35 #include "platform/graphics/LoggingCanvas.h"
36 #include "platform/graphics/ProfilingCanvas.h" 36 #include "platform/graphics/ProfilingCanvas.h"
37 #include "platform/graphics/ReplayingCanvas.h" 37 #include "platform/graphics/ReplayingCanvas.h"
38 #include "platform/graphics/skia/ImagePixelLocker.h" 38 #include "platform/graphics/skia/ImagePixelLocker.h"
39 #include "platform/image-decoders/ImageDecoder.h" 39 #include "platform/image-decoders/ImageDecoder.h"
40 #include "platform/image-decoders/ImageFrame.h" 40 #include "platform/image-decoders/ImageFrame.h"
41 #include "platform/image-decoders/SkDataSegmentReader.h"
scroggo_chromium 2016/03/22 20:18:42 I'm not sure the proper way to name this, since it
Peter Kasting 2016/03/23 02:42:58 I think DataSegmentReader is still readable enough
f(malita) 2016/03/23 16:41:58 I would normally use SkiaDataSegmentReader to clar
scroggo_chromium 2016/03/24 13:59:45 How did you choose between DataSegmentReader and S
Peter Kasting 2016/03/24 22:05:43 It sounds like that would be a bit cleaner, yes; m
scroggo_chromium 2016/03/25 01:05:10 I've left the names alone and switched to using fa
41 #include "platform/image-encoders/skia/PNGImageEncoder.h" 42 #include "platform/image-encoders/skia/PNGImageEncoder.h"
43 #include "skia/ext/refptr.h"
44 #include "third_party/skia/include/core/SkData.h"
42 #include "third_party/skia/include/core/SkImage.h" 45 #include "third_party/skia/include/core/SkImage.h"
43 #include "third_party/skia/include/core/SkPictureRecorder.h" 46 #include "third_party/skia/include/core/SkPictureRecorder.h"
44 #include "third_party/skia/include/core/SkStream.h" 47 #include "third_party/skia/include/core/SkStream.h"
45 #include "wtf/HexNumber.h" 48 #include "wtf/HexNumber.h"
46 #include "wtf/text/Base64.h" 49 #include "wtf/text/Base64.h"
47 #include "wtf/text/TextEncoding.h" 50 #include "wtf/text/TextEncoding.h"
48 51
49 namespace blink { 52 namespace blink {
50 53
51 PictureSnapshot::PictureSnapshot(PassRefPtr<const SkPicture> picture) 54 PictureSnapshot::PictureSnapshot(PassRefPtr<const SkPicture> picture)
52 : m_picture(picture) 55 : m_picture(picture)
53 { 56 {
54 } 57 }
55 58
56 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result) 59 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result)
57 { 60 {
58 RefPtr<SharedBuffer> buffer = SharedBuffer::create(static_cast<const char*>( data), length); 61 // No need to copy the data; this decodes immediately.
59 OwnPtr<ImageDecoder> imageDecoder = ImageDecoder::create(*buffer, ImageDecod er::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored); 62 skia::RefPtr<SkData> skdata = skia::AdoptRef(SkData::NewWithoutCopy(data, le ngth));
f(malita) 2016/03/23 16:41:58 RefPtr<SkData> skData = adoptRef(...);
scroggo_chromium 2016/03/24 13:59:45 Now that DataSegmentReader takes a PassRefPtr, I j
63 SkDataSegmentReader segmentReader(skdata.get());
Peter Kasting 2016/03/23 02:42:58 I think this needs to be refcounted if it's passed
scroggo_chromium 2016/03/24 13:59:45 I think this is safe since the ImageDecoder will r
64 OwnPtr<ImageDecoder> imageDecoder = ImageDecoder::create(segmentReader, Imag eDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored);
60 if (!imageDecoder) 65 if (!imageDecoder)
61 return false; 66 return false;
62 imageDecoder->setData(buffer.get(), true); 67 imageDecoder->setData(&segmentReader, true);
63 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); 68 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0);
64 if (!frame) 69 if (!frame)
65 return true; 70 return true;
66 *result = frame->getSkBitmap(); 71 *result = frame->getSkBitmap();
67 return true; 72 return true;
68 } 73 }
69 74
70 PassRefPtr<PictureSnapshot> PictureSnapshot::load(const Vector<RefPtr<TilePictur eStream>>& tiles) 75 PassRefPtr<PictureSnapshot> PictureSnapshot::load(const Vector<RefPtr<TilePictur eStream>>& tiles)
71 { 76 {
72 ASSERT(!tiles.isEmpty()); 77 ASSERT(!tiles.isEmpty());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 167
163 PassRefPtr<JSONArray> PictureSnapshot::snapshotCommandLog() const 168 PassRefPtr<JSONArray> PictureSnapshot::snapshotCommandLog() const
164 { 169 {
165 const SkIRect bounds = m_picture->cullRect().roundOut(); 170 const SkIRect bounds = m_picture->cullRect().roundOut();
166 LoggingCanvas canvas(bounds.width(), bounds.height()); 171 LoggingCanvas canvas(bounds.width(), bounds.height());
167 m_picture->playback(&canvas); 172 m_picture->playback(&canvas);
168 return canvas.log(); 173 return canvas.log();
169 } 174 }
170 175
171 } // namespace blink 176 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698