Permalink
Browse files

Merge branch 'skia'

  • Loading branch information...
dacap committed May 26, 2015
2 parents 6a8dfad + 9dd8d0d commit 26b170e67f5d2796bb7fb2209c996724e0b83d87
@@ -55,10 +55,10 @@ std::string show_file_selector(const std::string& title,
dlg->addFilter("*." + tok, tok + " files (*." + tok + ")");
dlg->addFilter("*.*", "All files (*.*)");
if (dlg->show(she::instance()->defaultDisplay()->nativeHandle())) {
if (dlg->show(she::instance()->defaultDisplay()->nativeHandle()))
res = dlg->getFileName();
dlg->dispose();
}
dlg->dispose();
return res;
}
}
View
@@ -19,20 +19,30 @@ if(USE_ALLEG4_BACKEND)
endif()
if(USE_SKIA_BACKEND)
set(SKIA_BUILD_DIR "" CACHE PATH "Skia build directory")
set(SKIA_DIR "" CACHE PATH "Skia source code directory")
add_definitions(
-DSK_INTERNAL
-DSK_GAMMA_SRGB
-DSK_GAMMA_APPLY_TO_A8
-DSK_SCALAR_TO_FLOAT_EXCLUDED
-DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1
-DSK_SUPPORT_GPU=1
-DSK_SUPPORT_OPENCL=0
-DSK_FORCE_DISTANCE_FIELD_TEXT=0
-DGR_GL_FUNCTION_TYPE=__stdcall)
add_definitions(-DSK_INTERNAL -DSK_GAMMA_SRGB -DSK_GAMMA_APPLY_TO_A8 -DSK_SCALAR_TO_FLOAT_EXCLUDED -DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1 -DSK_SUPPORT_GPU=1 -DSK_SUPPORT_OPENCL=0 -DSK_FORCE_DISTANCE_FIELD_TEXT=0 -DGR_GL_FUNCTION_TYPE=__stdcall)
if(WIN32)
add_definitions(-DSK_BUILD_FOR_WIN32)
elseif(APPLE)
add_definitions(-DSK_BUILD_FOR_MAC)
endif()
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(SKIA_BUILD_OUT_DIR "${SKIA_BUILD_DIR}/out/Debug")
set(SKIA_BUILD_OUT_DIR "${SKIA_DIR}/out/Debug")
add_definitions(-DSK_DEVELOPER=1)
else()
set(SKIA_BUILD_OUT_DIR "${SKIA_BUILD_DIR}/out/Release")
set(SKIA_BUILD_OUT_DIR "${SKIA_DIR}/out/Release")
endif()
find_library(SKIA_CORE_LIBRARY skia_core PATH "${SKIA_BUILD_OUT_DIR}")
@@ -46,34 +56,46 @@ if(USE_SKIA_BACKEND)
find_library(SKIA_GPU_LIBRARY skia_skgpu PATH "${SKIA_BUILD_OUT_DIR}")
find_library(SKIA_UTILS_LIBRARY skia_utils PATH "${SKIA_BUILD_OUT_DIR}")
set(SKIA_LIBEGL_LIBRARY "")
if(WIN32)
find_library(ETC1_LIBRARY libetc1 PATH "${SKIA_BUILD_OUT_DIR}/obj/gyp")
find_library(LIBSKKTX_LIBRARY libSkKTX PATH "${SKIA_BUILD_OUT_DIR}/obj/gyp")
find_library(OPENGL32_LIBRARY opengl32)
find_library(SKIA_ETC1_LIBRARY libetc1 PATH "${SKIA_BUILD_OUT_DIR}/obj/gyp")
find_library(SKIA_LIBSKKTX_LIBRARY libSkKTX PATH "${SKIA_BUILD_OUT_DIR}/obj/gyp")
find_library(SKIA_OPENGL32_LIBRARY opengl32)
find_library(SKIA_LIBEGL_LIBRARY libEGL.dll.lib PATH "${SKIA_BUILD_OUT_DIR}")
if(SKIA_LIBEGL_LIBRARY)
add_definitions(-DSK_ANGLE=1)
endif()
else()
set(ETC1_LIBRARY)
set(LIBSKKTX_LIBRARY)
# find_library(OPENGL32_LIBRARY glapi)
set(OPENGL32_LIBRARY)
set(SKIA_ETC1_LIBRARY)
set(SKIA_LIBSKKTX_LIBRARY)
# find_library(SKIA_OPENGL32_LIBRARY glapi)
set(SKIA_OPENGL32_LIBRARY)
endif()
find_path(SKIA_CONFIG_INCLUDE_DIR SkUserConfig.h HINTS "${SKIA_BUILD_DIR}/include/config")
find_path(SKIA_CORE_INCLUDE_DIR SkCanvas.h HINTS "${SKIA_BUILD_DIR}/include/core")
find_path(SKIA_EFFECTS_INCLUDE_DIR SkBitmapSource.h HINTS "${SKIA_BUILD_DIR}/include/effects")
find_path(SKIA_GPU_INCLUDE_DIR SkGr.h HINTS "${SKIA_BUILD_DIR}/include/gpu")
find_path(SKIA_UTILS_INCLUDE_DIR SkRandom.h HINTS "${SKIA_BUILD_DIR}/include/utils")
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_EFFECTS_INCLUDE_DIR SkBitmapSource.h HINTS "${SKIA_DIR}/include/effects")
find_path(SKIA_GPU_INCLUDE_DIR SkGr.h HINTS "${SKIA_DIR}/include/gpu")
find_path(SKIA_UTILS_INCLUDE_DIR SkRandom.h HINTS "${SKIA_DIR}/include/utils")
set(SKIA_ANGLE_INCLUDE_DIR "")
if(WIN32)
find_path(SKIA_ANGLE_INCLUDE_DIR angle_gl.h HINTS "${SKIA_DIR}/third_party/externals/angle2/include")
endif()
include_directories(
${SKIA_CONFIG_INCLUDE_DIR}
${SKIA_CORE_INCLUDE_DIR}
${SKIA_GPU_INCLUDE_DIR}
${SKIA_PORTS_INCLUDE_DIR}
${SKIA_UTILS_INCLUDE_DIR})
${SKIA_UTILS_INCLUDE_DIR}
${SKIA_ANGLE_INCLUDE_DIR})
set(SKIA_LIBRARIES
${ETC1_LIBRARY}
${LIBSKKTX_LIBRARY}
${OPENGL32_LIBRARY}
${SKIA_ETC1_LIBRARY}
${SKIA_LIBSKKTX_LIBRARY}
${SKIA_OPENGL32_LIBRARY}
${SKIA_LIBEGL_LIBRARY}
${SKIA_CORE_LIBRARY}
${SKIA_EFFECTS_LIBRARY}
${SKIA_GPU_LIBRARY}
@@ -87,11 +109,11 @@ if(USE_SKIA_BACKEND)
list(APPEND SHE_SOURCES
skia/skia_display.cpp
skia/skia_window.cpp
skia/she.cpp)
if(WIN32)
list(APPEND SHE_SOURCES
skia/skia_window_win.cpp
win/vk.cpp)
endif()
endif()
View
@@ -135,7 +135,7 @@ class Alleg4EventQueue : public EventQueue {
event.setType(Event::None);
}
void queueEvent(const Event& event) {
void queueEvent(const Event& event) override {
m_events.push(event);
}
View
@@ -349,6 +349,13 @@ namespace she {
width, height);
}
void scrollTo(const gfx::Rect& rc, int dx, int dy) override {
blit(m_bmp, m_bmp,
rc.x, rc.y,
rc.x+dx, rc.y+dy,
rc.w, rc.h);
}
void drawSurface(const LockedSurface* src, int dstx, int dsty) override {
draw_sprite(m_bmp, static_cast<const Alleg4Surface*>(src)->m_bmp, dstx, dsty);
}
View
@@ -14,6 +14,8 @@
#include "she/scoped_surface_lock.h"
#include "she/surface.h"
#include <vector>
namespace she {
class CommonFont : public Font {
View
@@ -16,6 +16,7 @@ namespace she {
public:
virtual ~EventQueue() { }
virtual void getEvent(Event& ev, bool canWait) = 0;
virtual void queueEvent(const Event& ev) = 0;
};
} // namespace she
View
@@ -44,6 +44,7 @@ namespace she {
virtual void fillRect(gfx::Color color, const gfx::Rect& rc) = 0;
virtual void blitTo(LockedSurface* dest, int srcx, int srcy, int dstx, int dsty, int width, int height) const = 0;
virtual void scrollTo(const gfx::Rect& rc, int dx, int dy) = 0;
virtual void drawSurface(const LockedSurface* src, int dstx, int dsty) = 0;
virtual void drawRgbaSurface(const LockedSurface* src, int dstx, int dsty) = 0;
virtual void drawColoredRgbaSurface(const LockedSurface* src, gfx::Color fg, gfx::Color bg, const gfx::Clip& clip) = 0;
@@ -0,0 +1,111 @@
// SHE library
// Copyright (C) 2012-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#include <windows.h>
#include "GL/gl.h"
#include "gl/SkGLContext.h"
namespace she {
class GLContextWGL : public SkGLContext {
public:
GLContextWGL(HWND hwnd, GrGLStandard forcedGpuAPI)
: m_hwnd(hwnd)
, m_glrc(nullptr) {
HDC hdc = GetDC(m_hwnd);
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL, // support OpenGL
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
8, // 8-bit alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
0, // no z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int pixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, pixelFormat, &pfd);
m_glrc = wglCreateContext(hdc);
if (!m_glrc) {
ReleaseDC(m_hwnd, hdc);
return;
}
wglMakeCurrent(hdc, m_glrc);
fGL.reset(GrGLCreateNativeInterface());
if (!fGL) {
ReleaseDC(m_hwnd, hdc);
destroy();
return;
}
if (!fGL->validate()) {
ReleaseDC(m_hwnd, hdc);
destroy();
return;
}
ReleaseDC(m_hwnd, hdc);
}
~GLContextWGL() {
destroy();
}
void makeCurrent() const override {
HDC hdc = GetDC(m_hwnd);
wglMakeCurrent(hdc, m_glrc);
ReleaseDC(m_hwnd, hdc);
}
void swapBuffers() const override {
HDC hdc = GetDC(m_hwnd);
SwapBuffers(hdc);
ReleaseDC(m_hwnd, hdc);
}
int getStencilBits() {
HDC hdc = GetDC(m_hwnd);
int pixelFormat = GetPixelFormat(hdc);
PIXELFORMATDESCRIPTOR pfd;
DescribePixelFormat(hdc, pixelFormat, sizeof(pfd), &pfd);
ReleaseDC(m_hwnd, hdc);
return pfd.cStencilBits;
}
int getSampleCount() {
return 0; // TODO
}
private:
void destroy() {
fGL.reset(nullptr);
if (m_glrc) {
wglMakeCurrent(nullptr, nullptr);
wglDeleteContext(m_glrc);
m_glrc = nullptr;
}
}
HWND m_hwnd;
HGLRC m_glrc;
};
} // namespace she
@@ -12,18 +12,30 @@
namespace she {
SkiaDisplay::SkiaDisplay(int width, int height, int scale)
: m_window(&m_queue, this)
SkiaDisplay::SkiaDisplay(EventQueue* queue, int width, int height, int scale)
: m_queue(queue)
, m_window(m_queue, this)
, m_surface(new SkiaSurface)
, m_customSurface(false)
{
m_surface->create(width, height);
m_window.setScale(scale);
m_window.setVisible(true);
m_recreated = false;
}
void SkiaDisplay::setSkiaSurface(SkiaSurface* surface)
{
m_surface->dispose();
m_surface = surface;
m_customSurface = true;
}
void SkiaDisplay::resize(const gfx::Size& size)
{
if (m_customSurface)
return;
m_surface->dispose();
m_surface = new SkiaSurface;
m_surface->create(size.w, size.h);
@@ -80,7 +92,7 @@ bool SkiaDisplay::flip()
return false;
}
m_window.invalidate();
m_window.updateWindow();
return true;
}
@@ -101,16 +113,18 @@ void SkiaDisplay::setTitleBar(const std::string& title)
EventQueue* SkiaDisplay::getEventQueue()
{
return &m_queue;
return m_queue;
}
bool SkiaDisplay::setNativeMouseCursor(NativeCursor cursor)
{
m_window.setNativeMouseCursor(cursor);
return true;
}
void SkiaDisplay::setMousePosition(const gfx::Point& position)
{
m_window.setMousePosition(position);
}
void SkiaDisplay::captureMouse()
@@ -9,16 +9,22 @@
#pragma once
#include "she/display.h"
#include "she/skia/skia_event_queue.h"
#include "she/skia/skia_window.h"
#ifdef _WIN32
#include "she/skia/skia_window_win.h"
#else
#error There is no SkiaWindow implementation for your platform
#endif
namespace she {
class SkiaSurface;
class SkiaDisplay : public Display {
public:
SkiaDisplay(int width, int height, int scale);
SkiaDisplay(EventQueue* queue, int width, int height, int scale);
void setSkiaSurface(SkiaSurface* surface);
void resize(const gfx::Size& size);
void dispose() override;
@@ -55,10 +61,11 @@ class SkiaDisplay : public Display {
DisplayHandle nativeHandle() override;
private:
SkiaEventQueue m_queue;
EventQueue* m_queue;
SkiaWindow m_window;
SkiaSurface* m_surface;
bool m_recreated;
bool m_customSurface;
};
} // namespace she
Oops, something went wrong.

0 comments on commit 26b170e

Please sign in to comment.