Update skia to chrome/m53

This commit is contained in:
David Capello 2016-07-12 13:23:24 -03:00
parent 691ff2c08a
commit 8e7b700c35
6 changed files with 143 additions and 121 deletions

View File

@ -73,59 +73,52 @@ if(USE_SKIA_BACKEND)
set(SKIA_BUILD_OUT_DIR "${SKIA_DIR}/out/Release")
endif()
find_library(SKIA_CODEC_LIBRARY skia_codec PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_CORE_LIBRARY skia_core PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_DNG_SDK_LIBRARY dng_sdk PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_EFFECTS_LIBRARY skia_effects PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_ETC1_LIBRARY etc1 NAMES libetc1 PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_FLAGS_LIBRARY flags PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_GIF_LIBRARY giflib PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_IMAGES_LIBRARY skia_images PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_OPTS_LIBRARY skia_opts PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_OPTS_AVX_LIBRARY skia_opts_avx PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_JPG_LIBRARY jpeg-turbo NAMES libjpeg-turbo PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_OPTS_AVX2_LIBRARY skia_opts_avx2 PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_OPTS_AVX_LIBRARY skia_opts_avx PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_OPTS_AVX_LIBRARY skia_opts_avx PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_OPTS_LIBRARY skia_opts PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_OPTS_SSE41_LIBRARY skia_opts_sse41 PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_OPTS_SSE42_LIBRARY skia_opts_sse42 PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_OPTS_SSSE3_LIBRARY skia_opts_ssse3 PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_OPTS_AVX_LIBRARY skia_opts_avx PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_PIEX_LIBRARY piex PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_PNG_LIBRARY png_static NAMES libpng_static PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_PORTS_LIBRARY skia_ports PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_RAW_CODEC_LIBRARY raw_codec PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_SFNT_LIBRARY skia_sfnt PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_SKKTX_LIBRARY SkKTX libSkKTX PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_UTILS_LIBRARY skia_utils PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_WEBP_DEC_LIBRARY webp_dec NAMES libwebp_dec PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_WEBP_DSP_LIBRARY webp_dsp NAMES libwebp_dsp PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_WEBP_UTILS_LIBRARY webp_utils NAMES libwebp_utils PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_ZLIB_LIBRARY zlib PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_GPU_LIBRARY skia_skgpu PATH "${SKIA_BUILD_OUT_DIR}")
if(SKIA_GPU_LIBRARY)
add_definitions(-DSK_SUPPORT_GPU=1)
else()
add_definitions(-DSK_SUPPORT_GPU=0)
set(SKIA_GPU_LIBRARY "")
endif()
find_library(SKIA_ETC1_LIBRARY etc1 PATH "${SKIA_BUILD_OUT_DIR}")
if(NOT SKIA_ETC1_LIBRARY)
set(SKIA_ETC1_LIBRARY "")
endif()
find_library(SKIA_FLAGS_LIBRARY flags PATH "${SKIA_BUILD_OUT_DIR}")
if(NOT SKIA_FLAGS_LIBRARY)
set(SKIA_FLAGS_LIBRARY "")
endif()
find_library(SKIA_SKKTX_LIBRARY SkKTX PATH "${SKIA_BUILD_OUT_DIR}")
if(NOT SKIA_SKKTX_LIBRARY)
set(SKIA_SKKTX_LIBRARY "")
endif()
if(WIN32)
if(SKIA_GPU_LIBRARY)
if(WIN32)
find_library(SKIA_OPENGL_LIBRARY opengl32)
find_library(SKIA_LIBEGL_LIBRARY libEGL.dll PATH "${SKIA_BUILD_OUT_DIR}")
if(SKIA_LIBEGL_LIBRARY)
add_definitions(-DSK_ANGLE=1)
endif()
else()
find_library(SKIA_OPENGL_LIBRARY opengl NAMES GL)
endif()
else()
if(SKIA_GPU_LIBRARY)
find_library(SKIA_OPENGL_LIBRARY opengl)
endif()
endif()
if(NOT SKIA_OPENGL_LIBRARY)
add_definitions(-DSK_SUPPORT_GPU=0)
set(SKIA_GPU_LIBRARY "")
set(SKIA_OPENGL_LIBRARY "")
endif()
if(NOT SKIA_LIBEGL_LIBRARY)
set(SKIA_LIBEGL_LIBRARY "")
endif()
@ -133,7 +126,8 @@ if(USE_SKIA_BACKEND)
find_path(SKIA_CONFIG_INCLUDE_DIR SkUserConfig.h HINTS "${SKIA_DIR}/include/config")
find_path(SKIA_CORE_INCLUDE_DIR SkCanvas.h HINTS "${SKIA_DIR}/include/core")
find_path(SKIA_UTILS_INCLUDE_DIR SkRandom.h HINTS "${SKIA_DIR}/include/utils")
find_path(SKIA_EFFECTS_INCLUDE_DIR SkBitmapSource.h HINTS "${SKIA_DIR}/include/effects")
find_path(SKIA_CODEC_INCLUDE_DIR SkCodec.h HINTS "${SKIA_DIR}/include/codec")
find_path(SKIA_EFFECTS_INCLUDE_DIR SkImageSource.h HINTS "${SKIA_DIR}/include/effects")
if(SKIA_GPU_LIBRARY)
find_path(SKIA_GPU_INCLUDE_DIR SkGr.h HINTS "${SKIA_DIR}/include/gpu")
find_path(SKIA_ANGLE_INCLUDE_DIR angle_gl.h HINTS "${SKIA_DIR}/third_party/externals/angle2/include")
@ -143,7 +137,8 @@ if(USE_SKIA_BACKEND)
${SKIA_CONFIG_INCLUDE_DIR}
${SKIA_CORE_INCLUDE_DIR}
${SKIA_PORTS_INCLUDE_DIR}
${SKIA_UTILS_INCLUDE_DIR})
${SKIA_UTILS_INCLUDE_DIR}
${SKIA_CODEC_INCLUDE_DIR})
if(SKIA_GPU_LIBRARY)
include_directories(${SKIA_GPU_INCLUDE_DIR})
if(WIN32)
@ -151,14 +146,7 @@ if(USE_SKIA_BACKEND)
endif()
endif()
# Patch for Skia (branch m50) as we don't link with skia_codec library
add_library(skia_missing_files ${SKIA_DIR}/src/ports/SkImageGenerator_none.cpp)
set(SKIA_MISSING_FILES skia_missing_files)
set(SKIA_LIBRARIES
${SKIA_ETC1_LIBRARY}
${SKIA_FLAGS_LIBRARY}
${SKIA_SKKTX_LIBRARY}
${SKIA_CORE_LIBRARY}
${SKIA_IMAGES_LIBRARY}
${SKIA_OPTS_LIBRARY}
@ -169,15 +157,28 @@ if(USE_SKIA_BACKEND)
${SKIA_OPTS_AVX2_LIBRARY}
${SKIA_PORTS_LIBRARY}
${SKIA_EFFECTS_LIBRARY}
${SKIA_CODEC_LIBRARY}
${SKIA_RAW_CODEC_LIBRARY}
${SKIA_PIEX_LIBRARY}
${SKIA_DNG_SDK_LIBRARY}
${SKIA_GIF_LIBRARY}
${SKIA_JPG_LIBRARY}
${SKIA_WEBP_DEC_LIBRARY}
${SKIA_WEBP_DSP_LIBRARY}
${SKIA_WEBP_UTILS_LIBRARY}
${SKIA_PNG_LIBRARY}
${SKIA_ZLIB_LIBRARY}
${SKIA_GPU_LIBRARY}
# We've to include two times skia_core as a dependency as it looks
# like Skia libraries depends one each other (core+ports+effects)
${SKIA_CORE_LIBRARY}
${SKIA_MISSING_FILES}
${SKIA_UTILS_LIBRARY}
${SKIA_SFNT_LIBRARY}
${SKIA_OPENGL_LIBRARY}
${SKIA_LIBEGL_LIBRARY}
${SKIA_GPU_LIBRARY}
${SKIA_SKKTX_LIBRARY}
${SKIA_ETC1_LIBRARY}
${SKIA_FLAGS_LIBRARY}
CACHE INTERNAL "Skia libraries")
list(APPEND SHE_SOURCES

View File

@ -38,7 +38,7 @@ public:
, m_lock(0) {
}
SkiaSurface(SkSurface* surface)
SkiaSurface(const sk_sp<SkSurface>& surface)
: m_surface(surface)
, m_canvas(nullptr)
, m_clip(0, 0, width(), height())
@ -149,11 +149,11 @@ public:
bitmap.unlockPixels();
}
SkAutoTUnref<SkShader> shader(
SkShader::CreateBitmapShader(
sk_sp<SkShader> shader(
SkShader::MakeBitmapShader(
bitmap,
SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode, nullptr));
SkShader::kRepeat_TileMode));
m_paint.setShader(shader);
}
break;
@ -426,8 +426,8 @@ public:
m_canvas->drawRect(dstRect, paint);
}
SkAutoTUnref<SkColorFilter> colorFilter(
SkColorFilter::CreateModeFilter(to_skia(fg), SkXfermode::kSrcIn_Mode));
sk_sp<SkColorFilter> colorFilter(
SkColorFilter::MakeModeFilter(to_skia(fg), SkXfermode::kSrcIn_Mode));
paint.setColorFilter(colorFilter);
m_canvas->drawBitmapRect(
@ -457,7 +457,7 @@ private:
}
SkBitmap m_bitmap;
SkSurface* m_surface;
sk_sp<SkSurface> m_surface;
SkCanvas* m_canvas;
SkPaint m_paint;
gfx::Rect m_clip;

View File

@ -11,7 +11,7 @@
#include "base/base.h"
#include "base/file_handle.h"
#include "SkImageDecoder.h"
#include "SkCodec.h"
#include "SkPixelRef.h"
#include "SkStream.h"
@ -41,13 +41,6 @@ public:
SkiaSystem()
: m_defaultDisplay(nullptr)
, m_gpuAcceleration(false) {
#if !defined(__APPLE__) && !defined(_WIN32)
// Create one decoder on Linux to load .png files with
// libpng. Without this, SkImageDecoder::Factory() returns null
// for .png files.
SkAutoTDelete<SkImageDecoder> decoder(
CreatePNGImageDecoder());
#endif
}
~SkiaSystem() {
@ -133,22 +126,27 @@ public:
Surface* loadSurface(const char* filename) override {
base::FileHandle fp(base::open_file_with_exception(filename, "rb"));
SkAutoTDelete<SkStreamAsset> stream(new SkFILEStream(fp.get(), SkFILEStream::kCallerRetains_Ownership));
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream));
if (decoder) {
stream->rewind();
SkBitmap bm;
SkImageDecoder::Result res = decoder->decode(stream, &bm,
kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
SkAutoTDelete<SkCodec> codec(
SkCodec::NewFromStream(
new SkFILEStream(fp.get(), SkFILEStream::kCallerRetains_Ownership)));
if (!codec)
return nullptr;
if (res == SkImageDecoder::kSuccess) {
SkiaSurface* sur = new SkiaSurface();
sur->swapBitmap(bm);
return sur;
}
}
return nullptr;
SkImageInfo info = codec->getInfo()
.makeColorType(kN32_SkColorType)
.makeAlphaType(kPremul_SkAlphaType);
SkBitmap bm;
if (!bm.tryAllocPixels(info))
return nullptr;
const SkCodec::Result r = codec->getPixels(info, bm.getPixels(), bm.rowBytes());
if (r != SkCodec::kSuccess)
return nullptr;
SkiaSurface* sur = new SkiaSurface();
sur->swapBitmap(bm);
return sur;
}
Surface* loadRgbaSurface(const char* filename) override {

View File

@ -216,7 +216,7 @@ private:
if (m_nsGL)
m_nsGL = nil;
setSurface(nullptr);
m_skSurface.reset(nullptr);
m_skSurfaceDirect.reset(nullptr);
m_grRenderTarget.reset(nullptr);
m_grCtx.reset(nullptr);
@ -237,21 +237,22 @@ private:
desc.fRenderTargetHandle = 0; // direct frame buffer
m_grRenderTarget.reset(m_grCtx->textureProvider()->wrapBackendRenderTarget(desc));
setSurface(nullptr); // set m_skSurface comparing with the old m_skSurfaceDirect
m_skSurfaceDirect.reset(
SkSurface::NewRenderTargetDirect(m_grRenderTarget));
m_skSurface.reset(nullptr); // set m_skSurface comparing with the old m_skSurfaceDirect
m_skSurfaceDirect =
SkSurface::MakeRenderTargetDirect(m_grRenderTarget.get());
if (scale == 1) {
setSurface(m_skSurfaceDirect);
m_skSurface = m_skSurfaceDirect;
}
else {
setSurface(
SkSurface::NewRenderTarget(
m_grCtx,
SkSurface::kYes_Budgeted,
m_skSurface =
SkSurface::MakeRenderTarget(
m_grCtx.get(),
SkBudgeted::kYes,
SkImageInfo::MakeN32Premul(MAX(1, size.w / scale),
MAX(1, size.h / scale)),
m_glCtx->getSampleCount()));
m_glCtx->getSampleCount(),
nullptr);
}
if (!m_skSurface)
@ -263,12 +264,6 @@ private:
[m_nsGL update];
}
void setSurface(SkSurface* surface) {
if (m_skSurface && m_skSurface != m_skSurfaceDirect)
delete m_skSurface;
m_skSurface = surface;
}
#endif
void paintGC(const gfx::Rect& rect) {
@ -310,10 +305,10 @@ private:
base::UniquePtr<GLContext> m_glCtx;
SkAutoTUnref<const GrGLInterface> m_glInterfaces;
NSOpenGLContext* m_nsGL;
SkAutoTUnref<GrContext> m_grCtx;
SkAutoTUnref<GrRenderTarget> m_grRenderTarget;
SkAutoTDelete<SkSurface> m_skSurfaceDirect;
SkSurface* m_skSurface;
sk_sp<GrContext> m_grCtx;
sk_sp<GrRenderTarget> m_grRenderTarget;
sk_sp<SkSurface> m_skSurfaceDirect;
sk_sp<SkSurface> m_skSurface;
gfx::Size m_lastSize;
#endif
};

View File

@ -21,6 +21,7 @@
#include "she/gl/gl_context_wgl.h"
#if SK_ANGLE
#include "she/gl/gl_context_egl.h"
#include "gl/GrGLAssembleInterface.h"
#endif
#endif
@ -106,7 +107,7 @@ void SkiaWindow::paintImpl(HDC hdc)
texDesc.fConfig = kSkia8888_GrPixelConfig;
texDesc.fSampleCnt = m_sampleCount;
texDesc.fTextureHandle = texID;
SkAutoTUnref<SkImage> image(SkImage::NewFromTexture(m_grCtx, texDesc));
sk_sp<SkImage> image(SkImage::MakeFromTexture(m_grCtx.get(), texDesc));
SkRect dstRect(SkRect::MakeWH(SkIntToScalar(m_lastSize.w),
SkIntToScalar(m_lastSize.h)));
@ -160,22 +161,55 @@ void SkiaWindow::paintHDC(HDC hdc)
#if SK_ANGLE
struct ANGLEAssembleContext {
ANGLEAssembleContext() {
fEGL = GetModuleHandle(L"libEGL.dll");
fGL = GetModuleHandle(L"libGLESv2.dll");
}
bool isValid() const { return SkToBool(fEGL) && SkToBool(fGL); }
HMODULE fEGL;
HMODULE fGL;
};
static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) {
const ANGLEAssembleContext& context = *reinterpret_cast<const ANGLEAssembleContext*>(ctx);
GrGLFuncPtr proc = (GrGLFuncPtr) GetProcAddress(context.fGL, name);
if (proc) {
return proc;
}
proc = (GrGLFuncPtr) GetProcAddress(context.fEGL, name);
if (proc) {
return proc;
}
return eglGetProcAddress(name);
}
static const GrGLInterface* get_angle_gl_interface() {
ANGLEAssembleContext context;
if (!context.isValid()) {
return nullptr;
}
return GrGLAssembleGLESInterface(&context, angle_get_gl_proc);
}
bool SkiaWindow::attachANGLE()
{
if (!m_glCtx) {
try {
SkAutoTDelete<GLContext> ctx(new GLContextEGL(handle()));
base::UniquePtr<GLContext> ctx(new GLContextEGL(handle()));
if (!ctx->createGLContext())
throw std::runtime_error("Cannot create EGL context");
m_glInterfaces.reset(GrGLCreateANGLEInterface());
m_glInterfaces.reset(get_angle_gl_interface());
if (!m_glInterfaces || !m_glInterfaces->validate())
throw std::runtime_error("Cannot create EGL interfaces\n");
m_stencilBits = ctx->getStencilBits();
m_sampleCount = ctx->getSampleCount();
m_glCtx.reset(ctx.detach());
m_glCtx.reset(ctx.release());
m_grCtx.reset(
GrContext::Create(kOpenGL_GrBackend,
(GrBackendContext)m_glInterfaces.get()));
@ -200,7 +234,7 @@ bool SkiaWindow::attachGL()
{
if (!m_glCtx) {
try {
SkAutoTDelete<GLContext> ctx(new GLContextWGL(handle()));
base::UniquePtr<GLContext> ctx(new GLContextWGL(handle()));
if (!ctx->createGLContext())
throw std::runtime_error("Cannot create WGL context\n");
@ -211,9 +245,10 @@ bool SkiaWindow::attachGL()
m_stencilBits = ctx->getStencilBits();
m_sampleCount = ctx->getSampleCount();
m_glCtx.reset(ctx.detach());
m_grCtx.reset(GrContext::Create(kOpenGL_GrBackend,
(GrBackendContext)m_glInterfaces.get()));
m_glCtx.reset(ctx.release());
m_grCtx.reset(
GrContext::Create(kOpenGL_GrBackend,
(GrBackendContext)m_glInterfaces.get()));
LOG("Using WGL backend\n");
}
@ -234,7 +269,7 @@ void SkiaWindow::detachGL()
if (m_glCtx && m_display)
m_display->resetSkiaSurface();
setSurface(nullptr);
m_skSurface.reset(nullptr);
m_skSurfaceDirect.reset(nullptr);
m_grRenderTarget.reset(nullptr);
m_grCtx.reset(nullptr);
@ -256,21 +291,22 @@ void SkiaWindow::createRenderTarget(const gfx::Size& size)
desc.fRenderTargetHandle = 0; // direct frame buffer
m_grRenderTarget.reset(m_grCtx->textureProvider()->wrapBackendRenderTarget(desc));
setSurface(nullptr); // set m_skSurface comparing with the old m_skSurfaceDirect
m_skSurfaceDirect.reset(
SkSurface::NewRenderTargetDirect(m_grRenderTarget));
m_skSurface.reset(nullptr); // set m_skSurface comparing with the old m_skSurfaceDirect
m_skSurfaceDirect =
SkSurface::MakeRenderTargetDirect(m_grRenderTarget.get());
if (scale == 1) {
setSurface(m_skSurfaceDirect);
m_skSurface = m_skSurfaceDirect;
}
else {
setSurface(
SkSurface::NewRenderTarget(
m_grCtx,
SkSurface::kYes_Budgeted,
m_skSurface =
SkSurface::MakeRenderTarget(
m_grCtx.get(),
SkBudgeted::kYes,
SkImageInfo::MakeN32Premul(MAX(1, size.w / scale),
MAX(1, size.h / scale)),
m_sampleCount));
m_sampleCount,
nullptr);
}
if (!m_skSurface)
@ -279,13 +315,6 @@ void SkiaWindow::createRenderTarget(const gfx::Size& size)
m_display->setSkiaSurface(new SkiaSurface(m_skSurface));
}
void SkiaWindow::setSurface(SkSurface* surface)
{
if (m_skSurface && m_skSurface != m_skSurfaceDirect)
delete m_skSurface;
m_skSurface = surface;
}
#endif // SK_SUPPORT_GPU
void SkiaWindow::resizeImpl(const gfx::Size& size)

View File

@ -45,7 +45,6 @@ private:
bool attachGL();
void detachGL();
void createRenderTarget(const gfx::Size& size);
void setSurface(SkSurface* surface);
#endif // SK_SUPPORT_GPU
EventQueue* m_queue;
@ -54,10 +53,10 @@ private:
#if SK_SUPPORT_GPU
base::UniquePtr<GLContext> m_glCtx;
SkAutoTUnref<const GrGLInterface> m_glInterfaces;
SkAutoTUnref<GrContext> m_grCtx;
SkAutoTUnref<GrRenderTarget> m_grRenderTarget;
SkAutoTDelete<SkSurface> m_skSurfaceDirect;
SkSurface* m_skSurface;
sk_sp<GrContext> m_grCtx;
sk_sp<GrRenderTarget> m_grRenderTarget;
sk_sp<SkSurface> m_skSurfaceDirect;
sk_sp<SkSurface> m_skSurface;
int m_sampleCount;
int m_stencilBits;
gfx::Size m_lastSize;