diff options
author | bungeman <bungeman@google.com> | 2015-06-29 14:12:41 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-29 14:12:41 -0700 |
commit | 3fdde4e129f43b9d2f0c31a791ebe17ff06e4612 (patch) | |
tree | 1793e44158e81c69335a1ebeca86b9762c7f21f8 /src/utils | |
parent | 09b2c932d8fc6f0e1e8ab82c63df8c76f2b63a75 (diff) |
Remove old iOS porting files.
These files do not appear to be used, are unfinished, and should be
redundant with the mac porting files.
Review URL: https://codereview.chromium.org/1197963003
Diffstat (limited to 'src/utils')
-rwxr-xr-x | src/utils/ios/SkFontHost_iOS.mm | 262 | ||||
-rwxr-xr-x | src/utils/ios/SkImageDecoder_iOS.mm | 65 | ||||
-rwxr-xr-x | src/utils/ios/SkOSFile_iOS.mm | 98 | ||||
-rwxr-xr-x | src/utils/ios/SkStream_NSData.mm | 44 |
4 files changed, 0 insertions, 469 deletions
diff --git a/src/utils/ios/SkFontHost_iOS.mm b/src/utils/ios/SkFontHost_iOS.mm deleted file mode 100755 index ae75165a4e..0000000000 --- a/src/utils/ios/SkFontHost_iOS.mm +++ /dev/null @@ -1,262 +0,0 @@ -#import <UIKit/UIKit.h> - -#include "SkStream_NSData.h" -#include "SkTypeface.h" -#include "SkFontHost.h" -#include "SkThread.h" -#include "SkTemplates.h" - -enum FontDesign { - kUnknown_Design, - kSans_FontDesign, - kSerif_FontDesign, - - kIllegal_FontDesign, // never use with a real font -}; - -// returns kIllegal_FontDesign if not found -static FontDesign find_design_from_name(const char name[]) { - static const struct { - const char* fName; - FontDesign fDesign; - } gRec[] = { - { "sans-serif", kSans_FontDesign }, - { "serif", kSerif_FontDesign }, - }; - - for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { - if (!strcasecmp(name, gRec[i].fName)) { - return gRec[i].fDesign; - } - } - return kIllegal_FontDesign; -} - -struct FontRes { - const char* fName; - SkTypeface::Style fStyle; - FontDesign fDesign; -}; - -static const FontRes gFontRes[] = { - { "DroidSans", SkTypeface::kNormal, kSans_FontDesign }, - { "DroidSans", SkTypeface::kBold, kSans_FontDesign }, - { "DroidSerif-Regular", SkTypeface::kNormal, kSerif_FontDesign }, - { "DroidSerif-Bold", SkTypeface::kBold, kSerif_FontDesign }, -// { "PescaderoPro", SkTypeface::kNormal, kSerif_FontDesign }, -// { "PescaderoPro-Bold", SkTypeface::kBold, kSerif_FontDesign }, -}; -#define FONTRES_COUNT SK_ARRAY_COUNT(gFontRes) - -#define DEFAULT_INDEX_REGULAR 1 -#define DEFAULT_INDEX_BOLD 2 - -/////////////////////////////////////////////////////////////////////////////// - -class SkTypeface_Stream : public SkTypeface { -public: - SkTypeface_Stream(SkStream* stream, Style style); - virtual ~SkTypeface_Stream(); - - SkStream* refStream() { - fStream->ref(); - return fStream; - } - -private: - SkStream* fStream; -}; - -static int32_t gUniqueFontID; - -SkTypeface_Stream::SkTypeface_Stream(SkStream* stream, Style style) -: SkTypeface(style, sk_atomic_inc(&gUniqueFontID) + 1) { - fStream = stream; - fStream->ref(); -} - -SkTypeface_Stream::~SkTypeface_Stream() { - fStream->unref(); -} - -static SkTypeface_Stream* create_from_fontres(const FontRes& res) { - SkStream* stream = SkStream_NSData::CreateFromResource(res.fName, "ttf"); - SkAutoUnref aur(stream); - - return SkNEW_ARGS(SkTypeface_Stream, (stream, res.fStyle)); -} - -/////////////////////////////////////////////////////////////////////////////// - -static int compute_style_distance(SkTypeface::Style a, SkTypeface::Style b) { - int dist = 0; - int diff = a ^ b; - if (diff & SkTypeface::kBold) { - dist += 2; - } - if (diff & SkTypeface::kItalic) { - dist += 1; - } - return dist; -} - -static SkTypeface_Stream* gFonts[FONTRES_COUNT]; - -static void assure_init_fonts() { - static bool gOnce; - if (!gOnce) { - for (size_t i = 0; i < FONTRES_COUNT; i++) { - gFonts[i] = create_from_fontres(gFontRes[i]); - gOnce = true; - } - } -} - -static SkTypeface_Stream* get_default_font(SkTypeface::Style style) { - assure_init_fonts(); - - if (style & SkTypeface::kBold) { - return gFonts[DEFAULT_INDEX_BOLD]; - } else { - return gFonts[DEFAULT_INDEX_REGULAR]; - } -} - -static SkTypeface_Stream* find_by_id(SkFontID fontID) { - assure_init_fonts(); - - for (size_t i = 0; i < FONTRES_COUNT; i++) { - if (gFonts[i]->uniqueID() == fontID) { - return gFonts[i]; - } - } - return NULL; -} - -/////////////////////////////////////////////////////////////////////////////// - -template <typename T> T* ref_and_return(T* obj) { - obj->ref(); - return obj; -} - -SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, - const char familyName[], - const void* data, size_t bytelength, - SkTypeface::Style style) { - assure_init_fonts(); - - if (familyName) { - FontDesign design = find_design_from_name(familyName); - if (kIllegal_FontDesign != design) { - familyName = "$#@*&%*#$@ never match any name"; - } - - int bestDistance = 999; - int bestIndex = -1; - for (size_t i = 0; i < FONTRES_COUNT; i++) { - if (design == gFontRes[i].fDesign || !strcmp(gFontRes[i].fName, familyName)) { - int dist = compute_style_distance(style, gFontRes[i].fStyle); - if (dist < bestDistance) { - bestDistance = dist; - bestIndex = i; - } - } - } - if (bestIndex >= 0) { - return ref_and_return(gFonts[bestIndex]); - } - } - - return ref_and_return(get_default_font(style)); -} - -SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { - SkDEBUGFAIL("SkFontHost::CreateTypeface unimplemented"); - return NULL; -} - -SkTypeface* SkFontHost::CreateTypefaceFromFile(char const*) { -// SkDEBUGFAIL("SkFontHost::CreateTypefaceFromFile unimplemented"); - return NULL; -} - -/////////////////////////////////////////////////////////////////////////////// - -SkStream* SkFontHost::OpenStream(uint32_t uniqueID) { - SkTypeface_Stream* tf = find_by_id(uniqueID); - SkASSERT(tf); - return tf->refStream(); -} - -size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, - int32_t* index) { - SkDebugf("SkFontHost::GetFileName unimplemented\n"); - return 0; -} - -/////////////////////////////////////////////////////////////////////////////// - -void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) { - SkDEBUGFAIL("SkFontHost::Serialize unimplemented"); -} - -SkTypeface* SkFontHost::Deserialize(SkStream* stream) { - int style = stream->readU8(); - int len = stream->readPackedUInt(); - const char* name = NULL; - if (len > 0) { - SkString str; - str.resize(len); - stream->read(str.writable_str(), len); - - if (str.startsWith("DroidSans")) { - name = "sans-serif"; - } else if (str.startsWith("DroidSerif")) { - name = "serif"; - } - SkDebugf("---- deserialize typeface <%s> %d %s\n", str.c_str(), style, name); - } -// name = NULL; style = 0; - return SkFontHost::CreateTypeface(NULL, name, NULL, NULL, - (SkTypeface::Style)style); -} - -SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) { - return 0; -} - -#define FONT_CACHE_MEMORY_BUDGET 1 * 1024 * 1024 - -size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) { - if (sizeAllocatedSoFar > FONT_CACHE_MEMORY_BUDGET) - return sizeAllocatedSoFar - FONT_CACHE_MEMORY_BUDGET; - else - return 0; // nothing to do -} - -/////////////////////////////////////////////////////////////////////////////// -int SkFontHost::ComputeGammaFlag(const SkPaint& paint) { - return 0; -} - -void SkFontHost::GetGammaTables(const uint8_t* tables[2]) { - tables[0] = NULL; // black gamma (e.g. exp=1.4) - tables[1] = NULL; // white gamma (e.g. exp= 1/1.4) -} - -// static -SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics( - uint32_t fontID, - SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo) { - SkDEBUGFAIL("SkFontHost::GetAdvancedTypefaceMetrics unimplemented"); - return NULL; -} - -void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface*) { -} - -SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) { - SkDEBUGFAIL("SkFontHost::CreateScalarContext unimplemented"); - return NULL; -}
\ No newline at end of file diff --git a/src/utils/ios/SkImageDecoder_iOS.mm b/src/utils/ios/SkImageDecoder_iOS.mm deleted file mode 100755 index f3db65e035..0000000000 --- a/src/utils/ios/SkImageDecoder_iOS.mm +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2010 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#import <CoreGraphics/CoreGraphics.h> -#include <CoreGraphics/CGColorSpace.h> -#import <UIKit/UIKit.h> - -#include "SkImageDecoder.h" -#include "SkImageEncoder.h" -#include "SkMovie.h" -#include "SkStream_NSData.h" - -class SkImageDecoder_iOS : public SkImageDecoder { -protected: - virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode); -}; - -#define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast) - -bool SkImageDecoder_iOS::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { - - NSData* data = NSData_dataWithStream(stream); - - UIImage* uimage = [UIImage imageWithData:data]; - - const int width = uimage.size.width; - const int height = uimage.size.height; - bm->setInfo(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType), 0); - if (SkImageDecoder::kDecodeBounds_Mode == mode) { - return true; - } - - if (!this->allocPixelRef(bm, NULL)) { - return false; - } - - bm->lockPixels(); - bm->eraseColor(0); - - CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); - CGContextRef cg = CGBitmapContextCreate(bm->getPixels(), width, height, - 8, bm->rowBytes(), cs, BITMAP_INFO); - CGContextDrawImage(cg, CGRectMake(0, 0, width, height), uimage.CGImage); - CGContextRelease(cg); - CGColorSpaceRelease(cs); - - bm->unlockPixels(); - return true; -} - -///////////////////////////////////////////////////////////////////////// - -SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) { - return new SkImageDecoder_iOS; -} - -SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) { - return NULL; -} - - diff --git a/src/utils/ios/SkOSFile_iOS.mm b/src/utils/ios/SkOSFile_iOS.mm deleted file mode 100755 index e38ecfdab4..0000000000 --- a/src/utils/ios/SkOSFile_iOS.mm +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2010 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <Foundation/Foundation.h> -#include "SkOSFile.h" -#include "SkString.h" - -struct SkFILE { - NSData* fData; - size_t fOffset; - size_t fLength; -}; - -SkFILE* sk_fopen(const char cpath[], SkFILE_Flags flags) { - if (flags & kWrite_SkFILE_Flag) { - return NULL; - } - - SkString cname, csuffix; - - const char* start = strrchr(cpath, '/'); - if (NULL == start) { - start = cpath; - } else { - start += 1; - } - const char* stop = strrchr(cpath, '.'); - if (NULL == stop) { - return NULL; - } else { - stop += 1; - } - - cname.set(start, stop - start - 1); - csuffix.set(stop); - - NSBundle* bundle = [NSBundle mainBundle]; - NSString* name = [NSString stringWithUTF8String:cname.c_str()]; - NSString* suffix = [NSString stringWithUTF8String:csuffix.c_str()]; - NSString* path = [bundle pathForResource:name ofType:suffix]; - NSData* data = [NSData dataWithContentsOfMappedFile:path]; - - if (data) { - [data retain]; - SkFILE* rec = new SkFILE; - rec->fData = data; - rec->fOffset = 0; - rec->fLength = [data length]; - return reinterpret_cast<SkFILE*>(rec); - } - return NULL; -} - -size_t sk_fgetsize(SkFILE* rec) { - SkASSERT(rec); - return rec->fLength; -} - -bool sk_frewind(SkFILE* rec) { - SkASSERT(rec); - rec->fOffset = 0; - return true; -} - -size_t sk_fread(void* buffer, size_t byteCount, SkFILE* rec) { - if (NULL == buffer) { - return rec->fLength; - } else { - size_t remaining = rec->fLength - rec->fOffset; - if (byteCount > remaining) { - byteCount = remaining; - } - memcpy(buffer, (char*)[rec->fData bytes] + rec->fOffset, byteCount); - rec->fOffset += byteCount; - SkASSERT(rec->fOffset <= rec->fLength); - return byteCount; - } -} - -size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE* f) { - SkDEBUGFAIL("Not supported yet"); - return 0; -} - -void sk_fflush(SkFILE* f) { - SkDEBUGFAIL("Not supported yet"); -} - -void sk_fclose(SkFILE* rec) { - SkASSERT(rec); - [rec->fData release]; - delete rec; -} - diff --git a/src/utils/ios/SkStream_NSData.mm b/src/utils/ios/SkStream_NSData.mm deleted file mode 100755 index ef20f63e13..0000000000 --- a/src/utils/ios/SkStream_NSData.mm +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2010 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkStream_NSData.h" - -NSData* NSData_dataWithStream(SkStream* stream) { - size_t length = stream->getLength(); - void* src = malloc(length); - size_t bytes = stream->read(src, length); - SkASSERT(bytes == length); - return [NSData dataWithBytesNoCopy:src length:length freeWhenDone:YES]; -} - -NSData* NSData_dataFromResource(const char cname[], const char csuffix[]) { - NSBundle* bundle = [NSBundle mainBundle]; - NSString* name = [NSString stringWithUTF8String:cname]; - NSString* suffix = [NSString stringWithUTF8String:csuffix]; - NSString* path = [bundle pathForResource:name ofType:suffix]; - return [NSData dataWithContentsOfMappedFile:path]; -} - -/////////////////////////////////////////////////////////////////////////////// - -SkStream_NSData::SkStream_NSData(NSData* data) { - fNSData = data; - [fNSData retain]; - - this->setMemory([fNSData bytes], [fNSData length], false); -} - -SkStream_NSData::~SkStream_NSData() { - [fNSData release]; -} - -SkStream_NSData* SkStream_NSData::CreateFromResource(const char name[], - const char suffix[]) { - NSData* data = NSData_dataFromResource(name, suffix); - return SkNEW_ARGS(SkStream_NSData, (data)); -} - |