V8 and Skia

R=robertphillips@google.com

Author: jcgregorio@google.com

Review URL: https://codereview.chromium.org/93933005

git-svn-id: http://skia.googlecode.com/svn/trunk@12503 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2013-12-05 13:45:19 +00:00
parent bd04652cd6
commit 44a3877442
4 changed files with 225 additions and 0 deletions

View File

@ -0,0 +1,108 @@
/*
* Copyright 2013 Google Inc.
*
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
*/
#include <v8.h>
using namespace v8;
#include "SkV8Example.h"
#include "gl/GrGLUtil.h"
#include "gl/GrGLDefines.h"
#include "gl/GrGLInterface.h"
#include "SkApplication.h"
#include "SkDraw.h"
#include "SkGpuDevice.h"
#include "SkGraphics.h"
void application_init() {
SkGraphics::Init();
SkEvent::Init();
}
void application_term() {
SkEvent::Term();
SkGraphics::Term();
}
SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd)
: INHERITED(hwnd) {
this->setConfig(SkBitmap::kARGB_8888_Config);
this->setVisibleP(true);
this->setClipToBounds(false);
}
void SkV8ExampleWindow::onDraw(SkCanvas* canvas) {
printf("Draw\n");
canvas->drawColor(SK_ColorWHITE);
SkPaint paint;
paint.setColor(SK_ColorRED);
// Draw a rectangle with blue paint
SkRect rect = {
SkIntToScalar(10), SkIntToScalar(10),
SkIntToScalar(128), SkIntToScalar(128)
};
canvas->drawRect(rect, paint);
INHERITED::onDraw(canvas);
}
#ifdef SK_BUILD_FOR_WIN
void SkV8ExampleWindow::onHandleInval(const SkIRect& rect) {
RECT winRect;
winRect.top = rect.top();
winRect.bottom = rect.bottom();
winRect.right = rect.right();
winRect.left = rect.left();
InvalidateRect((HWND)this->getHWND(), &winRect, false);
}
#endif
SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
printf("Started\n");
// Get the default Isolate created at startup.
Isolate* isolate = Isolate::GetCurrent();
// Create a stack-allocated handle scope.
HandleScope handle_scope(isolate);
// Create a new context.
Handle<Context> context = Context::New(isolate);
// Here's how you could create a Persistent handle to the context, if needed.
Persistent<Context> persistent_context(isolate, context);
// Enter the created context for compiling and
// running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Handle<String> source = String::New("'Hello' + ', World!'");
// Compile the source code.
Handle<Script> script = Script::Compile(source);
// Run the script to get the result.
Handle<Value> result = script->Run();
// The persistent handle needs to be eventually disposed.
persistent_context.Dispose();
// Convert the result to an ASCII string and print it.
String::AsciiValue ascii(result);
printf("%s\n", *ascii);
return new SkV8ExampleWindow(hwnd);
}

View File

@ -0,0 +1,35 @@
/*
* Copyright 2013 Google Inc.
*
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
*/
#ifndef SkV8Example_DEFINED
#define SkV8Example_DEFINED
#include "SkWindow.h"
class SkCanvas;
class SkV8ExampleWindow : public SkOSWindow {
public:
SkV8ExampleWindow(void* hwnd);
protected:
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE;
#ifdef SK_BUILD_FOR_WIN
virtual void onHandleInval(const SkIRect&) SK_OVERRIDE;
#endif
private:
typedef SkOSWindow INHERITED;
};
#endif

View File

@ -22,6 +22,7 @@
'dependencies': [
'debugger.gyp:debugger',
'pdfviewer.gyp:pdfviewer',
#'v8.gyp:SkV8Example',
],
}],
# DM assumes you've got a GPU.

81
gyp/v8.gyp Normal file
View File

@ -0,0 +1,81 @@
# GYP file to build a V8 sample.
{
'targets': [
{
'target_name': 'SkV8Example',
'type': 'executable',
'mac_bundle' : 1,
'include_dirs' : [
'../tools/flags',
'../../../v8/include',
],
'includes': [],
'sources': [
'../experimental/SkV8Example/SkV8Example.h',
'../experimental/SkV8Example/SkV8Example.cpp',
],
'dependencies': [
'skia_lib.gyp:skia_lib',
'views.gyp:views',
'xml.gyp:xml',
],
'link_settings': {
'libraries': [
'-lpthread',
'-lrt',
'../../../v8/out/native/obj.target/tools/gyp/libv8_base.x64.a',
'../../../v8/out/native/obj.target/tools/gyp/libv8_snapshot.a',
'../../../v8/out/native/obj.target/third_party/icu/libicudata.a',
'../../../v8/out/native/obj.target/third_party/icu/libicui18n.a',
'../../../v8/out/native/obj.target/third_party/icu/libicuuc.a',
'../../../v8/out/native/obj.target/icudata/third_party/icu/linux/icudt46l_dat.o',
],
},
'conditions' : [
[ 'skia_gpu == 1', {
'include_dirs' : [
'../src/gpu', #gl/GrGLUtil.h
]
}],
[ 'skia_os == "win"', {
'sources' : [
'../src/views/win/SkOSWindow_Win.cpp',
'../src/views/win/skia_win.cpp',
],
},
],
[ 'skia_os == "mac"', {
'sources': [
'../src/views/mac/SampleAppDelegate.h',
'../src/views/mac/SampleAppDelegate.mm',
'../src/views/mac/SkEventNotifier.mm',
'../src/views/mac/skia_mac.mm',
'../src/views/mac/SkNSView.h',
'../src/views/mac/SkNSView.mm',
'../src/views/mac/SkOptionsTableView.h',
'../src/views/mac/SkOptionsTableView.mm',
'../src/views/mac/SkOSWindow_Mac.mm',
'../src/views/mac/SkTextFieldCell.h',
'../src/views/mac/SkTextFieldCell.m',
],
'include_dirs' : [
'../src/views/mac/'
],
'xcode_settings' : {
'INFOPLIST_FILE' : '../experimental/SkiaExamples/SkiaExamples-Info.plist',
},
'mac_bundle_resources' : [
'../experimental/SkiaExamples/SkiaExamples.xib'
],
}
],
],
}
],
}