aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-06 20:03:55 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-06 20:03:55 +0000
commit9ee0e32886254fc3feba9ab25ec112b270085b92 (patch)
tree5321a1d5717d8c13d4401fa205884960b8a78448
parent31fdb92995bbd49cc3b60a5d6b97fd20b0c0ef47 (diff)
Turn on GL drawing, allow switching via --gpu flag.
This CL comes after https://codereview.chromium.org/121303004/. BUG= R=robertphillips@google.com Author: jcgregorio@google.com Review URL: https://codereview.chromium.org/122453003 git-svn-id: http://skia.googlecode.com/svn/trunk@12923 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--experimental/SkV8Example/SkV8Example.cpp80
-rw-r--r--experimental/SkV8Example/SkV8Example.h17
2 files changed, 94 insertions, 3 deletions
diff --git a/experimental/SkV8Example/SkV8Example.cpp b/experimental/SkV8Example/SkV8Example.cpp
index 7dc7db0b4e..6eb8d89e04 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;
}
diff --git a/experimental/SkV8Example/SkV8Example.h b/experimental/SkV8Example/SkV8Example.h
index 770597f55d..3d87d7add5 100644
--- a/experimental/SkV8Example/SkV8Example.h
+++ b/experimental/SkV8Example/SkV8Example.h
@@ -12,6 +12,10 @@
#include "SkWindow.h"
+class GrContext;
+class GrGLInterface;
+class GrRenderTarget;
+
class JsContext;
class SkV8ExampleWindow : public SkOSWindow {
@@ -20,14 +24,27 @@ public:
protected:
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE;
+ virtual void onSizeChange() SK_OVERRIDE;
+
+#if SK_SUPPORT_GPU
+ virtual SkCanvas* createCanvas() SK_OVERRIDE;
+#endif
#ifdef SK_BUILD_FOR_WIN
virtual void onHandleInval(const SkIRect&) SK_OVERRIDE;
#endif
+ void windowSizeChanged();
+
private:
typedef SkOSWindow INHERITED;
JsContext* fJsContext;
+
+#if SK_SUPPORT_GPU
+ GrContext* fCurContext;
+ const GrGLInterface* fCurIntf;
+ GrRenderTarget* fCurRenderTarget;
+#endif
};
#endif