Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Unified Diff: experimental/SkV8Example/SkV8Example.cpp

Issue 122453003: Add GPU, controlled via command line flag. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/SkV8Example/SkV8Example.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/SkV8Example/SkV8Example.cpp
diff --git a/experimental/SkV8Example/SkV8Example.cpp b/experimental/SkV8Example/SkV8Example.cpp
index 7dc7db0b4e309e5132edcedd146aaef3374df5c9..6eb8d89e047fa403dfdbac9a28d839595034175f 100644
--- a/experimental/SkV8Example/SkV8Example.cpp
+++ b/experimental/SkV8Example/SkV8Example.cpp
@@ -18,6 +18,8 @@ using namespace v8;
#include "gl/GrGLUtil.h"
#include "gl/GrGLDefines.h"
#include "gl/GrGLInterface.h"
+#include "GrRenderTarget.h"
+#include "GrContext.h"
#include "SkApplication.h"
#include "SkCommandLineFlags.h"
#include "SkData.h"
@@ -28,6 +30,7 @@ using namespace v8;
DEFINE_string2(infile, i, NULL, "Name of file to load JS from.\n");
+DEFINE_bool(gpu, true, "Use the GPU for rendering.");
void application_init() {
SkGraphics::Init();
@@ -39,14 +42,78 @@ void application_term() {
SkGraphics::Term();
}
-
SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd, JsContext* context)
: INHERITED(hwnd)
, fJsContext(context)
+#if SK_SUPPORT_GPU
+ , fCurContext(NULL)
+ , fCurIntf(NULL)
+ , fCurRenderTarget(NULL)
+#endif
{
this->setConfig(SkBitmap::kARGB_8888_Config);
this->setVisibleP(true);
this->setClipToBounds(false);
+
+#if SK_SUPPORT_GPU
+ this->windowSizeChanged();
+#endif
+}
+
+#if SK_SUPPORT_GPU
+void SkV8ExampleWindow::windowSizeChanged() {
+ if (FLAGS_gpu) {
+ SkOSWindow::AttachmentInfo attachmentInfo;
+ bool result = this->attach(
+ SkOSWindow::kNativeGL_BackEndType, 0, &attachmentInfo);
+ if (!result) {
+ printf("Failed to attach.");
+ exit(1);
+ }
+
+ fCurIntf = GrGLCreateNativeInterface();
+ fCurContext = GrContext::Create(
+ kOpenGL_GrBackend, (GrBackendContext) fCurIntf);
+ if (NULL == fCurIntf || NULL == fCurContext) {
+ printf("Failed to initialize GL.");
+ exit(1);
+ }
+
+ GrBackendRenderTargetDesc desc;
+ desc.fWidth = SkScalarRoundToInt(this->width());
+ desc.fHeight = SkScalarRoundToInt(this->height());
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
+ desc.fSampleCnt = attachmentInfo.fSampleCount;
+ desc.fStencilBits = attachmentInfo.fStencilBits;
+ GrGLint buffer;
+ GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer);
+ desc.fRenderTargetHandle = buffer;
+
+ SkSafeUnref(fCurRenderTarget);
+ fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc);
+ }
+}
+#endif
+
+#if SK_SUPPORT_GPU
+SkCanvas* SkV8ExampleWindow::createCanvas() {
+ if (FLAGS_gpu) {
+ SkAutoTUnref<SkBaseDevice> device(
+ new SkGpuDevice(fCurContext, fCurRenderTarget));
+ return new SkCanvas(device);
+ } else {
+ return this->INHERITED::createCanvas();
+ }
+}
+#endif
+
+void SkV8ExampleWindow::onSizeChange() {
+ this->INHERITED::onSizeChange();
+
+#if SK_SUPPORT_GPU
+ this->windowSizeChanged();
+#endif
}
void SkV8ExampleWindow::onDraw(SkCanvas* canvas) {
@@ -59,9 +126,15 @@ void SkV8ExampleWindow::onDraw(SkCanvas* canvas) {
canvas->restore();
- INHERITED::onDraw(canvas);
-}
+ this->INHERITED::onDraw(canvas);
+#if SK_SUPPORT_GPU
+ if (FLAGS_gpu) {
+ fCurContext->flush();
+ this->present();
+ }
+#endif
+}
#ifdef SK_BUILD_FOR_WIN
void SkV8ExampleWindow::onHandleInval(const SkIRect& rect) {
@@ -114,5 +187,6 @@ SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
}
SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext);
global->setWindow(win);
+
return win;
}
« no previous file with comments | « experimental/SkV8Example/SkV8Example.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698