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

Side by Side Diff: src/utils/win/SkDWriteFontFileStream.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 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/utils/win/SkDWrite.cpp ('k') | src/utils/win/SkDWriteGeometrySink.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 2012 Google Inc. 2 * Copyright 2012 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 "SkTypes.h" 8 #include "SkTypes.h"
9 #include "SkDWriteFontFileStream.h" 9 #include "SkDWriteFontFileStream.h"
10 #include "SkHRESULT.h" 10 #include "SkHRESULT.h"
11 #include "SkTemplates.h" 11 #include "SkTemplates.h"
12 #include "SkTFitsIn.h" 12 #include "SkTFitsIn.h"
13 #include "SkTScopedComPtr.h" 13 #include "SkTScopedComPtr.h"
14 14
15 #include <dwrite.h> 15 #include <dwrite.h>
16 16
17 /////////////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////////////
18 // SkIDWriteFontFileStream 18 // SkIDWriteFontFileStream
19 19
20 SkDWriteFontFileStream::SkDWriteFontFileStream(IDWriteFontFileStream* fontFileSt ream) 20 SkDWriteFontFileStream::SkDWriteFontFileStream(IDWriteFontFileStream* fontFileSt ream)
21 : fFontFileStream(SkRefComPtr(fontFileStream)) 21 : fFontFileStream(SkRefComPtr(fontFileStream))
22 , fPos(0) 22 , fPos(0)
23 , fLockedMemory(NULL) 23 , fLockedMemory(nullptr)
24 , fFragmentLock(NULL) { 24 , fFragmentLock(nullptr) {
25 } 25 }
26 26
27 SkDWriteFontFileStream::~SkDWriteFontFileStream() { 27 SkDWriteFontFileStream::~SkDWriteFontFileStream() {
28 if (fFragmentLock) { 28 if (fFragmentLock) {
29 fFontFileStream->ReleaseFileFragment(fFragmentLock); 29 fFontFileStream->ReleaseFileFragment(fFragmentLock);
30 } 30 }
31 } 31 }
32 32
33 size_t SkDWriteFontFileStream::read(void* buffer, size_t size) { 33 size_t SkDWriteFontFileStream::read(void* buffer, size_t size) {
34 HRESULT hr = S_OK; 34 HRESULT hr = S_OK;
35 35
36 if (NULL == buffer) { 36 if (nullptr == buffer) {
37 size_t fileSize = this->getLength(); 37 size_t fileSize = this->getLength();
38 38
39 if (fPos + size > fileSize) { 39 if (fPos + size > fileSize) {
40 size_t skipped = fileSize - fPos; 40 size_t skipped = fileSize - fPos;
41 fPos = fileSize; 41 fPos = fileSize;
42 return skipped; 42 return skipped;
43 } else { 43 } else {
44 fPos += size; 44 fPos += size;
45 return size; 45 return size;
46 } 46 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return fLockedMemory; 130 return fLockedMemory;
131 } 131 }
132 132
133 /////////////////////////////////////////////////////////////////////////////// 133 ///////////////////////////////////////////////////////////////////////////////
134 // SkIDWriteFontFileStreamWrapper 134 // SkIDWriteFontFileStreamWrapper
135 135
136 HRESULT SkDWriteFontFileStreamWrapper::Create(SkStreamAsset* stream, 136 HRESULT SkDWriteFontFileStreamWrapper::Create(SkStreamAsset* stream,
137 SkDWriteFontFileStreamWrapper** st reamFontFileStream) 137 SkDWriteFontFileStreamWrapper** st reamFontFileStream)
138 { 138 {
139 *streamFontFileStream = new SkDWriteFontFileStreamWrapper(stream); 139 *streamFontFileStream = new SkDWriteFontFileStreamWrapper(stream);
140 if (NULL == streamFontFileStream) { 140 if (nullptr == streamFontFileStream) {
141 return E_OUTOFMEMORY; 141 return E_OUTOFMEMORY;
142 } 142 }
143 return S_OK; 143 return S_OK;
144 } 144 }
145 145
146 SkDWriteFontFileStreamWrapper::SkDWriteFontFileStreamWrapper(SkStreamAsset* stre am) 146 SkDWriteFontFileStreamWrapper::SkDWriteFontFileStreamWrapper(SkStreamAsset* stre am)
147 : fRefCount(1), fStream(stream) { 147 : fRefCount(1), fStream(stream) {
148 } 148 }
149 149
150 HRESULT STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::QueryInterface(REFIID i id, void** ppvObject) { 150 HRESULT STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::QueryInterface(REFIID i id, void** ppvObject) {
151 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileStream)) { 151 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileStream)) {
152 *ppvObject = this; 152 *ppvObject = this;
153 AddRef(); 153 AddRef();
154 return S_OK; 154 return S_OK;
155 } else { 155 } else {
156 *ppvObject = NULL; 156 *ppvObject = nullptr;
157 return E_NOINTERFACE; 157 return E_NOINTERFACE;
158 } 158 }
159 } 159 }
160 160
161 ULONG STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::AddRef() { 161 ULONG STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::AddRef() {
162 return InterlockedIncrement(&fRefCount); 162 return InterlockedIncrement(&fRefCount);
163 } 163 }
164 164
165 ULONG STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::Release() { 165 ULONG STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::Release() {
166 ULONG newCount = InterlockedDecrement(&fRefCount); 166 ULONG newCount = InterlockedDecrement(&fRefCount);
167 if (0 == newCount) { 167 if (0 == newCount) {
168 delete this; 168 delete this;
169 } 169 }
170 return newCount; 170 return newCount;
171 } 171 }
172 172
173 HRESULT STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::ReadFileFragment( 173 HRESULT STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::ReadFileFragment(
174 void const** fragmentStart, 174 void const** fragmentStart,
175 UINT64 fileOffset, 175 UINT64 fileOffset,
176 UINT64 fragmentSize, 176 UINT64 fragmentSize,
177 void** fragmentContext) 177 void** fragmentContext)
178 { 178 {
179 // The loader is responsible for doing a bounds check. 179 // The loader is responsible for doing a bounds check.
180 UINT64 fileSize; 180 UINT64 fileSize;
181 this->GetFileSize(&fileSize); 181 this->GetFileSize(&fileSize);
182 if (fileOffset > fileSize || fragmentSize > fileSize - fileOffset) { 182 if (fileOffset > fileSize || fragmentSize > fileSize - fileOffset) {
183 *fragmentStart = NULL; 183 *fragmentStart = nullptr;
184 *fragmentContext = NULL; 184 *fragmentContext = nullptr;
185 return E_FAIL; 185 return E_FAIL;
186 } 186 }
187 187
188 if (!SkTFitsIn<size_t>(fileOffset + fragmentSize)) { 188 if (!SkTFitsIn<size_t>(fileOffset + fragmentSize)) {
189 return E_FAIL; 189 return E_FAIL;
190 } 190 }
191 191
192 const void* data = fStream->getMemoryBase(); 192 const void* data = fStream->getMemoryBase();
193 if (data) { 193 if (data) {
194 *fragmentStart = static_cast<BYTE const*>(data) + static_cast<size_t>(fi leOffset); 194 *fragmentStart = static_cast<BYTE const*>(data) + static_cast<size_t>(fi leOffset);
195 *fragmentContext = NULL; 195 *fragmentContext = nullptr;
196 196
197 } else { 197 } else {
198 // May be called from multiple threads. 198 // May be called from multiple threads.
199 SkAutoMutexAcquire ama(fStreamMutex); 199 SkAutoMutexAcquire ama(fStreamMutex);
200 200
201 *fragmentStart = NULL; 201 *fragmentStart = nullptr;
202 *fragmentContext = NULL; 202 *fragmentContext = nullptr;
203 203
204 if (!fStream->seek(static_cast<size_t>(fileOffset))) { 204 if (!fStream->seek(static_cast<size_t>(fileOffset))) {
205 return E_FAIL; 205 return E_FAIL;
206 } 206 }
207 SkAutoTMalloc<uint8_t> streamData(static_cast<size_t>(fragmentSize)); 207 SkAutoTMalloc<uint8_t> streamData(static_cast<size_t>(fragmentSize));
208 if (fStream->read(streamData.get(), static_cast<size_t>(fragmentSize)) ! = fragmentSize) { 208 if (fStream->read(streamData.get(), static_cast<size_t>(fragmentSize)) ! = fragmentSize) {
209 return E_FAIL; 209 return E_FAIL;
210 } 210 }
211 211
212 *fragmentStart = streamData.get(); 212 *fragmentStart = streamData.get();
213 *fragmentContext = streamData.detach(); 213 *fragmentContext = streamData.detach();
214 } 214 }
215 return S_OK; 215 return S_OK;
216 } 216 }
217 217
218 void STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::ReleaseFileFragment(void* fragmentContext) { 218 void STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::ReleaseFileFragment(void* fragmentContext) {
219 sk_free(fragmentContext); 219 sk_free(fragmentContext);
220 } 220 }
221 221
222 HRESULT STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::GetFileSize(UINT64* fil eSize) { 222 HRESULT STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::GetFileSize(UINT64* fil eSize) {
223 *fileSize = fStream->getLength(); 223 *fileSize = fStream->getLength();
224 return S_OK; 224 return S_OK;
225 } 225 }
226 226
227 HRESULT STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::GetLastWriteTime(UINT64 * lastWriteTime) { 227 HRESULT STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::GetLastWriteTime(UINT64 * lastWriteTime) {
228 // The concept of last write time does not apply to this loader. 228 // The concept of last write time does not apply to this loader.
229 *lastWriteTime = 0; 229 *lastWriteTime = 0;
230 return E_NOTIMPL; 230 return E_NOTIMPL;
231 } 231 }
OLDNEW
« no previous file with comments | « src/utils/win/SkDWrite.cpp ('k') | src/utils/win/SkDWriteGeometrySink.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698