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

Side by Side Diff: skia/ext/SkFontHost_fontconfig.cpp

Issue 8800017: Change SkFileDescriptorStream to handle failure to open the file descriptor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 /* libs/graphics/ports/SkFontHost_fontconfig.cpp 1 /* libs/graphics/ports/SkFontHost_fontconfig.cpp
2 ** 2 **
3 ** Copyright 2008, Google Inc. 3 ** Copyright 2008, Google Inc.
4 ** 4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License. 6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at 7 ** You may obtain a copy of the License at
8 ** 8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** http://www.apache.org/licenses/LICENSE-2.0
10 ** 10 **
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 return 0; 236 return 0;
237 } 237 }
238 238
239 /////////////////////////////////////////////////////////////////////////////// 239 ///////////////////////////////////////////////////////////////////////////////
240 240
241 class SkFileDescriptorStream : public SkStream { 241 class SkFileDescriptorStream : public SkStream {
242 public: 242 public:
243 SkFileDescriptorStream(int fd) { 243 SkFileDescriptorStream(int fd) {
244 memory_ = NULL; 244 memory_ = NULL;
245 offset_ = 0; 245 offset_ = 0;
246 length_ = 0;
bungeman-skia 2011/12/05 21:02:45 This is following the existing convention, but sho
246 247
247 struct stat st; 248 struct stat st;
248 if (fstat(fd, &st)) 249 if (fstat(fd, &st))
249 return; 250 return;
250 251
251 void* memory = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); 252 void* memory = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
252 close(fd); 253 close(fd);
253 if (memory == MAP_FAILED) 254 if (memory == MAP_FAILED)
254 return; 255 return;
255 256
(...skipping 10 matching lines...) Expand all
266 return true; 267 return true;
267 } 268 }
268 269
269 // SkStream implementation. 270 // SkStream implementation.
270 virtual size_t read(void* buffer, size_t size) { 271 virtual size_t read(void* buffer, size_t size) {
271 if (!buffer && !size) { 272 if (!buffer && !size) {
272 // This is request for the length of the stream. 273 // This is request for the length of the stream.
273 return length_; 274 return length_;
274 } 275 }
275 276
276 if (!buffer) {
277 // This is a request to skip bytes.
278 if (offset_ + size < offset_)
279 return offset_;
280 offset_ += size;
281 if (offset_ > length_)
282 offset_ = length_;
283 return offset_;
284 }
285
286 size_t remaining = length_ - offset_; 277 size_t remaining = length_ - offset_;
287 if (size > remaining) 278 if (size > remaining)
288 size = remaining; 279 size = remaining;
289 memcpy(buffer, memory_ + offset_, size); 280 if (buffer)
281 memcpy(buffer, memory_ + offset_, size);
282
290 offset_ += size; 283 offset_ += size;
291 return size; 284 return size;
292 } 285 }
293 286
294 virtual const void* getMemoryBase() { 287 virtual const void* getMemoryBase() {
295 return memory_; 288 return memory_;
296 } 289 }
297 290
298 private: 291 private:
299 const uint8_t* memory_; 292 const uint8_t* memory_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 if (!path) 336 if (!path)
344 return 1; 337 return 1;
345 } 338 }
346 339
347 if (path) 340 if (path)
348 SkASSERT(!"SkFontHost::GetFileName does not support the font path " 341 SkASSERT(!"SkFontHost::GetFileName does not support the font path "
349 "retrieval."); 342 "retrieval.");
350 343
351 return 0; 344 return 0;
352 } 345 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698