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

Side by Side Diff: src/codec/SkRawCodec.cpp

Issue 2206633004: Move off SK_SUPPORT_LEGACY_DATA_FACTORIES. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Gotta catch 'em all. Created 4 years, 4 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 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 250
251 size_t sum; 251 size_t sum;
252 if (!safe_add_to_size_t(offset, length, &sum)) { 252 if (!safe_add_to_size_t(offset, length, &sum)) {
253 return false; 253 return false;
254 } 254 }
255 255
256 return this->bufferMoreData(sum) && fStreamBuffer.read(data, offset, len gth); 256 return this->bufferMoreData(sum) && fStreamBuffer.read(data, offset, len gth);
257 } 257 }
258 258
259 SkMemoryStream* transferBuffer(size_t offset, size_t size) override { 259 SkMemoryStream* transferBuffer(size_t offset, size_t size) override {
260 SkAutoTUnref<SkData> data(SkData::NewUninitialized(size)); 260 sk_sp<SkData> data(SkData::MakeUninitialized(size));
261 if (offset > fStreamBuffer.bytesWritten()) { 261 if (offset > fStreamBuffer.bytesWritten()) {
262 // If the offset is not buffered, read from fStream directly and ski p the buffering. 262 // If the offset is not buffered, read from fStream directly and ski p the buffering.
263 const size_t skipLength = offset - fStreamBuffer.bytesWritten(); 263 const size_t skipLength = offset - fStreamBuffer.bytesWritten();
264 if (fStream->skip(skipLength) != skipLength) { 264 if (fStream->skip(skipLength) != skipLength) {
265 return nullptr; 265 return nullptr;
266 } 266 }
267 const size_t bytesRead = fStream->read(data->writable_data(), size); 267 const size_t bytesRead = fStream->read(data->writable_data(), size);
268 if (bytesRead < size) { 268 if (bytesRead < size) {
269 data.reset(SkData::NewSubset(data.get(), 0, bytesRead)); 269 data = SkData::MakeSubset(data.get(), 0, bytesRead);
270 } 270 }
271 } else { 271 } else {
272 const size_t alreadyBuffered = SkTMin(fStreamBuffer.bytesWritten() - offset, size); 272 const size_t alreadyBuffered = SkTMin(fStreamBuffer.bytesWritten() - offset, size);
273 if (alreadyBuffered > 0 && 273 if (alreadyBuffered > 0 &&
274 !fStreamBuffer.read(data->writable_data(), offset, alreadyBuffer ed)) { 274 !fStreamBuffer.read(data->writable_data(), offset, alreadyBuffer ed)) {
275 return nullptr; 275 return nullptr;
276 } 276 }
277 277
278 const size_t remaining = size - alreadyBuffered; 278 const size_t remaining = size - alreadyBuffered;
279 if (remaining) { 279 if (remaining) {
280 auto* dst = static_cast<uint8_t*>(data->writable_data()) + alrea dyBuffered; 280 auto* dst = static_cast<uint8_t*>(data->writable_data()) + alrea dyBuffered;
281 const size_t bytesRead = fStream->read(dst, remaining); 281 const size_t bytesRead = fStream->read(dst, remaining);
282 size_t newSize; 282 size_t newSize;
283 if (bytesRead < remaining) { 283 if (bytesRead < remaining) {
284 if (!safe_add_to_size_t(alreadyBuffered, bytesRead, &newSize )) { 284 if (!safe_add_to_size_t(alreadyBuffered, bytesRead, &newSize )) {
285 return nullptr; 285 return nullptr;
286 } 286 }
287 data.reset(SkData::NewSubset(data.get(), 0, newSize)); 287 data = SkData::MakeSubset(data.get(), 0, newSize);
288 } 288 }
289 } 289 }
290 } 290 }
291 return new SkMemoryStream(data); 291 return new SkMemoryStream(data);
292 } 292 }
293 293
294 private: 294 private:
295 // Note: if the newSize == kReadToEnd (0), this function will read to the en d of stream. 295 // Note: if the newSize == kReadToEnd (0), this function will read to the en d of stream.
296 bool bufferMoreData(size_t newSize) { 296 bool bufferMoreData(size_t newSize) {
297 if (newSize == kReadToEnd) { 297 if (newSize == kReadToEnd) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 372 }
373 373
374 // This will allow read less than the requested "size", because the JPEG codec wants to 374 // This will allow read less than the requested "size", because the JPEG codec wants to
375 // handle also a partial JPEG file. 375 // handle also a partial JPEG file.
376 const size_t bytesToRead = SkTMin(sum, fStream->getLength()) - offset; 376 const size_t bytesToRead = SkTMin(sum, fStream->getLength()) - offset;
377 if (bytesToRead == 0) { 377 if (bytesToRead == 0) {
378 return nullptr; 378 return nullptr;
379 } 379 }
380 380
381 if (fStream->getMemoryBase()) { // directly copy if getMemoryBase() is available. 381 if (fStream->getMemoryBase()) { // directly copy if getMemoryBase() is available.
382 SkAutoTUnref<SkData> data(SkData::NewWithCopy( 382 sk_sp<SkData> data(SkData::MakeWithCopy(
383 static_cast<const uint8_t*>(fStream->getMemoryBase()) + offset, bytesToRead)); 383 static_cast<const uint8_t*>(fStream->getMemoryBase()) + offset, bytesToRead));
384 fStream.reset(); 384 fStream.reset();
385 return new SkMemoryStream(data); 385 return new SkMemoryStream(data);
386 } else { 386 } else {
387 SkAutoTUnref<SkData> data(SkData::NewUninitialized(bytesToRead)); 387 sk_sp<SkData> data(SkData::MakeUninitialized(bytesToRead));
388 if (!fStream->seek(offset)) { 388 if (!fStream->seek(offset)) {
389 return nullptr; 389 return nullptr;
390 } 390 }
391 const size_t bytesRead = fStream->read(data->writable_data(), bytesT oRead); 391 const size_t bytesRead = fStream->read(data->writable_data(), bytesT oRead);
392 if (bytesRead < bytesToRead) { 392 if (bytesRead < bytesToRead) {
393 data.reset(SkData::NewSubset(data.get(), 0, bytesRead)); 393 data = SkData::MakeSubset(data.get(), 0, bytesRead);
394 } 394 }
395 return new SkMemoryStream(data); 395 return new SkMemoryStream(data);
396 } 396 }
397 } 397 }
398 private: 398 private:
399 SkAutoTDelete<SkStream> fStream; 399 SkAutoTDelete<SkStream> fStream;
400 }; 400 };
401 401
402 class SkPiexStream : public ::piex::StreamInterface { 402 class SkPiexStream : public ::piex::StreamInterface {
403 public: 403 public:
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd ge / shortEdge)); 773 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd ge / shortEdge));
774 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge / shortEdge)); 774 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge / shortEdge));
775 return sizeFloor == dim || sizeCeil == dim; 775 return sizeFloor == dim || sizeCeil == dim;
776 } 776 }
777 777
778 SkRawCodec::~SkRawCodec() {} 778 SkRawCodec::~SkRawCodec() {}
779 779
780 SkRawCodec::SkRawCodec(SkDngImage* dngImage) 780 SkRawCodec::SkRawCodec(SkDngImage* dngImage)
781 : INHERITED(dngImage->width(), dngImage->height(), dngImage->getEncodedInfo( ), nullptr) 781 : INHERITED(dngImage->width(), dngImage->height(), dngImage->getEncodedInfo( ), nullptr)
782 , fDngImage(dngImage) {} 782 , fDngImage(dngImage) {}
OLDNEW
« include/core/SkData.h ('K') | « src/codec/SkIcoCodec.cpp ('k') | src/codec/SkWbmpCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698