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

Side by Side Diff: src/utils/mac/SkCreateCGImageRef.cpp

Issue 2343933002: Revert of SkFontData to use smart pointers. (Closed)
Patch Set: Created 4 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/SkWhitelistTypefaces.cpp ('k') | src/utils/mac/SkStream_mac.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 "SkTypes.h" 8 #include "SkTypes.h"
9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) 9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
10 10
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 CGContextScaleCTM(cg, 1, -1); 169 CGContextScaleCTM(cg, 1, -1);
170 170
171 CGContextDrawImage(cg, r, img); 171 CGContextDrawImage(cg, r, img);
172 172
173 CGContextRestoreGState(cg); 173 CGContextRestoreGState(cg);
174 174
175 CGImageRelease(img); 175 CGImageRelease(img);
176 } 176 }
177 } 177 }
178 178
179 ///////////////////////////////////////////////////////////////////////////////
180
181 #include "SkStream.h"
182
183 class SkAutoPDFRelease {
184 public:
185 SkAutoPDFRelease(CGPDFDocumentRef doc) : fDoc(doc) {}
186 ~SkAutoPDFRelease() {
187 if (fDoc) {
188 CGPDFDocumentRelease(fDoc);
189 }
190 }
191 private:
192 CGPDFDocumentRef fDoc;
193 };
194 #define SkAutoPDFRelease(...) SK_REQUIRE_LOCAL_VAR(SkAutoPDFRelease)
195
196 bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output) {
197 CGDataProviderRef data = SkCreateDataProviderFromStream(stream);
198 if (nullptr == data) {
199 return false;
200 }
201
202 CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(data);
203 CGDataProviderRelease(data);
204 if (nullptr == pdf) {
205 return false;
206 }
207 SkAutoPDFRelease releaseMe(pdf);
208
209 CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);
210 if (nullptr == page) {
211 return false;
212 }
213
214 CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
215
216 int w = (int)CGRectGetWidth(bounds);
217 int h = (int)CGRectGetHeight(bounds);
218
219 SkBitmap bitmap;
220 if (!bitmap.tryAllocN32Pixels(w, h)) {
221 return false;
222 }
223 bitmap.eraseColor(SK_ColorWHITE);
224
225 size_t bitsPerComponent;
226 CGBitmapInfo info;
227 getBitmapInfo(bitmap, &bitsPerComponent, &info, nullptr);
228
229 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
230 CGContextRef ctx = CGBitmapContextCreate(bitmap.getPixels(), w, h,
231 bitsPerComponent, bitmap.rowBytes() ,
232 cs, info);
233 CGColorSpaceRelease(cs);
234
235 if (ctx) {
236 CGContextDrawPDFPage(ctx, page);
237 CGContextRelease(ctx);
238 }
239
240 output->swap(bitmap);
241 return true;
242 }
243
179 //////////////////////////////////////////////////////////////////////////////// /////////////////// 244 //////////////////////////////////////////////////////////////////////////////// ///////////////////
180 245
181 SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, vo id* pixels, 246 SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, vo id* pixels,
182 CGImageRef image) { 247 CGImageRef image) {
183 CGBitmapInfo cg_bitmap_info = 0; 248 CGBitmapInfo cg_bitmap_info = 0;
184 size_t bitsPerComponent = 0; 249 size_t bitsPerComponent = 0;
185 switch (info.colorType()) { 250 switch (info.colorType()) {
186 case kRGBA_8888_SkColorType: 251 case kRGBA_8888_SkColorType:
187 bitsPerComponent = 8; 252 bitsPerComponent = 8;
188 cg_bitmap_info = ComputeCGAlphaInfo_RGBA(info.alphaType()); 253 cg_bitmap_info = ComputeCGAlphaInfo_RGBA(info.alphaType());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 if (SkBitmap::ComputeIsOpaque(tmp)) { 304 if (SkBitmap::ComputeIsOpaque(tmp)) {
240 tmp.setAlphaType(kOpaque_SkAlphaType); 305 tmp.setAlphaType(kOpaque_SkAlphaType);
241 } 306 }
242 } 307 }
243 308
244 *dst = tmp; 309 *dst = tmp;
245 return true; 310 return true;
246 } 311 }
247 312
248 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) 313 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
OLDNEW
« no previous file with comments | « src/utils/SkWhitelistTypefaces.cpp ('k') | src/utils/mac/SkStream_mac.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698