Update Skia to chrome/m62 (our aseprite-m62 branch)

This commit is contained in:
David Capello 2017-09-19 13:41:28 -03:00
parent 82e1377a41
commit c5c964bfcd
21 changed files with 248 additions and 252 deletions

View File

@ -32,6 +32,9 @@ endif()
# Note: This needs to be done before the project command
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_BUILD_TYPE}" CACHE INTERNAL "internal")
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/c_flag_overrides.cmake)
set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cxx_flag_overrides.cmake)
# Aseprite project
project(aseprite C CXX)
@ -56,7 +59,6 @@ option(WITH_DEPRECATED_GLIB_SUPPORT "Enable support for older glib versions" off
option(WITH_DESKTOP_INTEGRATION "Enable desktop integration modules" off)
option(WITH_QT_THUMBNAILER "Enable kde5/qt5 thumnailer" off)
option(USE_STATIC_LIBC "Use static version of C and C++ runtimes" off)
option(USE_SHARED_CMARK "Use your installed copy of cmark" off)
option(USE_SHARED_CURL "Use your installed copy of curl" off)
option(USE_SHARED_GIFLIB "Use your installed copy of giflib" off)
@ -109,7 +111,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
endif()
if(MSVC)
set(CMAKE_C_FLAGS_PROFILE "/MD /Zi /Ox /Gd"
set(CMAKE_C_FLAGS_PROFILE "/MT /Zi /Ox /Gd"
CACHE STRING "Profiling C flags")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE}"
CACHE STRING "Profiling C++ flags")
@ -168,18 +170,6 @@ else()
add_definitions(-DNDEBUG)
endif()
if(MSVC)
if(USE_STATIC_LIBC)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MTd")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MTd")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MT")
endif()
endif()
endif()
if(NOT WIN32 AND NOT APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu89")
endif()
@ -463,10 +453,6 @@ if(ENABLE_MEMLEAK)
add_definitions(-DLAF_MEMLEAK)
endif()
if(NOT USE_STATIC_LIBC)
set(gtest_force_shared_crt ON CACHE BOOL "Use shared (DLL) run-time lib even when Google Test is built as static lib.")
endif()
set(LAF_WITH_TESTS ${ENABLE_TESTS} CACHE BOOL "Enable LAF tests")
set(UNDO_TESTS ${ENABLE_TESTS} CACHE BOOL "Enable undo tests")

View File

@ -22,7 +22,7 @@
You should be able to compile Aseprite successfully on the following
platforms:
* Windows 10 + VS2015 Community Edition + Windows 10 SDK
* Windows 10 + VS2015 or VS2017 Community Edition + Windows 10 SDK
* macOS 10.12.1 Sierra + Xcode 8.0 + macOS 10.12 SDK + Skia
* Linux + gcc 4.8 with some C++11 support
@ -71,8 +71,8 @@ Aseprite can be compiled with two different back-ends:
First of all, you will need:
* Windows 10 (we don't support cross-compiling and don't know if this would be possible)
* [VS2015 Community Edition](https://www.visualstudio.com/downloads/) (VS2017 should work too)
* Windows 10 SDK (it's included with VS2015, remember to install it)
* [Visual Studio Community Edition](https://www.visualstudio.com/downloads/) (VS2015 or VS2017)
* Windows 10 SDK (it's included with the Visual Studio installer, remember to install it)
Then, you will need an extra little utility: `awk`, used to compile
the libpng library. You can get this utility from MSYS2 distributions
@ -234,7 +234,7 @@ Skia.
You can always check the
[official Skia instructions](https://skia.org/user/quick) and select
the OS you are building for. Aseprite uses the `aseprite-m55` Skia
the OS you are building for. Aseprite uses the `aseprite-m62` Skia
branch from `https://github.com/aseprite/skia`.
## Skia on Windows
@ -243,9 +243,15 @@ Download
[Google depot tools](https://storage.googleapis.com/chrome-infra/depot_tools.zip)
and uncompress it in some place like `C:\deps\depot_tools`.
Then open a command line follow these steps (for VS2015):
Then open a command line follow these steps:
For VS2015:
call "%VS140COMNTOOLS%\vsvars32.bat"
For VS2017:
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat"
Then:
set PATH=C:\deps\depot_tools;%PATH%
cd C:\deps\depot_tools
gclient sync
@ -257,16 +263,22 @@ Just ignore it.)
cd C:\deps
git clone https://github.com/aseprite/skia.git
cd skia
git checkout aseprite-m55
python bin/sync-and-gyp
git checkout aseprite-m62
python tools/git-sync-deps
(The `bin/sync-and-gyp` will take some minutes because it downloads a
(The `tools/git-sync-deps` will take some minutes because it downloads a
lot of packages, please wait and re-run the same command in case it fails.)
ninja -C out/Release dm
For VS2015:
gn gen out/Release --args="is_official_build=true skia_use_system_expat=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false target_cpu=""x86"""
ninja -C out/Release
For VS2017:
gn gen out/Release --args="is_official_build=true skia_use_system_expat=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false target_cpu=""x86"" msvc=2017"
ninja -C out/Release
More information about these steps in the
[official Skia documentation](https://skia.org/user/quick/windows).
[official Skia documentation](https://skia.org/user/build).
## Skia on macOS
@ -281,9 +293,10 @@ several minutes to finish:
git clone https://github.com/aseprite/skia.git
export PATH="${PWD}/depot_tools:${PATH}"
cd skia
git checkout aseprite-m55
python bin/sync-and-gyp
ninja -C out/Release dm
git checkout aseprite-m62
python tools/git-sync-deps
gn gen out/Release --args="is_official_build=true skia_use_system_expat=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false"
ninja -C out/Release
After this you should have all Skia libraries compiled. When you
[compile Aseprite](#compiling), remember to add
@ -291,4 +304,4 @@ After this you should have all Skia libraries compiled. When you
described in the [macOS details](#macos-details) section.
More information about these steps in the
[official Skia documentation](https://skia.org/user/quick/macos).
[official Skia documentation](https://skia.org/user/build).

View File

@ -0,0 +1,6 @@
if(MSVC)
set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
endif()

View File

@ -0,0 +1,6 @@
if(MSVC)
set(CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
endif()

View File

@ -243,12 +243,10 @@ void BrushPreview::show(const gfx::Point& screenPos)
if (!(m_type & NATIVE_CROSSHAIR) ||
(m_type & BRUSH_BOUNDARIES)) {
ui::ScreenGraphics g;
ui::SetClip clip(&g, gfx::Rect(0, 0, g.width(), g.height()));
ui::SetClip clip(&g);
gfx::Color uiCursorColor = color_utils::color_for_ui(appCursorColor);
forEachBrushPixel(&g, m_screenPosition, spritePos, uiCursorColor, &BrushPreview::savePixelDelegate);
forEachBrushPixel(&g, m_screenPosition, spritePos, uiCursorColor, &BrushPreview::drawPixelDelegate);
m_withModifiedPixels = true;
}
@ -287,8 +285,7 @@ void BrushPreview::hide()
if (m_withModifiedPixels) {
// Restore pixels
ui::ScreenGraphics g;
ui::SetClip clip(&g, gfx::Rect(0, 0, g.width(), g.height()));
ui::SetClip clip(&g);
forEachBrushPixel(&g, m_screenPosition, m_editorPosition, gfx::ColorNone,
&BrushPreview::clearPixelDelegate);
}

View File

@ -635,7 +635,7 @@ void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& sprite
if (tmp)
tmp->dispose();
tmp = she::instance()->createRgbaSurface(rc.w, rc.h);
tmp = she::instance()->createSurface(rc.w, rc.h);
}
if (tmp->nativeHandle()) {

View File

@ -113,9 +113,7 @@ void EditorView::onSetViewScroll(const gfx::Point& pt)
{
Editor* editor = this->editor();
if (editor) {
// We have to hide the brush preview to scroll (without this,
// keyboard shortcuts to scroll when the brush preview is visible
// will leave brush previews all over the screen).
// Hide the brush preview to avoid leaving a cursor trail.
HideBrushPreview hide(editor->brushPreview());
View::onSetViewScroll(pt);
}

View File

@ -19,6 +19,10 @@
// Disable warning C4355 in MSVC: 'this' used in base member initializer list
#pragma warning(disable:4355)
// Disable warning C4710 in MSVC: function not inlined (generated by MSVC header files)
// https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4710
#pragma warning(disable:4710)
#endif
// General information

View File

@ -53,7 +53,8 @@ if(USE_SKIA_BACKEND)
-DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1
-DSK_SUPPORT_OPENCL=0
-DSK_FORCE_DISTANCE_FIELD_TEXT=0
-DGR_GL_FUNCTION_TYPE=__stdcall)
-DGR_GL_FUNCTION_TYPE=__stdcall
-DSK_SUPPORT_GPU=1)
if(WIN32)
add_definitions(-DSK_BUILD_FOR_WIN32)
@ -69,61 +70,15 @@ if(USE_SKIA_BACKEND)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(SKIA_BUILD_OUT_DIR "${SKIA_DIR}/out/Debug")
add_definitions(-DSK_DEVELOPER=1)
else()
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_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_AVX_LIBRARY skia_opts_avx PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_OPTS_HSW_LIBRARY skia_opts_hsw 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_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_DEMUX_LIBRARY webp_demux NAMES libwebp_demux 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_DSP_ENC_LIBRARY webp_dsp_enc NAMES libwebp_dsp_enc PATHS "${SKIA_BUILD_OUT_DIR}" "${SKIA_BUILD_OUT_DIR}/obj/gyp" NO_DEFAULT_PATH)
find_library(SKIA_WEBP_ENC_LIBRARY webp_enc NAMES libwebp_enc 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)
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()
find_library(SKIA_LIBRARY skia PATH "${SKIA_BUILD_OUT_DIR}")
if(WIN32)
find_library(SKIA_OPENGL_LIBRARY opengl32)
else()
add_definitions(-DSK_SUPPORT_GPU=0)
set(SKIA_GPU_LIBRARY "")
set(SKIA_OPENGL_LIBRARY "")
endif()
if(NOT SKIA_LIBEGL_LIBRARY)
set(SKIA_LIBEGL_LIBRARY "")
find_library(SKIA_OPENGL_LIBRARY opengl NAMES GL)
endif()
find_path(SKIA_CONFIG_INCLUDE_DIR SkUserConfig.h HINTS "${SKIA_DIR}/include/config")
@ -131,60 +86,25 @@ if(USE_SKIA_BACKEND)
find_path(SKIA_UTILS_INCLUDE_DIR SkRandom.h HINTS "${SKIA_DIR}/include/utils")
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")
endif()
find_path(SKIA_GPU_INCLUDE_DIR GrContext.h HINTS "${SKIA_DIR}/include/gpu")
find_path(SKIA_GPU2_INCLUDE_DIR gl/GrGLDefines.h HINTS "${SKIA_DIR}/src/gpu")
find_path(SKIA_ANGLE_INCLUDE_DIR angle_gl.h HINTS "${SKIA_DIR}/third_party/externals/angle2/include")
include_directories(
${SKIA_CONFIG_INCLUDE_DIR}
${SKIA_CORE_INCLUDE_DIR}
${SKIA_PORTS_INCLUDE_DIR}
${SKIA_UTILS_INCLUDE_DIR}
${SKIA_CODEC_INCLUDE_DIR})
if(SKIA_GPU_LIBRARY)
include_directories(${SKIA_GPU_INCLUDE_DIR})
if(WIN32)
include_directories(${SKIA_ANGLE_INCLUDE_DIR})
endif()
${SKIA_CODEC_INCLUDE_DIR}
${SKIA_GPU_INCLUDE_DIR}
${SKIA_GPU2_INCLUDE_DIR})
if(WIN32)
include_directories(${SKIA_ANGLE_INCLUDE_DIR})
endif()
set(SKIA_LIBRARIES
${SKIA_CORE_LIBRARY}
${SKIA_IMAGES_LIBRARY}
${SKIA_OPTS_LIBRARY}
${SKIA_OPTS_SSSE3_LIBRARY}
${SKIA_OPTS_SSE41_LIBRARY}
${SKIA_OPTS_SSE42_LIBRARY}
${SKIA_OPTS_HSW_LIBRARY}
${SKIA_OPTS_AVX_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_DEMUX_LIBRARY}
${SKIA_WEBP_DSP_LIBRARY}
${SKIA_WEBP_DSP_ENC_LIBRARY}
${SKIA_WEBP_ENC_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_UTILS_LIBRARY}
${SKIA_SFNT_LIBRARY}
${SKIA_LIBRARY}
${SKIA_OPENGL_LIBRARY}
${SKIA_LIBEGL_LIBRARY}
${SKIA_SKKTX_LIBRARY}
${SKIA_ETC1_LIBRARY}
${SKIA_FLAGS_LIBRARY}
CACHE INTERNAL "Skia libraries")
list(APPEND SHE_SOURCES

View File

@ -83,6 +83,7 @@ Alleg4Surface::Alleg4Surface(BITMAP* bmp, DestroyFlag destroy)
, m_destroy(destroy)
, m_lock(0)
{
saveClip();
}
Alleg4Surface::Alleg4Surface(int width, int height, DestroyFlag destroy)
@ -90,6 +91,7 @@ Alleg4Surface::Alleg4Surface(int width, int height, DestroyFlag destroy)
, m_destroy(destroy)
, m_lock(0)
{
saveClip();
}
Alleg4Surface::Alleg4Surface(int width, int height, int bpp, DestroyFlag destroy)
@ -97,6 +99,7 @@ Alleg4Surface::Alleg4Surface(int width, int height, int bpp, DestroyFlag destroy
, m_destroy(destroy)
, m_lock(0)
{
saveClip();
}
Alleg4Surface::~Alleg4Surface()
@ -131,7 +134,12 @@ bool Alleg4Surface::isDirectToScreen() const
return m_bmp == screen;
}
gfx::Rect Alleg4Surface::getClipBounds()
int Alleg4Surface::getSaveCount() const
{
return int(m_clipStack.size());
}
gfx::Rect Alleg4Surface::getClipBounds() const
{
return gfx::Rect(
m_bmp->cl,
@ -140,8 +148,18 @@ gfx::Rect Alleg4Surface::getClipBounds()
m_bmp->cb - m_bmp->ct);
}
void Alleg4Surface::setClipBounds(const gfx::Rect& rc)
void Alleg4Surface::saveClip()
{
m_clipStack.push_back(getClipBounds());
}
void Alleg4Surface::restoreClip()
{
ASSERT(!m_clipStack.empty());
gfx::Rect rc = m_clipStack.back();
m_clipStack.pop_back();
set_clip_rect(m_bmp,
rc.x,
rc.y,
@ -149,7 +167,7 @@ void Alleg4Surface::setClipBounds(const gfx::Rect& rc)
rc.y+rc.h-1);
}
bool Alleg4Surface::intersectClipRect(const gfx::Rect& rc)
bool Alleg4Surface::clipRect(const gfx::Rect& rc)
{
add_clip_rect(m_bmp,
rc.x,

View File

@ -9,7 +9,9 @@
#pragma once
#include <allegro.h>
#include <vector>
#include "gfx/rect.h"
#include "she/surface.h"
#include "she/common/generic_surface.h"
@ -34,9 +36,11 @@ namespace she {
int width() const override;
int height() const override;
bool isDirectToScreen() const override;
gfx::Rect getClipBounds() override;
void setClipBounds(const gfx::Rect& rc) override;
bool intersectClipRect(const gfx::Rect& rc) override;
int getSaveCount() const override;
gfx::Rect getClipBounds() const override;
void saveClip() override;
void restoreClip() override;
bool clipRect(const gfx::Rect& rc) override;
void lock() override;
void unlock() override;
void setDrawMode(DrawMode mode, int param,
@ -64,6 +68,7 @@ namespace she {
BITMAP* m_bmp;
DestroyFlag m_destroy;
int m_lock;
std::vector<gfx::Rect> m_clipStack;
};
} // namespace she

View File

@ -23,6 +23,7 @@
#include "ft/lib.h"
#include "she/common/freetype_font.h"
#include "she/common/sprite_sheet_font.h"
#include "she/menus.h"
#include "she/system.h"
namespace she {

View File

@ -16,6 +16,8 @@
#include "SkPixelRef.h"
#include "SkStream.h"
#include <memory>
namespace she {
sk_sp<SkColorSpace> SkiaSurface::m_colorSpace;
@ -23,11 +25,9 @@ sk_sp<SkColorSpace> SkiaSurface::m_colorSpace;
// static
Surface* SkiaSurface::loadSurface(const char* filename)
{
base::FileHandle fp(base::open_file_with_exception(filename, "rb"));
SkAutoTDelete<SkCodec> codec(
SkCodec::NewFromStream(
new SkFILEStream(fp.get(), SkFILEStream::kCallerRetains_Ownership)));
std::unique_ptr<SkCodec> codec(
SkCodec::MakeFromStream(
std::unique_ptr<SkFILEStream>(new SkFILEStream(base::open_file_raw(filename, "rb")))));
if (!codec)
return nullptr;

View File

@ -41,7 +41,6 @@ public:
SkiaSurface(const sk_sp<SkSurface>& surface)
: m_surface(surface)
, m_canvas(nullptr)
, m_clip(0, 0, width(), height())
, m_lock(0)
{
ASSERT(m_surface);
@ -107,19 +106,29 @@ public:
return false;
}
gfx::Rect getClipBounds() override {
return m_clip;
int getSaveCount() const override {
return m_canvas->getSaveCount();
}
void setClipBounds(const gfx::Rect& rc) override {
m_clip = rc;
m_canvas->clipRect(SkRect::Make(to_skia(m_clip)), kReplace_SkClipOp);
gfx::Rect getClipBounds() const override {
SkIRect rc;
if (m_canvas->getDeviceClipBounds(&rc))
return gfx::Rect(rc.x(), rc.y(), rc.width(), rc.height());
else
return gfx::Rect();
}
bool intersectClipRect(const gfx::Rect& rc) override {
m_clip &= rc;
m_canvas->clipRect(SkRect::Make(to_skia(m_clip)), kReplace_SkClipOp);
return !m_clip.isEmpty();
void saveClip() override {
m_canvas->save();
}
void restoreClip() override {
m_canvas->restore();
}
bool clipRect(const gfx::Rect& rc) override {
m_canvas->clipRect(SkRect::Make(to_skia(rc)));
return !m_canvas->isClipEmpty();
}
void setDrawMode(DrawMode mode, int param,
@ -142,14 +151,12 @@ public:
throw base::Exception("Cannot create temporary Skia surface");
{
bitmap.lockPixels();
SkPMColor A = SkPreMultiplyARGB(gfx::geta(a), gfx::getr(a), gfx::getg(a), gfx::getb(a));
SkPMColor B = SkPreMultiplyARGB(gfx::geta(b), gfx::getr(b), gfx::getg(b), gfx::getb(b));
int offset = 7 - (param & 7);
for (int y=0; y<8; y++)
for (int x=0; x<8; x++)
*bitmap.getAddr32(x, y) = (((x+y+offset)&7) < 4 ? B: A);
bitmap.unlockPixels();
}
sk_sp<SkShader> shader(
@ -166,14 +173,16 @@ public:
void lock() override {
ASSERT(m_lock >= 0);
if (m_lock++ == 0)
m_bitmap.lockPixels();
if (m_lock++ == 0) {
// m_bitmap is always locked
}
}
void unlock() override {
ASSERT(m_lock > 0);
if (--m_lock == 0)
m_bitmap.unlockPixels();
if (--m_lock == 0) {
// m_bitmap is always locked
}
}
void applyScale(int scaleFactor) override {
@ -181,9 +190,9 @@ public:
SkBitmap result;
if (!result.tryAllocPixels(
SkImageInfo::Make(width()*scaleFactor, height()*scaleFactor,
m_bitmap.info().colorType(),
m_bitmap.info().alphaType())))
m_bitmap.info().makeWH(
width()*scaleFactor,
height()*scaleFactor)))
throw base::Exception("Cannot create temporary Skia surface to change scale");
SkPaint paint;
@ -207,7 +216,10 @@ public:
}
uint8_t* getData(int x, int y) const override {
return (uint8_t*)m_bitmap.getAddr(x, y);
if (m_bitmap.isNull())
return nullptr;
else
return (uint8_t*)m_bitmap.getAddr32(x, y);
}
void getFormat(SurfaceFormatData* formatData) const override {
@ -256,7 +268,6 @@ public:
formatData->alphaMask = (255 << SK_BGRA_A32_SHIFT);
break;
default:
ASSERT(false);
formatData->redShift = 0;
formatData->greenShift = 0;
formatData->blueShift = 0;
@ -326,12 +337,19 @@ public:
m_canvas->drawIRect(to_skia(rc), m_paint);
}
void blitTo(Surface* dest, int srcx, int srcy, int dstx, int dsty, int width, int height) const override {
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height, colorSpace());
std::vector<uint32_t> pixels(width * height * 4);
m_canvas->readPixels(info, (void*)&pixels[0], 4*width, srcx, srcy);
static_cast<SkiaSurface*>(dest)
->m_canvas->writePixels(info, (void*)&pixels[0], 4*width, dstx, dsty);
void blitTo(Surface* _dst, int srcx, int srcy, int dstx, int dsty, int width, int height) const override {
ASSERT(!m_bitmap.empty());
auto dst = static_cast<SkiaSurface*>(_dst);
SkIRect srcRect = SkIRect::MakeXYWH(srcx, srcy, width, height);
SkRect dstRect = SkRect::Make(SkIRect::MakeXYWH(dstx, dsty, width, height));
SkPaint paint;
paint.setBlendMode(SkBlendMode::kSrc);
dst->m_canvas->drawBitmapRect(m_bitmap, srcRect, dstRect, &paint,
SkCanvas::kStrict_SrcRectConstraint);
}
void scrollTo(const gfx::Rect& rc, int dx, int dy) override {
@ -371,6 +389,8 @@ public:
dst += rowDelta;
src += rowDelta;
}
m_bitmap.notifyPixelsChanged();
}
void drawSurface(const Surface* src, int dstx, int dsty) override {
@ -446,13 +466,12 @@ public:
}
sk_sp<SkColorFilter> colorFilter(
SkColorFilter::MakeModeFilter(to_skia(fg), SkXfermode::kSrcIn_Mode));
SkColorFilter::MakeModeFilter(to_skia(fg), SkBlendMode::kSrcIn));
paint.setColorFilter(colorFilter);
m_canvas->drawBitmapRect(
((SkiaSurface*)src)->m_bitmap,
srcRect, dstRect, &paint,
SkCanvas::kStrict_SrcRectConstraint);
srcRect, dstRect, &paint);
}
SkBitmap& bitmap() {
@ -474,7 +493,6 @@ private:
delete m_canvas;
m_canvas = new SkCanvas(m_bitmap);
m_clip = gfx::Rect(0, 0, width(), height());
}
static sk_sp<SkColorSpace> colorSpace();
@ -483,7 +501,6 @@ private:
sk_sp<SkSurface> m_surface;
SkCanvas* m_canvas;
SkPaint m_paint;
gfx::Rect m_clip;
int m_lock;
static sk_sp<SkColorSpace> m_colorSpace;

View File

@ -25,7 +25,9 @@
#if SK_SUPPORT_GPU
#include "GrBackendSurface.h"
#include "GrContext.h"
#include "gl/GrGLDefines.h"
#include "gl/GrGLInterface.h"
#include "she/gl/gl_context_cgl.h"
#include "she/skia/skia_surface.h"
@ -166,14 +168,6 @@ public:
}
void onDrawRect(const gfx::Rect& rect) override {
#if SK_SUPPORT_GPU
// Flush operations to the SkCanvas
if (m_display->isInitialized()) {
SkiaSurface* surface = static_cast<SkiaSurface*>(m_display->getSurface());
surface->flush();
}
#endif
switch (m_backend) {
case Backend::NONE:
@ -182,6 +176,7 @@ public:
#if SK_SUPPORT_GPU
case Backend::GL:
// TODO
if (m_nsGL)
[m_nsGL flushBuffer];
break;
@ -201,7 +196,7 @@ private:
bool attachGL() {
if (!m_glCtx) {
try {
SkAutoTDelete<GLContext> ctx(new GLContextCGL);
base::UniquePtr<GLContext> ctx(new GLContextCGL);
if (!ctx->createGLContext())
throw std::runtime_error("Cannot create CGL context");
@ -212,7 +207,9 @@ private:
return false;
}
m_glCtx.reset(ctx);
m_glCtx.reset(ctx.get());
ctx.release();
m_grCtx.reset(GrContext::Create(kOpenGL_GrBackend,
(GrBackendContext)m_glInterfaces.get()));
@ -242,26 +239,35 @@ private:
}
void createRenderTarget(const gfx::Size& size) {
int scale = this->scale();
const int scale = this->scale();
m_lastSize = size;
GrBackendRenderTargetDesc desc;
desc.fWidth = size.w;
desc.fHeight = size.h;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fSampleCnt = m_glCtx->getSampleCount();
desc.fStencilBits = m_glCtx->getStencilBits();
desc.fRenderTargetHandle = 0; // direct frame buffer
GrGLint buffer;
m_glInterfaces->fFunctions.fGetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &buffer);
GrGLFramebufferInfo info;
info.fFBOID = (GrGLuint)buffer;
GrBackendRenderTarget
target(size.w, size.h,
m_glCtx->getSampleCount(),
m_glCtx->getStencilBits(),
kSkia8888_GrPixelConfig,
info);
SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
m_skSurface.reset(nullptr); // set m_skSurface comparing with the old m_skSurfaceDirect
m_skSurfaceDirect = SkSurface::MakeFromBackendRenderTarget(
m_grCtx.get(), desc, nullptr);
m_grCtx.get(), target,
kBottomLeft_GrSurfaceOrigin,
nullptr, &props);
if (scale == 1) {
if (scale == 1 && m_skSurfaceDirect) {
LOG("OS: Using GL direct surface\n");
m_skSurface = m_skSurfaceDirect;
}
else {
LOG("OS: Using double buffering\n");
m_skSurface =
SkSurface::MakeRenderTarget(
m_grCtx.get(),
@ -305,7 +311,6 @@ private:
rect.h/scale)))
return;
bitmap.lockPixels();
@autoreleasepool {
NSGraphicsContext* gc = [NSGraphicsContext currentContext];
CGContextRef cg = (CGContextRef)[gc graphicsPort];
@ -324,7 +329,6 @@ private:
}
CGColorSpaceRelease(colorSpace);
}
bitmap.unlockPixels();
}
SkiaDisplay* m_display;
@ -333,7 +337,7 @@ private:
OSXWindow* m_window;
#if SK_SUPPORT_GPU
base::UniquePtr<GLContext> m_glCtx;
SkAutoTUnref<const GrGLInterface> m_glInterfaces;
sk_sp<const GrGLInterface> m_glInterfaces;
NSOpenGLContext* m_nsGL;
sk_sp<GrContext> m_grCtx;
sk_sp<SkSurface> m_skSurfaceDirect;

View File

@ -1,5 +1,5 @@
// SHE library
// Copyright (C) 2012-2016 David Capello
// Copyright (C) 2012-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -15,9 +15,13 @@
#include "she/skia/skia_display.h"
#include "she/system.h"
#undef max // To avoid include/private/SkPathRef.h(451): error C2589: '(': illegal token on right side of '::'
#if SK_SUPPORT_GPU
#include "GrBackendSurface.h"
#include "GrContext.h"
#include "gl/GrGLDefines.h"
#include "she/gl/gl_context_wgl.h"
#if SK_ANGLE
#include "she/gl/gl_context_egl.h"
@ -26,12 +30,8 @@
#endif
#ifdef _WIN32
#include <windows.h>
#include "she/win/window_dde.h"
#endif
#include <windows.h>
#include "she/win/window_dde.h"
#include <iostream>
@ -97,6 +97,7 @@ void SkiaWindow::paintImpl(HDC hdc)
// If we are drawing inside an off-screen texture, here we have
// to blit that texture into the main framebuffer.
if (m_skSurfaceDirect != m_skSurface) {
#if 0 // TODO
GrBackendObject texID = m_skSurface->getTextureHandle(
SkSurface::kFlushRead_BackendHandleAccess);
@ -119,6 +120,7 @@ void SkiaWindow::paintImpl(HDC hdc)
SkCanvas::kStrict_SrcRectConstraint);
m_skSurfaceDirect->getCanvas()->flush();
#endif
}
// Flush GL context
@ -146,7 +148,6 @@ void SkiaWindow::paintHDC(HDC hdc)
bmi.bmiHeader.biSizeImage = 0;
ASSERT(bitmap.width() * bitmap.bytesPerPixel() == bitmap.rowBytes());
bitmap.lockPixels();
int ret = StretchDIBits(hdc,
0, 0, bitmap.width()*scale(), bitmap.height()*scale(),
@ -154,8 +155,6 @@ void SkiaWindow::paintHDC(HDC hdc)
bitmap.getPixels(),
&bmi, DIB_RGB_COLORS, SRCCOPY);
(void)ret;
bitmap.unlockPixels();
}
#if SK_SUPPORT_GPU
@ -281,18 +280,25 @@ void SkiaWindow::createRenderTarget(const gfx::Size& size)
int scale = m_display->scale();
m_lastSize = size;
GrBackendRenderTargetDesc desc;
desc.fWidth = size.w;
desc.fHeight = size.h;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fSampleCnt = m_sampleCount;
desc.fStencilBits = m_stencilBits;
desc.fRenderTargetHandle = 0; // direct frame buffer
GrGLint buffer;
m_glInterfaces->fFunctions.fGetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &buffer);
GrGLFramebufferInfo info;
info.fFBOID = (GrGLuint) buffer;
GrBackendRenderTarget
target(size.w, size.h,
m_sampleCount,
m_stencilBits,
kSkia8888_GrPixelConfig,
info);
SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
m_skSurface.reset(nullptr); // set m_skSurface comparing with the old m_skSurfaceDirect
m_skSurfaceDirect = SkSurface::MakeFromBackendRenderTarget(
m_grCtx.get(), desc, nullptr);
m_grCtx.get(), target,
kBottomLeft_GrSurfaceOrigin,
nullptr, &props);
if (scale == 1) {
m_skSurface = m_skSurfaceDirect;

View File

@ -1,5 +1,5 @@
// SHE library
// Copyright (C) 2012-2016 David Capello
// Copyright (C) 2012-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -52,7 +52,7 @@ private:
Backend m_backend;
#if SK_SUPPORT_GPU
base::UniquePtr<GLContext> m_glCtx;
SkAutoTUnref<const GrGLInterface> m_glInterfaces;
sk_sp<const GrGLInterface> m_glInterfaces;
sk_sp<GrContext> m_grCtx;
sk_sp<SkSurface> m_skSurfaceDirect;
sk_sp<SkSurface> m_skSurface;

View File

@ -34,9 +34,11 @@ namespace she {
virtual int height() const = 0;
virtual bool isDirectToScreen() const = 0;
virtual gfx::Rect getClipBounds() = 0;
virtual void setClipBounds(const gfx::Rect& rc) = 0;
virtual bool intersectClipRect(const gfx::Rect& rc) = 0;
virtual int getSaveCount() const = 0;
virtual gfx::Rect getClipBounds() const = 0;
virtual void saveClip() = 0;
virtual void restoreClip() = 0;
virtual bool clipRect(const gfx::Rect& rc) = 0;
virtual void setDrawMode(DrawMode mode, int param = 0,
const gfx::Color a = gfx::ColorNone,

View File

@ -54,19 +54,29 @@ int Graphics::height() const
return m_surface->height();
}
int Graphics::getSaveCount() const
{
return m_surface->getSaveCount();
}
gfx::Rect Graphics::getClipBounds() const
{
return m_surface->getClipBounds().offset(-m_dx, -m_dy);
}
void Graphics::setClipBounds(const gfx::Rect& rc)
void Graphics::saveClip()
{
m_surface->setClipBounds(gfx::Rect(rc).offset(m_dx, m_dy));
m_surface->saveClip();
}
bool Graphics::intersectClipRect(const gfx::Rect& rc)
void Graphics::restoreClip()
{
return m_surface->intersectClipRect(gfx::Rect(rc).offset(m_dx, m_dy));
m_surface->restoreClip();
}
bool Graphics::clipRect(const gfx::Rect& rc)
{
return m_surface->clipRect(gfx::Rect(rc).offset(m_dx, m_dy));
}
void Graphics::setDrawMode(DrawMode mode, int param,

View File

@ -49,9 +49,11 @@ namespace ui {
int getInternalDeltaX() { return m_dx; }
int getInternalDeltaY() { return m_dy; }
int getSaveCount() const;
gfx::Rect getClipBounds() const;
void setClipBounds(const gfx::Rect& rc);
bool intersectClipRect(const gfx::Rect& rc);
void saveClip();
void restoreClip();
bool clipRect(const gfx::Rect& rc);
void setDrawMode(DrawMode mode, int param = 0,
const gfx::Color a = gfx::ColorNone,
@ -119,25 +121,29 @@ namespace ui {
virtual ~ScreenGraphics();
};
// Class to temporary set the Graphics' clip region (in the
// life-time of the SetClip instance).
// Class to temporary set the Graphics' clip region to the full
// extend.
class SetClip {
public:
SetClip(Graphics* g, const gfx::Rect& rc)
SetClip(Graphics* g)
: m_graphics(g)
, m_oldClip(g->getClipBounds())
{
m_graphics->setClipBounds(rc);
, m_oldCount(g->getSaveCount()) {
if (m_oldCount > 1)
m_graphics->restoreClip();
}
~SetClip()
{
m_graphics->setClipBounds(m_oldClip);
~SetClip() {
if (m_oldCount > 1) {
m_graphics->saveClip();
m_graphics->clipRect(m_oldClip);
}
}
private:
Graphics* m_graphics;
gfx::Rect m_oldClip;
int m_oldCount;
DISABLE_COPYING(SetClip);
};
@ -147,22 +153,19 @@ namespace ui {
class IntersectClip {
public:
IntersectClip(Graphics* g, const gfx::Rect& rc)
: m_graphics(g)
, m_oldClip(g->getClipBounds())
{
m_notEmpty = m_graphics->intersectClipRect(rc);
: m_graphics(g) {
m_graphics->saveClip();
m_notEmpty = m_graphics->clipRect(rc);
}
~IntersectClip()
{
m_graphics->setClipBounds(m_oldClip);
~IntersectClip() {
m_graphics->restoreClip();
}
operator bool() const { return m_notEmpty; }
private:
Graphics* m_graphics;
gfx::Rect m_oldClip;
bool m_notEmpty;
DISABLE_COPYING(IntersectClip);

View File

@ -1403,9 +1403,9 @@ bool Manager::sendMessageToWidget(Message* msg, Widget* widget)
PaintMessage* paintMsg = static_cast<PaintMessage*>(msg);
she::Surface* surface = m_display->getSurface();
gfx::Rect oldClip = surface->getClipBounds();
surface->saveClip();
if (surface->intersectClipRect(paintMsg->rect())) {
if (surface->clipRect(paintMsg->rect())) {
#ifdef REPORT_EVENTS
std::cout << " - clip("
<< paintMsg->rect().x << ", "
@ -1432,7 +1432,7 @@ bool Manager::sendMessageToWidget(Message* msg, Widget* widget)
used = widget->sendMessage(msg);
// Restore clip region for paint messages.
surface->setClipBounds(oldClip);
surface->restoreClip();
}
}