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

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

Issue 536003002: Hide fields in SkImageInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix qt Created 6 years, 3 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
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | src/core/SkPixelRef.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkMallocPixelRef.h" 8 #include "SkMallocPixelRef.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
11 #include "SkWriteBuffer.h" 11 #include "SkWriteBuffer.h"
12 12
13 // assumes ptr was allocated via sk_malloc 13 // assumes ptr was allocated via sk_malloc
14 static void sk_free_releaseproc(void* ptr, void*) { 14 static void sk_free_releaseproc(void* ptr, void*) {
15 sk_free(ptr); 15 sk_free(ptr);
16 } 16 }
17 17
18 static bool is_valid(const SkImageInfo& info, SkColorTable* ctable) { 18 static bool is_valid(const SkImageInfo& info, SkColorTable* ctable) {
19 if (info.fWidth < 0 || 19 if (info.width() < 0 || info.height() < 0 ||
20 info.fHeight < 0 || 20 (unsigned)info.colorType() > (unsigned)kLastEnum_SkColorType ||
21 (unsigned)info.fColorType > (unsigned)kLastEnum_SkColorType || 21 (unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType)
22 (unsigned)info.fAlphaType > (unsigned)kLastEnum_SkAlphaType)
23 { 22 {
24 return false; 23 return false;
25 } 24 }
26 25
27 // these seem like good checks, but currently we have (at least) tests 26 // these seem like good checks, but currently we have (at least) tests
28 // that expect the pixelref to succeed even when there is a mismatch 27 // that expect the pixelref to succeed even when there is a mismatch
29 // with colortables. fix? 28 // with colortables. fix?
30 #if 0 29 #if 0
31 if (kIndex8_SkColorType == info.fColorType && NULL == ctable) { 30 if (kIndex8_SkColorType == info.fColorType && NULL == ctable) {
32 return false; 31 return false;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return NULL; // cannot meet requested rowbytes 64 return NULL; // cannot meet requested rowbytes
66 } 65 }
67 66
68 int32_t rowBytes; 67 int32_t rowBytes;
69 if (requestedRowBytes) { 68 if (requestedRowBytes) {
70 rowBytes = SkToS32(requestedRowBytes); 69 rowBytes = SkToS32(requestedRowBytes);
71 } else { 70 } else {
72 rowBytes = minRB; 71 rowBytes = minRB;
73 } 72 }
74 73
75 int64_t bigSize = (int64_t)info.fHeight * rowBytes; 74 int64_t bigSize = (int64_t)info.height() * rowBytes;
76 if (!sk_64_isS32(bigSize)) { 75 if (!sk_64_isS32(bigSize)) {
77 return NULL; 76 return NULL;
78 } 77 }
79 78
80 size_t size = sk_64_asS32(bigSize); 79 size_t size = sk_64_asS32(bigSize);
81 SkASSERT(size >= info.getSafeSize(rowBytes)); 80 SkASSERT(size >= info.getSafeSize(rowBytes));
82 void* addr = sk_malloc_flags(size, 0); 81 void* addr = sk_malloc_flags(size, 0);
83 if (NULL == addr) { 82 if (NULL == addr) {
84 return NULL; 83 return NULL;
85 } 84 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage, 134 SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage,
136 size_t rowBytes, SkColorTable* ctable, 135 size_t rowBytes, SkColorTable* ctable,
137 bool ownsPixels) 136 bool ownsPixels)
138 : INHERITED(info) 137 : INHERITED(info)
139 , fReleaseProc(ownsPixels ? sk_free_releaseproc : NULL) 138 , fReleaseProc(ownsPixels ? sk_free_releaseproc : NULL)
140 , fReleaseProcContext(NULL) { 139 , fReleaseProcContext(NULL) {
141 // This constructor is now DEPRICATED. 140 // This constructor is now DEPRICATED.
142 SkASSERT(is_valid(info, ctable)); 141 SkASSERT(is_valid(info, ctable));
143 SkASSERT(rowBytes >= info.minRowBytes()); 142 SkASSERT(rowBytes >= info.minRowBytes());
144 143
145 if (kIndex_8_SkColorType != info.fColorType) { 144 if (kIndex_8_SkColorType != info.colorType()) {
146 ctable = NULL; 145 ctable = NULL;
147 } 146 }
148 147
149 fStorage = storage; 148 fStorage = storage;
150 fCTable = ctable; 149 fCTable = ctable;
151 fRB = rowBytes; 150 fRB = rowBytes;
152 SkSafeRef(ctable); 151 SkSafeRef(ctable);
153 152
154 this->setPreLocked(fStorage, rowBytes, fCTable); 153 this->setPreLocked(fStorage, rowBytes, fCTable);
155 } 154 }
156 155
157 SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage, 156 SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage,
158 size_t rowBytes, SkColorTable* ctable, 157 size_t rowBytes, SkColorTable* ctable,
159 SkMallocPixelRef::ReleaseProc proc, 158 SkMallocPixelRef::ReleaseProc proc,
160 void* context) 159 void* context)
161 : INHERITED(info) 160 : INHERITED(info)
162 , fReleaseProc(proc) 161 , fReleaseProc(proc)
163 , fReleaseProcContext(context) 162 , fReleaseProcContext(context)
164 { 163 {
165 SkASSERT(is_valid(info, ctable)); 164 SkASSERT(is_valid(info, ctable));
166 SkASSERT(rowBytes >= info.minRowBytes()); 165 SkASSERT(rowBytes >= info.minRowBytes());
167 166
168 if (kIndex_8_SkColorType != info.fColorType) { 167 if (kIndex_8_SkColorType != info.colorType()) {
169 ctable = NULL; 168 ctable = NULL;
170 } 169 }
171 170
172 fStorage = storage; 171 fStorage = storage;
173 fCTable = ctable; 172 fCTable = ctable;
174 fRB = rowBytes; 173 fRB = rowBytes;
175 SkSafeRef(ctable); 174 SkSafeRef(ctable);
176 175
177 this->setPreLocked(fStorage, rowBytes, fCTable); 176 this->setPreLocked(fStorage, rowBytes, fCTable);
178 } 177 }
(...skipping 20 matching lines...) Expand all
199 size_t SkMallocPixelRef::getAllocatedSizeInBytes() const { 198 size_t SkMallocPixelRef::getAllocatedSizeInBytes() const {
200 return this->info().getSafeSize(fRB); 199 return this->info().getSafeSize(fRB);
201 } 200 }
202 201
203 /////////////////////////////////////////////////////////////////////////////// 202 ///////////////////////////////////////////////////////////////////////////////
204 203
205 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, size_t rowBytes, 204 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, size_t rowBytes,
206 SkColorTable* ctable) { 205 SkColorTable* ctable) {
207 return SkMallocPixelRef::NewAllocate(info, rowBytes, ctable); 206 return SkMallocPixelRef::NewAllocate(info, rowBytes, ctable);
208 } 207 }
OLDNEW
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | src/core/SkPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698