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

Side by Side Diff: src/core/SkColorTable.cpp

Issue 134163010: Refactor read and write buffers. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: original write flags were fine Created 6 years, 10 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 /* 2 /*
3 * Copyright 2009 The Android Open Source Project 3 * Copyright 2009 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkColorTable.h" 10 #include "SkColorTable.h"
11 #include "SkFlattenableBuffers.h" 11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h"
12 #include "SkStream.h" 13 #include "SkStream.h"
13 #include "SkTemplates.h" 14 #include "SkTemplates.h"
14 15
15 // As copy constructor is hidden in the class hierarchy, we need to call 16 // As copy constructor is hidden in the class hierarchy, we need to call
16 // default constructor explicitly to suppress a compiler warning. 17 // default constructor explicitly to suppress a compiler warning.
17 SkColorTable::SkColorTable(const SkColorTable& src) : INHERITED() { 18 SkColorTable::SkColorTable(const SkColorTable& src) : INHERITED() {
18 f16BitCache = NULL; 19 f16BitCache = NULL;
19 fAlphaType = src.fAlphaType; 20 fAlphaType = src.fAlphaType;
20 int count = src.count(); 21 int count = src.count();
21 fCount = SkToU16(count); 22 fCount = SkToU16(count);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 f16BitCache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t)); 77 f16BitCache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t));
77 build_16bitcache(f16BitCache, fColors, fCount); 78 build_16bitcache(f16BitCache, fColors, fCount);
78 } 79 }
79 80
80 SkDEBUGCODE(f16BitCacheLockCount += 1); 81 SkDEBUGCODE(f16BitCacheLockCount += 1);
81 return f16BitCache; 82 return f16BitCache;
82 } 83 }
83 84
84 /////////////////////////////////////////////////////////////////////////////// 85 ///////////////////////////////////////////////////////////////////////////////
85 86
86 SkColorTable::SkColorTable(SkFlattenableReadBuffer& buffer) { 87 SkColorTable::SkColorTable(SkReadBuffer& buffer) {
87 f16BitCache = NULL; 88 f16BitCache = NULL;
88 SkDEBUGCODE(fColorLockCount = 0;) 89 SkDEBUGCODE(fColorLockCount = 0;)
89 SkDEBUGCODE(f16BitCacheLockCount = 0;) 90 SkDEBUGCODE(f16BitCacheLockCount = 0;)
90 91
91 fAlphaType = SkToU8(buffer.readUInt()); 92 fAlphaType = SkToU8(buffer.readUInt());
92 fCount = buffer.getArrayCount(); 93 fCount = buffer.getArrayCount();
93 size_t allocSize = fCount * sizeof(SkPMColor); 94 size_t allocSize = fCount * sizeof(SkPMColor);
94 SkDEBUGCODE(bool success = false;) 95 SkDEBUGCODE(bool success = false;)
95 if (buffer.validateAvailable(allocSize)) { 96 if (buffer.validateAvailable(allocSize)) {
96 fColors = (SkPMColor*)sk_malloc_throw(allocSize); 97 fColors = (SkPMColor*)sk_malloc_throw(allocSize);
97 SkDEBUGCODE(success =) buffer.readColorArray(fColors, fCount); 98 SkDEBUGCODE(success =) buffer.readColorArray(fColors, fCount);
98 } else { 99 } else {
99 fCount = 0; 100 fCount = 0;
100 fColors = NULL; 101 fColors = NULL;
101 } 102 }
102 #ifdef SK_DEBUG 103 #ifdef SK_DEBUG
103 SkASSERT((unsigned)fCount <= 256); 104 SkASSERT((unsigned)fCount <= 256);
104 SkASSERT(success); 105 SkASSERT(success);
105 #endif 106 #endif
106 } 107 }
107 108
108 void SkColorTable::writeToBuffer(SkFlattenableWriteBuffer& buffer) const { 109 void SkColorTable::writeToBuffer(SkWriteBuffer& buffer) const {
109 buffer.writeUInt(fAlphaType); 110 buffer.writeUInt(fAlphaType);
110 buffer.writeColorArray(fColors, fCount); 111 buffer.writeColorArray(fColors, fCount);
111 } 112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698