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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h

Issue 1812273003: Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Convert to PassRefPtr in ImageDecoder, helper for setData 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) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 15 matching lines...) Expand all
26 26
27 #ifndef ImageDecoder_h 27 #ifndef ImageDecoder_h
28 #define ImageDecoder_h 28 #define ImageDecoder_h
29 29
30 #include "SkColorPriv.h" 30 #include "SkColorPriv.h"
31 #include "platform/PlatformExport.h" 31 #include "platform/PlatformExport.h"
32 #include "platform/SharedBuffer.h" 32 #include "platform/SharedBuffer.h"
33 #include "platform/graphics/ImageOrientation.h" 33 #include "platform/graphics/ImageOrientation.h"
34 #include "platform/image-decoders/ImageAnimation.h" 34 #include "platform/image-decoders/ImageAnimation.h"
35 #include "platform/image-decoders/ImageFrame.h" 35 #include "platform/image-decoders/ImageFrame.h"
36 #include "platform/image-decoders/SegmentReader.h"
37 #include "platform/image-decoders/SharedBufferSegmentReader.h"
36 #include "public/platform/Platform.h" 38 #include "public/platform/Platform.h"
37 #include "wtf/Assertions.h" 39 #include "wtf/Assertions.h"
38 #include "wtf/PassOwnPtr.h" 40 #include "wtf/PassOwnPtr.h"
39 #include "wtf/RefPtr.h" 41 #include "wtf/RefPtr.h"
40 #include "wtf/Threading.h" 42 #include "wtf/Threading.h"
41 #include "wtf/Vector.h" 43 #include "wtf/Vector.h"
42 #include "wtf/text/WTFString.h" 44 #include "wtf/text/WTFString.h"
43 45
44 #if USE(QCMSLIB) 46 #if USE(QCMSLIB)
45 #include "qcms.h" 47 #include "qcms.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 , m_sizeAvailable(false) 94 , m_sizeAvailable(false)
93 , m_isAllDataReceived(false) 95 , m_isAllDataReceived(false)
94 , m_failed(false) { } 96 , m_failed(false) { }
95 97
96 virtual ~ImageDecoder() { } 98 virtual ~ImageDecoder() { }
97 99
98 // Returns a caller-owned decoder of the appropriate type. Returns 0 if 100 // Returns a caller-owned decoder of the appropriate type. Returns 0 if
99 // we can't sniff a supported type from the provided data (possibly 101 // we can't sniff a supported type from the provided data (possibly
100 // because there isn't enough data yet). 102 // because there isn't enough data yet).
101 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). 103 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes().
102 static PassOwnPtr<ImageDecoder> create(const SharedBuffer& data, AlphaOption , GammaAndColorProfileOption); 104 static PassOwnPtr<ImageDecoder> create(const char* data, size_t length, Alph aOption, GammaAndColorProfileOption);
105 static PassOwnPtr<ImageDecoder> create(const SharedBuffer&, AlphaOption, Gam maAndColorProfileOption);
106 static PassOwnPtr<ImageDecoder> create(const SegmentReader&, AlphaOption, Ga mmaAndColorProfileOption);
103 107
104 virtual String filenameExtension() const = 0; 108 virtual String filenameExtension() const = 0;
105 109
106 bool isAllDataReceived() const { return m_isAllDataReceived; } 110 bool isAllDataReceived() const { return m_isAllDataReceived; }
107 111
108 void setData(SharedBuffer* data, bool allDataReceived) 112 void setData(PassRefPtr<SegmentReader> data, bool allDataReceived)
109 { 113 {
110 if (m_failed) 114 if (m_failed)
111 return; 115 return;
112 m_data = data; 116 m_data = data;
113 m_isAllDataReceived = allDataReceived; 117 m_isAllDataReceived = allDataReceived;
114 onSetData(data); 118 onSetData(m_data.get());
115 } 119 }
116 120
117 virtual void onSetData(SharedBuffer* data) { } 121 void setData(PassRefPtr<SharedBuffer> data, bool allDataReceived)
122 {
123 setData(adoptRef(new SharedBufferSegmentReader(data)), allDataReceived);
124 }
125
126 virtual void onSetData(SegmentReader* data) { }
118 127
119 bool isSizeAvailable() 128 bool isSizeAvailable()
120 { 129 {
121 if (m_failed) 130 if (m_failed)
122 return false; 131 return false;
123 if (!m_sizeAvailable) 132 if (!m_sizeAvailable)
124 decodeSize(); 133 decodeSize();
125 return isDecodedSizeAvailable(); 134 return isDecodedSizeAvailable();
126 } 135 }
127 136
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // returns that number. 336 // returns that number.
328 virtual size_t decodeFrameCount() { return 1; } 337 virtual size_t decodeFrameCount() { return 1; }
329 338
330 // Performs any additional setup of the requested frame after it has been 339 // Performs any additional setup of the requested frame after it has been
331 // initially created, e.g. setting a duration or disposal method. 340 // initially created, e.g. setting a duration or disposal method.
332 virtual void initializeNewFrame(size_t) { } 341 virtual void initializeNewFrame(size_t) { }
333 342
334 // Decodes the requested frame. 343 // Decodes the requested frame.
335 virtual void decode(size_t) = 0; 344 virtual void decode(size_t) = 0;
336 345
337 RefPtr<SharedBuffer> m_data; // The encoded data. 346 RefPtr<SegmentReader> m_data; // The encoded data.
338 Vector<ImageFrame, 1> m_frameBufferCache; 347 Vector<ImageFrame, 1> m_frameBufferCache;
339 bool m_premultiplyAlpha; 348 bool m_premultiplyAlpha;
340 bool m_ignoreGammaAndColorProfile; 349 bool m_ignoreGammaAndColorProfile;
341 ImageOrientation m_orientation; 350 ImageOrientation m_orientation;
342 351
343 // The maximum amount of memory a decoded image should require. Ideally, 352 // The maximum amount of memory a decoded image should require. Ideally,
344 // image decoders should downsample large images to fit under this limit 353 // image decoders should downsample large images to fit under this limit
345 // (and then return the downsampled size from decodedSize()). Ignoring 354 // (and then return the downsampled size from decodedSize()). Ignoring
346 // this limit can cause excessive memory use or even crashes on low- 355 // this limit can cause excessive memory use or even crashes on low-
347 // memory devices. 356 // memory devices.
(...skipping 11 matching lines...) Expand all
359 368
360 IntSize m_size; 369 IntSize m_size;
361 bool m_sizeAvailable; 370 bool m_sizeAvailable;
362 bool m_isAllDataReceived; 371 bool m_isAllDataReceived;
363 bool m_failed; 372 bool m_failed;
364 }; 373 };
365 374
366 } // namespace blink 375 } // namespace blink
367 376
368 #endif 377 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698