diff options
author | 2014-02-27 17:39:40 +0000 | |
---|---|---|
committer | 2014-02-27 17:39:40 +0000 | |
commit | 939560b87a392911c5aeaacdbd1f8d26fe4845ad (patch) | |
tree | 49807f99a45cdf4c13a98b1e2cf766824c8df6b2 /experimental | |
parent | 5e16ef74db61d99d47b281ce4fc3d1a113b10fa0 (diff) |
Move SkV8Example to SkSurface
BUG=skia:
R=robertphillips@google.com
Author: jcgregorio@google.com
Review URL: https://codereview.chromium.org/148523019
git-svn-id: http://skia.googlecode.com/svn/trunk@13609 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/SkV8Example/SkV8Example.cpp | 24 | ||||
-rw-r--r-- | experimental/SkV8Example/SkV8Example.h | 3 |
2 files changed, 23 insertions, 4 deletions
diff --git a/experimental/SkV8Example/SkV8Example.cpp b/experimental/SkV8Example/SkV8Example.cpp index eb0e713376..96b52725d5 100644 --- a/experimental/SkV8Example/SkV8Example.cpp +++ b/experimental/SkV8Example/SkV8Example.cpp @@ -27,6 +27,7 @@ using namespace v8; #include "SkGpuDevice.h" #include "SkGraphics.h" #include "SkScalar.h" +#include "SkSurface.h" DEFINE_string2(infile, i, NULL, "Name of file to load JS from.\n"); @@ -49,9 +50,10 @@ SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd, JsContext* context) , fCurContext(NULL) , fCurIntf(NULL) , fCurRenderTarget(NULL) + , fCurSurface(NULL) #endif { - this->setConfig(SkBitmap::kARGB_8888_Config); + this->setColorType(kBGRA_8888_SkColorType); this->setVisibleP(true); this->setClipToBounds(false); @@ -60,6 +62,15 @@ SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd, JsContext* context) #endif } +SkV8ExampleWindow::~SkV8ExampleWindow() { +#if SK_SUPPORT_GPU + SkSafeUnref(fCurContext); + SkSafeUnref(fCurIntf); + SkSafeUnref(fCurRenderTarget); + SkSafeUnref(fCurSurface); +#endif +} + #if SK_SUPPORT_GPU void SkV8ExampleWindow::windowSizeChanged() { if (FLAGS_gpu) { @@ -92,6 +103,8 @@ void SkV8ExampleWindow::windowSizeChanged() { SkSafeUnref(fCurRenderTarget); fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc); + SkSafeUnref(fCurSurface); + fCurSurface = SkSurface::NewRenderTargetDirect(fCurRenderTarget); } } #endif @@ -99,9 +112,12 @@ void SkV8ExampleWindow::windowSizeChanged() { #if SK_SUPPORT_GPU SkCanvas* SkV8ExampleWindow::createCanvas() { if (FLAGS_gpu) { - SkAutoTUnref<SkBaseDevice> device( - new SkGpuDevice(fCurContext, fCurRenderTarget)); - return new SkCanvas(device); + SkCanvas* c = fCurSurface->getCanvas(); + // Increase the ref count since the surface keeps a reference + // to the canvas, but callers of createCanvas put the results + // in a SkAutoTUnref. + c->ref(); + return c; } else { return this->INHERITED::createCanvas(); } diff --git a/experimental/SkV8Example/SkV8Example.h b/experimental/SkV8Example/SkV8Example.h index 3d87d7add5..5e1400564c 100644 --- a/experimental/SkV8Example/SkV8Example.h +++ b/experimental/SkV8Example/SkV8Example.h @@ -15,12 +15,14 @@ class GrContext; class GrGLInterface; class GrRenderTarget; +class SkSurface; class JsContext; class SkV8ExampleWindow : public SkOSWindow { public: SkV8ExampleWindow(void* hwnd, JsContext* canvas); + virtual ~SkV8ExampleWindow(); protected: virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE; @@ -44,6 +46,7 @@ private: GrContext* fCurContext; const GrGLInterface* fCurIntf; GrRenderTarget* fCurRenderTarget; + SkSurface* fCurSurface; #endif }; |