Start making all .cpp files compile-able on all platforms.

I sometimes dream to hone our build process down to something as simple as
    $ find src -name '*.cpp' | xargs c++ <some cflags> -c -o skia.o

To start, it helps if we can compile all files on all platforms.  Each
non-portable file guards itself with defines provided by SkTypes.h.  This does
not convert all non-portable code, but it's a good representative chunk.

E.g. instead of having to remember which SkDebug_*.cpp to compile on which
platform we can just compile all three and let the code itself sort it out.

This has the nice side effect of making non-portable code declare the
conditions under which it can compile explicitly.

I've been testing mostly with the CMake build as it's easiest, but this should
apply equally to BUILD, Gyp, and GN files... to any build system really.

BUG=skia:4269
CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-CMake-Trybot,Build-Mac10.9-Clang-x86_64-Release-CMake-Trybot

Review URL: https://codereview.chromium.org/1411283005
This commit is contained in:
mtklein 2015-11-02 10:20:27 -08:00 committed by Commit bot
parent 3f0424ff57
commit 1ee76510f5
40 changed files with 162 additions and 56 deletions

View File

@ -52,16 +52,8 @@ remove_srcs (../src/ports/SkFontMgr_custom*.cpp)
remove_srcs (../src/animator/* ../src/*nacl* ../src/svg/* ../src/views/* ../src/xml/*)
# Remove OS-specific source files.
if (NOT WIN32)
remove_srcs(../src/*XPS*
../src/*_win*.cpp
../src/ports/SkImageDecoder_WIC.cpp
../src/utils/win/*)
endif()
if (NOT UNIX)
remove_srcs(../src/doc/SkDocument_XPS_None.cpp
../src/ports/*_posix.cpp
../src/ports/SkDebug_stdio.cpp
remove_srcs(../src/ports/*_posix.cpp
../src/ports/SkTLS_pthread.cpp
../src/ports/SkTime_Unix.cpp
../src/utils/SkThreadUtils_pthread.cpp)
@ -72,15 +64,6 @@ if (APPLE OR NOT UNIX)
../src/ports/SkFontMgr_fontconfig*.cpp
../src/*FreeType*)
endif()
if (NOT ANDROID)
remove_srcs(../src/*Hwui* ../src/*android*)
endif()
if (NOT APPLE)
remove_srcs(../src/*darwin*
../src/ports/SkImageDecoder_CG.cpp
../src/utils/mac/*
../src/*_mac*)
endif()
# Remove processor-specific source files.
if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ARM)
@ -128,6 +111,7 @@ set_source_files_properties(${sse41_srcs} PROPERTIES COMPILE_FLAGS -msse4.1)
# Detect our optional dependencies.
# If we can't find them, don't build the parts of Skia that use them.
find_package (EXPAT)
find_package (Lua)
find_package (ZLIB)
# No find_package for libwebp as far as I can tell, so simulate it here.
@ -148,6 +132,13 @@ endif()
# TODO: macro away this if (found) ... else() ... endif() stuff.
if (EXPAT_FOUND)
list (APPEND private_includes ${EXPAT_INCLUDE_DIRS})
list (APPEND libs ${EXPAT_LIBRARIES})
else()
remove_srcs (../src/ports/SkFontMgr_android_parser.cpp)
endif()
if (GIF_FOUND)
list (APPEND private_includes ${GIF_INCLUDE_DIRS})
list (APPEND libs ${GIF_LIBRARIES})

View File

@ -6,6 +6,7 @@
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#ifndef UNICODE
#define UNICODE
@ -2265,3 +2266,4 @@ SkBaseDevice* SkXPSDevice::onCreateDevice(const CreateInfo& info, const SkPaint*
return new SkXPSDevice(this->fXpsFactory.get());
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -5,6 +5,9 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkDocument.h"
#include "SkXPSDevice.h"
#include "SkStream.h"
@ -75,3 +78,5 @@ SkDocument* SkDocument::CreateXPS(const char path[], SkScalar dpi) {
}
return new SkDocument_XPS(stream.detach(), delete_wstream, dpi);
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -4,6 +4,12 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if !defined(SK_BUILD_FOR_WIN32)
#include "SkDocument.h"
SkDocument* SkDocument::CreateXPS(SkWStream*, SkScalar) { return nullptr; }
SkDocument* SkDocument::CreateXPS(const char path[], SkScalar) { return nullptr; }
#endif//!defined(SK_BUILD_FOR_WIN32)

View File

@ -5,6 +5,9 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_ANDROID)
#include "gl/GrGLInterface.h"
#include "gl/GrGLAssembleInterface.h"
#include "gl/GrGLUtil.h"
@ -227,3 +230,5 @@ static GrGLFuncPtr android_get_gl_proc(void* ctx, const char name[]) {
const GrGLInterface* GrGLCreateNativeInterface() {
return GrGLAssembleInterface(nullptr, android_get_gl_proc);
}
#endif//defined(SK_BUILD_FOR_ANDROID)

View File

@ -5,6 +5,8 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_MAC)
#include "gl/GrGLInterface.h"
@ -56,3 +58,5 @@ const GrGLInterface* GrGLCreateNativeInterface() {
GLProcGetter getter;
return GrGLAssembleGLInterface(&getter, mac_get_gl_proc);
}
#endif//defined(SK_BUILD_FOR_MAC)

View File

@ -5,6 +5,9 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_MAC)
#include "gl/SkGLContext.h"
#include "AvailabilityMacros.h"
@ -117,3 +120,5 @@ SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) {
}
return ctx;
}
#endif//defined(SK_BUILD_FOR_MAC)

View File

@ -5,6 +5,8 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "gl/GrGLInterface.h"
#include "gl/GrGLAssembleInterface.h"
@ -85,3 +87,5 @@ const GrGLInterface* GrGLCreateNativeInterface() {
}
return nullptr;
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -6,6 +6,8 @@
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_ANDROID)
#include <stdio.h>
#define LOG_TAG "skia"
@ -30,3 +32,5 @@ void SkDebugf(const char format[], ...) {
va_end(args1);
}
#endif//defined(SK_BUILD_FOR_ANDROID)

View File

@ -1,38 +0,0 @@
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
static const size_t kBufferSize = 2048;
#include <stdarg.h>
#include <stdio.h>
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/var.h"
extern pp::Instance* gPluginInstance;
namespace {
static const char* kLogPrefix = "SkDebugf:";
}
void SkDebugf(const char format[], ...) {
if (gPluginInstance) {
char buffer[kBufferSize + 1];
va_list args;
va_start(args, format);
sprintf(buffer, kLogPrefix);
vsnprintf(buffer + strlen(kLogPrefix), kBufferSize, format, args);
va_end(args);
pp::Var msg = pp::Var(buffer);
gPluginInstance->PostMessage(msg);
}
}

View File

@ -6,6 +6,7 @@
*/
#include "SkTypes.h"
#if !defined(SK_BUILD_FOR_WIN32) && !defined(SK_BUILD_FOR_ANDROID)
#include <stdarg.h>
#include <stdio.h>
@ -16,3 +17,4 @@ void SkDebugf(const char format[], ...) {
vfprintf(stderr, format, args);
va_end(args);
}
#endif//!defined(SK_BUILD_FOR_WIN32) && !defined(SK_BUILD_FOR_ANDROID)

View File

@ -9,6 +9,7 @@
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
static const size_t kBufferSize = 2048;
@ -31,3 +32,4 @@ void SkDebugf(const char format[], ...) {
OutputDebugStringA(buffer);
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -7,6 +7,7 @@
*/
#include "SkTypes.h" // Keep this before any #ifdef ...
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
#ifdef SK_BUILD_FOR_MAC
#import <ApplicationServices/ApplicationServices.h>
@ -2491,3 +2492,5 @@ protected:
///////////////////////////////////////////////////////////////////////////////
SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; }
#endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)

View File

@ -5,6 +5,9 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkAdvancedTypefaceMetrics.h"
#include "SkBase64.h"
#include "SkColorPriv.h"
@ -2511,3 +2514,5 @@ private:
///////////////////////////////////////////////////////////////////////////////
SkFontMgr* SkFontMgr_New_GDI() { return new SkFontMgrGDI; }
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -5,6 +5,9 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_ANDROID)
#include "SkFixed.h"
#include "SkFontDescriptor.h"
#include "SkFontHost_FreeType_common.h"
@ -586,3 +589,5 @@ SkFontMgr* SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) {
return new SkFontMgr_Android(custom);
}
#endif//defined(SK_BUILD_FOR_ANDROID)

View File

@ -4,6 +4,8 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_ANDROID)
#include "SkFontMgr.h"
#include "SkFontMgr_android.h"
@ -41,3 +43,5 @@ SkFontMgr* SkFontMgr::Factory() {
return SkFontMgr_New_Android(nullptr);
}
#endif//defined(SK_BUILD_FOR_ANDROID)

View File

@ -5,6 +5,8 @@
* found in the LICENSE file.
*/
// Despite the name and location, this is portable code.
#include "SkFontMgr_android_parser.h"
#include "SkStream.h"
#include "SkTDArray.h"

View File

@ -5,6 +5,9 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkDWrite.h"
#include "SkDWriteFontFileStream.h"
#include "SkFontMgr.h"
@ -1103,3 +1106,4 @@ SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) {
}
return new SkFontMgr_Indirect(impl.get(), proxy);
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -5,9 +5,14 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32) // And !SKIA_GDI?
#include "SkFontMgr.h"
#include "SkTypeface_win.h"
SkFontMgr* SkFontMgr::Factory() {
return SkFontMgr_New_DirectWrite();
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -5,9 +5,14 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32) // And SKIA_GDI?
#include "SkFontMgr.h"
#include "SkTypeface_win.h"
SkFontMgr* SkFontMgr::Factory() {
return SkFontMgr_New_GDI();
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -5,6 +5,9 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
#include "SkCGUtils.h"
#include "SkColorPriv.h"
#include "SkImageDecoder.h"
@ -401,3 +404,5 @@ static SkImageDecoder::Format get_format_cg(SkStreamRewindable* stream) {
}
static SkImageDecoder_FormatReg gFormatReg(get_format_cg);
#endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)

View File

@ -8,6 +8,8 @@
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
// Workaround for:
// http://connect.microsoft.com/VisualStudio/feedback/details/621653/
// http://crbug.com/225822
@ -462,3 +464,5 @@ static SkImageDecoder::Format get_format_wic(SkStreamRewindable* stream) {
}
static SkImageDecoder_FormatReg gFormatReg(get_format_wic);
#endif // defined(SK_BUILD_FOR_WIN32)

View File

@ -5,6 +5,9 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkOSFile.h"
#include "SkTFitsIn.h"
@ -240,3 +243,5 @@ bool SkOSFile::Iter::next(SkString* name, bool getDir) {
}
return self.fHandle != (HANDLE)~0 && get_the_file(self.fHandle, name, dataPtr, getDir);
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -5,6 +5,9 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if !defined(SK_BUILD_FOR_WIN32)
#include "SkOSLibrary.h"
#include <dlfcn.h>
@ -16,3 +19,4 @@ void* DynamicLoadLibrary(const char* libraryName) {
void* GetProcedureAddress(void* library, const char* functionName) {
return dlsym(library, functionName);
}
#endif//!defined(SK_BUILD_FOR_WIN32)

View File

@ -5,6 +5,9 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkOSLibrary.h"
#include <windows.h>
@ -15,3 +18,5 @@ void* DynamicLoadLibrary(const char* libraryName) {
void* GetProcedureAddress(void* library, const char* functionName) {
return ::GetProcAddress((HMODULE)library, functionName);
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -4,6 +4,8 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkDWrite.h"
#include "SkDWriteFontFileStream.h"
@ -504,3 +506,4 @@ SkRemotableFontMgr* SkRemotableFontMgr_New_DirectWrite() {
return new SkRemotableFontMgr_DirectWrite(sysFontCollection.get(), localeName, localeNameLen);
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -6,6 +6,8 @@
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#undef GetGlyphIndices
#include "SkDWrite.h"
@ -776,3 +778,5 @@ void SkScalerContext_DW::generatePath(const SkGlyph& glyph, SkPath* path) {
path->transform(fSkXform);
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -4,6 +4,8 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkTLS.h"
#include "SkMutex.h"
@ -73,3 +75,5 @@ PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback;
#endif
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -5,6 +5,8 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkTime.h"
@ -39,3 +41,4 @@ void SkTime::GetDateTime(DateTime* dt)
dt->fSecond = SkToU8(st.wSecond);
}
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -6,6 +6,8 @@
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
// SkTypes will include Windows.h, which will pull in all of the GDI defines.
// GDI #defines GetGlyphIndices to GetGlyphIndicesA or GetGlyphIndicesW, but
// IDWriteFontFace has a method called GetGlyphIndices. Since this file does
@ -459,3 +461,4 @@ SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics(
return info;
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -6,6 +6,7 @@
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkThreadUtils.h"
#include "SkThreadUtils_win.h"
@ -96,3 +97,5 @@ void SkThread::join() {
WaitForSingleObject(winData->fHandle, INFINITE);
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -5,6 +5,10 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
#include "SkCGUtils.h"
#include "SkBitmap.h"
#include "SkColorPriv.h"
@ -306,3 +310,5 @@ bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef image, SkISize* scaleTo
*dst = tmp;
return true;
}
#endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)

View File

@ -5,6 +5,9 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
#include "SkCGUtils.h"
#include "SkStream.h"
@ -74,3 +77,5 @@ CGDataProviderRef SkCreateDataProviderFromData(SkData* data) {
return CGDataProviderCreateWithData(data, data->data(), data->size(),
unref_proc);
}
#endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)

View File

@ -6,6 +6,9 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@ -27,3 +30,5 @@ SkAutoCoInitialize::~SkAutoCoInitialize() {
bool SkAutoCoInitialize::succeeded() {
return SUCCEEDED(this->fHR) || RPC_E_CHANGED_MODE == this->fHR;
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -4,6 +4,8 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkDWrite.h"
#include "SkHRESULT.h"
@ -122,3 +124,5 @@ HRESULT SkGetGetUserDefaultLocaleNameProc(SkGetUserDefaultLocaleNameProc* proc)
}
return S_OK;
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -4,6 +4,8 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkTypes.h"
#include "SkDWriteFontFileStream.h"
@ -229,3 +231,5 @@ HRESULT STDMETHODCALLTYPE SkDWriteFontFileStreamWrapper::GetLastWriteTime(UINT64
*lastWriteTime = 0;
return E_NOTIMPL;
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -6,6 +6,7 @@
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkDWriteGeometrySink.h"
#include "SkFloatUtils.h"
@ -144,3 +145,5 @@ HRESULT SkDWriteGeometrySink::Create(SkPath* path, IDWriteGeometrySink** geometr
*geometryToPath = new SkDWriteGeometrySink(path);
return S_OK;
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -6,6 +6,7 @@
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkHRESULT.h"
@ -35,3 +36,5 @@ void SkTraceHR(const char* file, unsigned long line, HRESULT hr, const char* msg
errorText = nullptr;
}
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -6,6 +6,8 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@ -275,3 +277,4 @@ HRESULT STDMETHODCALLTYPE SkWIStream::Stat(STATSTG* pStatstg
pStatstg->grfMode = STGM_WRITE;
return S_OK;
}
#endif//defined(SK_BUILD_FOR_WIN32)

View File

@ -6,6 +6,9 @@
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SkWGL.h"
#include "SkTDArray.h"
@ -455,3 +458,5 @@ SkWGLPbufferContext::SkWGLPbufferContext(HPBUFFER pbuffer, HDC dc, HGLRC glrc)
, fDC(dc)
, fGLRC(glrc) {
}
#endif//defined(SK_BUILD_FOR_WIN32)