aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-20 13:43:13 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-20 13:43:13 +0000
commitffa11bbbedd201899eb93bf05089c511f53d5c2a (patch)
treee5cccf6d8dfdd2e427e42ac204de419635dd471f
parente173992c2319205fdc263ccd10d7a9018c23013c (diff)
Move a bunch of headers from include/gpu to src/gpu. Delete some unused files.
Review URL: http://codereview.appspot.com/5304047/ git-svn-id: http://skia.googlecode.com/svn/trunk@2506 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--gyp/gpu.gyp32
-rw-r--r--include/gpu/FlingState.h51
-rw-r--r--include/gpu/GrIPoint.h28
-rw-r--r--include/gpu/GrMesh.h49
-rw-r--r--include/gpu/GrPathSink.h29
-rw-r--r--include/gpu/GrStopwatch.h128
-rw-r--r--include/gpu/SkUIView.h65
-rw-r--r--src/gpu/GrAllocPool.h (renamed from include/gpu/GrAllocPool.h)0
-rwxr-xr-xsrc/gpu/GrAllocator.h (renamed from include/gpu/GrAllocator.h)0
-rw-r--r--src/gpu/GrAtlas.h (renamed from include/gpu/GrAtlas.h)0
-rw-r--r--src/gpu/GrDrawMesh.cpp147
-rw-r--r--src/gpu/GrGLShaderVar.h1
-rw-r--r--src/gpu/GrGpuVertex.h (renamed from include/gpu/GrGpuVertex.h)0
-rw-r--r--src/gpu/GrPlotMgr.h (renamed from include/gpu/GrPlotMgr.h)0
-rw-r--r--src/gpu/GrRandom.h (renamed from include/gpu/GrRandom.h)0
-rw-r--r--src/gpu/GrRectanizer.h (renamed from include/gpu/GrRectanizer.h)0
-rw-r--r--src/gpu/GrStencil.h (renamed from include/gpu/GrStencil.h)0
-rw-r--r--src/gpu/GrStringBuilder.h (renamed from include/gpu/GrStringBuilder.h)0
-rw-r--r--src/gpu/GrTBSearch.h (renamed from include/gpu/GrTBSearch.h)0
-rw-r--r--src/gpu/GrTDArray.h (renamed from include/gpu/GrTDArray.h)0
-rw-r--r--src/gpu/GrTHashCache.h (renamed from include/gpu/GrTHashCache.h)0
-rw-r--r--src/gpu/GrTLList.h (renamed from include/gpu/GrTLList.h)0
-rw-r--r--src/gpu/GrTextStrike.h (renamed from include/gpu/GrTextStrike.h)0
-rw-r--r--src/gpu/ios/SkUIView.mm827
24 files changed, 15 insertions, 1342 deletions
diff --git a/gyp/gpu.gyp b/gyp/gpu.gyp
index 132b8e96ab..391824e85d 100644
--- a/gyp/gpu.gyp
+++ b/gyp/gpu.gyp
@@ -145,9 +145,6 @@
'libtess.gyp:libtess',
],
'sources': [
- '../include/gpu/GrAllocator.h',
- '../include/gpu/GrAllocPool.h',
- '../include/gpu/GrAtlas.h',
'../include/gpu/GrClip.h',
'../include/gpu/GrClipIterator.h',
'../include/gpu/GrColor.h',
@@ -158,44 +155,32 @@
'../include/gpu/GrGLConfig_chrome.h',
'../include/gpu/GrGLInterface.h',
'../include/gpu/GrGlyph.h',
- '../include/gpu/GrGpuVertex.h',
'../include/gpu/GrInstanceCounter.h',
- '../include/gpu/GrIPoint.h',
'../include/gpu/GrKey.h',
'../include/gpu/GrMatrix.h',
- '../include/gpu/GrMesh.h',
'../include/gpu/GrNoncopyable.h',
'../include/gpu/GrPaint.h',
'../include/gpu/GrPath.h',
- '../include/gpu/GrPathSink.h',
- '../include/gpu/GrPlotMgr.h',
'../include/gpu/GrPoint.h',
- '../include/gpu/GrRandom.h',
'../include/gpu/GrRect.h',
- '../include/gpu/GrRectanizer.h',
'../include/gpu/GrRefCnt.h',
'../include/gpu/GrRenderTarget.h',
'../include/gpu/GrResource.h',
'../include/gpu/GrSamplerState.h',
'../include/gpu/GrScalar.h',
- '../include/gpu/GrStencil.h',
- '../include/gpu/GrStopwatch.h',
- '../include/gpu/GrStringBuilder.h',
- '../include/gpu/GrTBSearch.h',
- '../include/gpu/GrTDArray.h',
'../include/gpu/GrTextContext.h',
- '../include/gpu/GrTextStrike.h',
'../include/gpu/GrTexture.h',
- '../include/gpu/GrTHashCache.h',
- '../include/gpu/GrTLList.h',
'../include/gpu/GrTypes.h',
'../include/gpu/GrUserConfig.h',
'../src/gpu/GrAAHairLinePathRenderer.cpp',
'../src/gpu/GrAAHairLinePathRenderer.h',
'../src/gpu/GrAddPathRenderers_aahairline.cpp',
+ '../src/gpu/GrAllocator.h',
+ '../src/gpu/GrAllocPool.h',
'../src/gpu/GrAllocPool.cpp',
'../src/gpu/GrAtlas.cpp',
+ '../src/gpu/GrAtlas.h',
'../src/gpu/GrBinHashKey.h',
'../src/gpu/GrBufferAllocPool.cpp',
'../src/gpu/GrBufferAllocPool.h',
@@ -234,6 +219,7 @@
'../src/gpu/GrGpuGLFixed.h',
'../src/gpu/GrGpuGLShaders.cpp',
'../src/gpu/GrGpuGLShaders.h',
+ '../src/gpu/GrGpuVertex.h',
'../src/gpu/GrIndexBuffer.h',
'../src/gpu/GrInOrderDrawBuffer.cpp',
'../src/gpu/GrInOrderDrawBuffer.h',
@@ -245,21 +231,31 @@
'../src/gpu/GrPathRenderer.h',
'../src/gpu/GrPathUtils.cpp',
'../src/gpu/GrPathUtils.h',
+ '../src/gpu/GrPlotMgr.h',
+ '../src/gpu/GrRandom.h',
'../src/gpu/GrRectanizer.cpp',
+ '../src/gpu/GrRectanizer.h',
'../src/gpu/GrRedBlackTree.h',
'../src/gpu/GrRenderTarget.cpp',
'../src/gpu/GrResource.cpp',
'../src/gpu/GrResourceCache.cpp',
'../src/gpu/GrResourceCache.h',
'../src/gpu/GrStencil.cpp',
+ '../src/gpu/GrStencil.h',
'../src/gpu/GrStencilBuffer.cpp',
'../src/gpu/GrStencilBuffer.h',
+ '../src/gpu/GrStringBuilder.h',
+ '../src/gpu/GrTBSearch.h',
+ '../src/gpu/GrTDArray.h',
'../src/gpu/GrTesselatedPathRenderer.cpp',
'../src/gpu/GrTesselatedPathRenderer.h',
'../src/gpu/GrTextContext.cpp',
'../src/gpu/GrTextStrike.cpp',
+ '../src/gpu/GrTextStrike.h',
'../src/gpu/GrTextStrike_impl.h',
'../src/gpu/GrTexture.cpp',
+ '../src/gpu/GrTHashCache.h',
+ '../src/gpu/GrTLList.h',
'../src/gpu/GrVertexBuffer.h',
'../src/gpu/gr_unittests.cpp',
diff --git a/include/gpu/FlingState.h b/include/gpu/FlingState.h
deleted file mode 100644
index 09557b90fb..0000000000
--- a/include/gpu/FlingState.h
+++ /dev/null
@@ -1,51 +0,0 @@
-
-/*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-
-#ifndef SkFlingState_DEFINED
-#define SkFlingState_DEFINED
-
-#include "SkScalar.h"
-#include "SkPoint.h"
-
-class SkMatrix;
-
-struct FlingState {
- FlingState() : fActive(false) {}
-
- bool isActive() const { return fActive; }
- void stop() { fActive = false; }
-
- void reset(float sx, float sy);
- bool evaluateMatrix(SkMatrix* matrix);
-
-private:
- SkPoint fDirection;
- SkScalar fSpeed0;
- double fTime0;
- bool fActive;
-};
-
-class GrAnimateFloat {
-public:
- GrAnimateFloat();
-
- void start(float v0, float v1, float duration);
- bool isActive() const { return fTime0 != 0; }
- void stop() { fTime0 = 0; }
-
- float evaluate();
-
-private:
- float fValue0, fValue1, fDuration;
- SkMSec fTime0;
-};
-
-#endif
-
diff --git a/include/gpu/GrIPoint.h b/include/gpu/GrIPoint.h
deleted file mode 100644
index 9471054f06..0000000000
--- a/include/gpu/GrIPoint.h
+++ /dev/null
@@ -1,28 +0,0 @@
-
-/*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-
-#ifndef GrIPoint_DEFINED
-#define GrIPoint_DEFINED
-
-#include "GrTypes.h"
-
-struct GrIPoint {
-public:
- int32_t fX, fY;
-
- GrIPoint(int32_t x, int32_t y) : fX(x), fY(y) {}
-
- void set(int32_t x, int32_t y) {
- fX = x;
- fY = y;
- }
-};
-
-#endif
diff --git a/include/gpu/GrMesh.h b/include/gpu/GrMesh.h
deleted file mode 100644
index 122613264f..0000000000
--- a/include/gpu/GrMesh.h
+++ /dev/null
@@ -1,49 +0,0 @@
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#ifndef GrMesh_DEFINED
-#define GrMesh_DEFINED
-
-#include "SkRect.h"
-#include "SkPoint.h"
-
-class SkCanvas;
-class SkPaint;
-
-class GrMesh {
-public:
- GrMesh();
- ~GrMesh();
-
- GrMesh& operator=(const GrMesh& src);
-
- void init(const SkRect& bounds, int rows, int cols,
- const SkRect& texture);
-
- const SkRect& bounds() const { return fBounds; }
-
- int rows() const { return fRows; }
- int cols() const { return fCols; }
- SkPoint& pt(int row, int col) {
- return fPts[row * (fRows + 1) + col];
- }
-
- void draw(SkCanvas*, const SkPaint&);
- void drawWireframe(SkCanvas* canvas, const SkPaint& paint);
-
-private:
- SkRect fBounds;
- int fRows, fCols;
- SkPoint* fPts;
- SkPoint* fTex; // just points into fPts, not separately allocated
- int fCount;
- uint16_t* fIndices;
- int fIndexCount;
-};
-
-#endif
-
diff --git a/include/gpu/GrPathSink.h b/include/gpu/GrPathSink.h
deleted file mode 100644
index ed71387e7f..0000000000
--- a/include/gpu/GrPathSink.h
+++ /dev/null
@@ -1,29 +0,0 @@
-
-/*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-
-#ifndef GrPathSink_DEFINED
-#define GrPathSink_DEFINED
-
-#include "GrScalar.h"
-
-class GrPathSink {
-public:
- virtual ~GrPathSink() {}
-
- virtual void moveTo(GrScalar x, GrScalar y) = 0;
- virtual void lineTo(GrScalar x, GrScalar y) = 0;
- virtual void quadTo(GrScalar x0, GrScalar y0, GrScalar x1, GrScalar y1) = 0;
- virtual void cubicTo(GrScalar x0, GrScalar y0, GrScalar x1, GrScalar y1,
- GrScalar x2, GrScalar y2) = 0;
- virtual void close() = 0;
-};
-
-#endif
-
diff --git a/include/gpu/GrStopwatch.h b/include/gpu/GrStopwatch.h
deleted file mode 100644
index 7ac3fd0d42..0000000000
--- a/include/gpu/GrStopwatch.h
+++ /dev/null
@@ -1,128 +0,0 @@
-
-/*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-
-#ifndef GrStopwatch_DEFINED
-#define GrStopwatch_DEFINED
-
-#include "GrTypes.h"
-
-template <typename PLATFORM_TIMER>
-/**
- * Base class for stopwatch. Relies on PLATFORM_TIMER for platform-specific
- * timer functions. PLATFORM_TIMER provides:
- * - typename TIMESTAMP : a timestamp value that can be used with Diff()
- * - static TIMESTAMP Now() : gets current timestamp
- * - static double Diff(const TIMESTAMP& begin, const TIMESTAMP& end) :
- * computes delta in seconds between two timestamps
- */
-class GrStopwatchBase {
-public:
- /**
- * Contructor - implicit reset()
- */
- GrStopwatchBase() {
- fRunning = false;
- fTotalElapsed = 0.0;
- }
-
- /**
- * begins a new lap
- */
- void start() {
- double lastLap = lapTime();
- fTotalElapsed += lastLap;
- fRunning = true;
- fLastStart = PLATFORM_TIMER::Now();
- }
-
- /**
- * ends current lap (or no effect if lap not started)
- */
- void stop() {
- double lastLap = lapTime();
- fTotalElapsed += lastLap;
- fRunning = false;
- }
-
- /**
- * ends current lap, resets total time
- */
- void reset() {
- fRunning = false;
- fTotalElapsed = 0.f;
- }
-
- /**
- * Computes the time of all laps since last reset() including current lap
- * if lap is still running.
- *
- * @return the sum time in seconds of all laps since last reset().
- */
- double totalTime() const {
- return fTotalElapsed + lapTime();
- }
-
- /**
- * Current lap time.
- *
- * @return time in seconds of current lap if one is running otherwise 0.
- */
- double lapTime() const {
- if (fRunning) {
- PLATFORM_TIMER::Timestamp now = PLATFORM_TIMER::Now();
- return PLATFORM_TIMER::Elapsed(fLastStart, now);
- }
- return 0.0;
- }
-
-private:
- double fTotalElapsed;
-
- typename PLATFORM_TIMER::Timestamp fLastStart;
- bool fRunning;
-};
-
-#if GR_WIN32_BUILD
-
- #include <Windows.h>
-
- class GrWin32Timer {
- public:
- typedef LARGE_INTEGER Timestamp;
-
- static Timestamp Now() {
- LARGE_INTEGER now;
- QueryPerformanceCounter(&now);
- return now;
- }
-
- static double Elapsed(const Timestamp& begin, const Timestamp& end) {
- double diff = (double)(end.QuadPart - begin.QuadPart);
- return diff * Scale();
- }
- private:
- static double Scale() {
- static double scale;
- if (0.0 == scale) {
- LARGE_INTEGER freq;
- QueryPerformanceFrequency(&freq);
- GrAssert(0 != freq.QuadPart);
- scale = 1 / (double) freq.QuadPart;
- }
- return scale;
- }
- };
- typedef GrStopwatchBase<GrWin32Timer> GrStopwatch;
-#else
- #error "Implement platform timer for stopwatch"
-#endif
-
-
-#endif
diff --git a/include/gpu/SkUIView.h b/include/gpu/SkUIView.h
deleted file mode 100644
index b5a4cd8ed8..0000000000
--- a/include/gpu/SkUIView.h
+++ /dev/null
@@ -1,65 +0,0 @@
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#import <UIKit/UIKit.h>
-
-#include "SkMatrix.h"
-#include "FlingState.h"
-
-#import <OpenGLES/EAGL.h>
-#import <OpenGLES/ES1/gl.h>
-#import <OpenGLES/ES1/glext.h>
-
-class SkOSWindow;
-class SkEvent;
-
-@interface SkUIView : UIView <UIAccelerometerDelegate> {
- BOOL fRedrawRequestPending;
- SkMatrix fMatrix, fLocalMatrix;
- bool fNeedGestureEnded;
-
- SkMatrix fRotateMatrix;
-
- float fFirstPinchX, fFirstPinchY;
- bool fNeedFirstPinch;
-
- float fZoomAroundX, fZoomAroundY;
- bool fZoomAround;
-
- FlingState fFlingState;
-
- GrAnimateFloat fWarpState;
- bool fUseWarp;
-
- struct {
- EAGLContext* fContext;
- GLuint fRenderbuffer;
- GLuint fStencilbuffer;
- GLuint fFramebuffer;
- GLint fWidth;
- GLint fHeight;
- } fGL;
-
- UINavigationItem* fTitle;
- SkOSWindow* fWind;
-}
-
-@property (nonatomic, assign) SkOSWindow *fWind;
-@property (nonatomic, retain) UINavigationItem* fTitle;
-@property (nonatomic, assign) Backend fBackend;
-@property (nonatomic, assign) bool fComplexClip;
-@property (nonatomic, assign, setter=setWarpState) bool fUseWarp;
-
-- (void)initGestures;
-- (void)flushLocalMatrix;
-
-- (void)setSkTitle:(const char*)title;
-- (void)postInvalWithRect:(const SkIRect*)rectOrNil;
-- (BOOL)onHandleEvent:(const SkEvent&)event;
-
-@end
-
diff --git a/include/gpu/GrAllocPool.h b/src/gpu/GrAllocPool.h
index 3ecc4aa189..3ecc4aa189 100644
--- a/include/gpu/GrAllocPool.h
+++ b/src/gpu/GrAllocPool.h
diff --git a/include/gpu/GrAllocator.h b/src/gpu/GrAllocator.h
index 21c79ec7aa..21c79ec7aa 100755
--- a/include/gpu/GrAllocator.h
+++ b/src/gpu/GrAllocator.h
diff --git a/include/gpu/GrAtlas.h b/src/gpu/GrAtlas.h
index f0114e399d..f0114e399d 100644
--- a/include/gpu/GrAtlas.h
+++ b/src/gpu/GrAtlas.h
diff --git a/src/gpu/GrDrawMesh.cpp b/src/gpu/GrDrawMesh.cpp
deleted file mode 100644
index 75960e4f92..0000000000
--- a/src/gpu/GrDrawMesh.cpp
+++ /dev/null
@@ -1,147 +0,0 @@
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "GrMesh.h"
-#include "SkCanvas.h"
-
-GrMesh::GrMesh() : fPts(NULL), fCount(0), fIndices(NULL), fIndexCount(0) {}
-
-GrMesh::~GrMesh() {
- delete[] fPts;
- delete[] fIndices;
-}
-
-GrMesh& GrMesh::operator=(const GrMesh& src) {
- delete[] fPts;
- delete[] fIndices;
-
- fBounds = src.fBounds;
- fRows = src.fRows;
- fCols = src.fCols;
-
- fCount = src.fCount;
- fPts = new SkPoint[fCount * 2];
- fTex = fPts + fCount;
- memcpy(fPts, src.fPts, fCount * 2 * sizeof(SkPoint));
-
- delete[] fIndices;
- fIndexCount = src.fIndexCount;
- fIndices = new uint16_t[fIndexCount];
- memcpy(fIndices, src.fIndices, fIndexCount * sizeof(uint16_t));
-
- return *this;
-}
-
-void GrMesh::init(const SkRect& bounds, int rows, int cols,
- const SkRect& texture) {
- SkASSERT(rows > 0 && cols > 0);
-
- fBounds = bounds;
- fRows = rows;
- fCols = cols;
-
- delete[] fPts;
- fCount = (rows + 1) * (cols + 1);
- fPts = new SkPoint[fCount * 2];
- fTex = fPts + fCount;
-
- delete[] fIndices;
- fIndexCount = rows * cols * 6;
- fIndices = new uint16_t[fIndexCount];
-
- SkPoint* pts = fPts;
- const SkScalar dx = bounds.width() / rows;
- const SkScalar dy = bounds.height() / cols;
- SkPoint* tex = fTex;
- const SkScalar dtx = texture.width() / rows;
- const SkScalar dty = texture.height() / cols;
- uint16_t* idx = fIndices;
- int index = 0;
- for (int y = 0; y <= cols; y++) {
- for (int x = 0; x <= rows; x++) {
- pts->set(bounds.fLeft + x*dx, bounds.fTop + y*dy);
- pts += 1;
- tex->set(texture.fLeft + x*dtx, texture.fTop + y*dty);
- tex += 1;
-
- if (y < cols && x < rows) {
- *idx++ = index;
- *idx++ = index + rows + 1;
- *idx++ = index + 1;
-
- *idx++ = index + 1;
- *idx++ = index + rows + 1;
- *idx++ = index + rows + 2;
-
- index += 1;
- }
- }
- index += 1;
- }
-}
-
-void GrMesh::draw(SkCanvas* canvas, const SkPaint& paint) {
- canvas->drawVertices(SkCanvas::kTriangles_VertexMode, fCount,
- fPts, fTex, NULL, NULL, fIndices, fIndexCount,
- paint);
-}
-
-/////////////////////////////////////////////
-
-#include "SkBoundaryPatch.h"
-#include "SkMeshUtils.h"
-
-static SkPoint SkPointInterp(const SkPoint& a, const SkPoint& b, SkScalar t) {
- return SkPoint::Make(SkScalarInterp(a.fX, b.fX, t),
- SkScalarInterp(a.fY, b.fY, t));
-}
-
-static void set_cubic(SkPoint pts[4], SkScalar x0, SkScalar y0,
- SkScalar x3, SkScalar y3, SkScalar scale = 1) {
- SkPoint tmp, tmp2;
-
- pts[0].set(x0, y0);
- pts[3].set(x3, y3);
-
- tmp = SkPointInterp(pts[0], pts[3], SK_Scalar1/3);
- tmp2 = pts[0] - tmp;
- tmp2.rotateCW();
- tmp2.scale(scale);
- pts[1] = tmp + tmp2;
-
- tmp = SkPointInterp(pts[0], pts[3], 2*SK_Scalar1/3);
- tmp2 = pts[3] - tmp;
- tmp2.rotateCW();
- tmp2.scale(scale);
- pts[2] = tmp + tmp2;
-}
-
-void test_patch(SkCanvas* canvas, const SkBitmap& bm, SkScalar scale) {
- const float w = bm.width();
- const float h = bm.height();
- SkCubicBoundary cubic;
- set_cubic(cubic.fPts + 0, 0, 0, w, 0, scale);
- set_cubic(cubic.fPts + 3, w, 0, w, h, scale);
- set_cubic(cubic.fPts + 6, w, h, 0, h, -scale);
- set_cubic(cubic.fPts + 9, 0, h, 0, 0, scale);
-
- SkBoundaryPatch patch;
- patch.setBoundary(&cubic);
-
- const int Rows = 16;
- const int Cols = 16;
- SkPoint pts[Rows * Cols];
- patch.evalPatch(pts, Rows, Cols);
-
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setFilterBitmap(true);
-
- SkMeshUtils::Draw(canvas, bm, Rows, Cols, pts, NULL, paint);
-}
-
-
diff --git a/src/gpu/GrGLShaderVar.h b/src/gpu/GrGLShaderVar.h
index 5c50079558..8eba7140c9 100644
--- a/src/gpu/GrGLShaderVar.h
+++ b/src/gpu/GrGLShaderVar.h
@@ -10,6 +10,7 @@
#define GrGLShaderVar_DEFINED
#include "GrGLInterface.h"
+#include "GrStringBuilder.h"
/**
* Represents a variable in a shader
diff --git a/include/gpu/GrGpuVertex.h b/src/gpu/GrGpuVertex.h
index 2abc2f407e..2abc2f407e 100644
--- a/include/gpu/GrGpuVertex.h
+++ b/src/gpu/GrGpuVertex.h
diff --git a/include/gpu/GrPlotMgr.h b/src/gpu/GrPlotMgr.h
index 0e631a9ade..0e631a9ade 100644
--- a/include/gpu/GrPlotMgr.h
+++ b/src/gpu/GrPlotMgr.h
diff --git a/include/gpu/GrRandom.h b/src/gpu/GrRandom.h
index c98a8fbd94..c98a8fbd94 100644
--- a/include/gpu/GrRandom.h
+++ b/src/gpu/GrRandom.h
diff --git a/include/gpu/GrRectanizer.h b/src/gpu/GrRectanizer.h
index d1f5033259..d1f5033259 100644
--- a/include/gpu/GrRectanizer.h
+++ b/src/gpu/GrRectanizer.h
diff --git a/include/gpu/GrStencil.h b/src/gpu/GrStencil.h
index b8610f2017..b8610f2017 100644
--- a/include/gpu/GrStencil.h
+++ b/src/gpu/GrStencil.h
diff --git a/include/gpu/GrStringBuilder.h b/src/gpu/GrStringBuilder.h
index 558d0419c0..558d0419c0 100644
--- a/include/gpu/GrStringBuilder.h
+++ b/src/gpu/GrStringBuilder.h
diff --git a/include/gpu/GrTBSearch.h b/src/gpu/GrTBSearch.h
index 2697f3733b..2697f3733b 100644
--- a/include/gpu/GrTBSearch.h
+++ b/src/gpu/GrTBSearch.h
diff --git a/include/gpu/GrTDArray.h b/src/gpu/GrTDArray.h
index 731001a8c9..731001a8c9 100644
--- a/include/gpu/GrTDArray.h
+++ b/src/gpu/GrTDArray.h
diff --git a/include/gpu/GrTHashCache.h b/src/gpu/GrTHashCache.h
index 8651c35c22..8651c35c22 100644
--- a/include/gpu/GrTHashCache.h
+++ b/src/gpu/GrTHashCache.h
diff --git a/include/gpu/GrTLList.h b/src/gpu/GrTLList.h
index ea310ac20e..ea310ac20e 100644
--- a/include/gpu/GrTLList.h
+++ b/src/gpu/GrTLList.h
diff --git a/include/gpu/GrTextStrike.h b/src/gpu/GrTextStrike.h
index 701acea7ab..701acea7ab 100644
--- a/include/gpu/GrTextStrike.h
+++ b/src/gpu/GrTextStrike.h
diff --git a/src/gpu/ios/SkUIView.mm b/src/gpu/ios/SkUIView.mm
deleted file mode 100644
index 261ed9ca1f..0000000000
--- a/src/gpu/ios/SkUIView.mm
+++ /dev/null
@@ -1,827 +0,0 @@
-#import "SkUIView.h"
-#include <QuartzCore/QuartzCore.h>
-
-//#include "SkGpuCanvas.h"
-#include "SkGpuDevice.h"
-#include "SkCGUtils.h"
-#include "GrContext.h"
-
-#define SKWIND_CONFIG SkBitmap::kRGB_565_Config
-//#define SKWIND_CONFIG SkBitmap::kARGB_8888_Config
-#define SKGL_CONFIG kEAGLColorFormatRGB565
-//#define SKGL_CONFIG kEAGLColorFormatRGBA8
-
-#define SHOW_FPS
-#define FORCE_REDRAW
-//#define DUMP_FPS_TO_PRINTF
-
-//#define USE_ACCEL_TO_ROTATE
-
-//#define SHOULD_COUNTER_INIT 334
-static int gShouldCounter;
-static bool should_draw() {
- if (--gShouldCounter == 0) {
- // printf("\n");
- }
- return true;
- return gShouldCounter >= 0;
-}
-#ifdef SHOULD_COUNTER_INIT
- bool (*gShouldDrawProc)() = should_draw;
-#else
- bool (*gShouldDrawProc)() = NULL;
-#endif
-
-//#define USE_GL_1
-//#define USE_GL_2
-
-#if defined(USE_GL_1) || defined(USE_GL_2)
- #define USE_GL
-#endif
-
-@implementation SkUIView
-
-
-@synthesize fWind;
-@synthesize fTitle;
-@synthesize fBackend;
-@synthesize fComplexClip;
-@synthesize fUseWarp;
-
-#include "SkWindow.h"
-#include "SkEvent.h"
-
-static float gScreenScale = 1;
-
-extern SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
-
-#define kREDRAW_UIVIEW_GL "sk_redraw_uiview_gl_iOS"
-
-#define TITLE_HEIGHT 0
-
-static const float SCALE_FOR_ZOOM_LENS = 4.0;
-#define Y_OFFSET_FOR_ZOOM_LENS 200
-#define SIZE_FOR_ZOOM_LENS 250
-
-static const float MAX_ZOOM_SCALE = 4.0;
-static const float MIN_ZOOM_SCALE = 2.0 / MAX_ZOOM_SCALE;
-
-extern bool gDoTraceDraw;
-#define DO_TRACE_DRAW_MAX 100
-
-#ifdef SHOW_FPS
-struct FPSState {
- static const int FRAME_COUNT = 60;
-
- CFTimeInterval fNow0, fNow1;
- CFTimeInterval fTime0, fTime1, fTotalTime;
- int fFrameCounter;
- int fDrawCounter;
-
- FPSState() {
- fTime0 = fTime1 = fTotalTime = 0;
- fFrameCounter = 0;
- }
-
- void startDraw() {
- fNow0 = CACurrentMediaTime();
-
- if (0 == fDrawCounter && false) {
- gDoTraceDraw = true;
- SkDebugf("\n");
- }
- }
-
- void endDraw() {
- fNow1 = CACurrentMediaTime();
-
- if (0 == fDrawCounter) {
- gDoTraceDraw = true;
- }
- if (DO_TRACE_DRAW_MAX == ++fDrawCounter) {
- fDrawCounter = 0;
- }
- }
-
- void flush(SkOSWindow* wind) {
- CFTimeInterval now2 = CACurrentMediaTime();
-
- fTime0 += fNow1 - fNow0;
- fTime1 += now2 - fNow1;
-
- if (++fFrameCounter == FRAME_COUNT) {
- CFTimeInterval totalNow = CACurrentMediaTime();
- fTotalTime = totalNow - fTotalTime;
-
- SkMSec ms0 = (int)(1000 * fTime0 / FRAME_COUNT);
- SkMSec msTotal = (int)(1000 * fTotalTime / FRAME_COUNT);
-
- SkString str;
- str.printf("ms: %d [%d], fps: %3.1f", msTotal, ms0,
- FRAME_COUNT / fTotalTime);
-#ifdef DUMP_FPS_TO_PRINTF
- SkDebugf("%s\n", str.c_str());
-#else
- wind->setTitle(str.c_str());
-#endif
-
- fTotalTime = totalNow;
- fTime0 = fTime1 = 0;
- fFrameCounter = 0;
- }
- }
-};
-
-static FPSState gFPS;
-
- #define FPS_StartDraw() gFPS.startDraw()
- #define FPS_EndDraw() gFPS.endDraw()
- #define FPS_Flush(wind) gFPS.flush(wind)
-#else
- #define FPS_StartDraw()
- #define FPS_EndDraw()
- #define FPS_Flush(wind)
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-
-#ifdef USE_GL
-+ (Class) layerClass
-{
- return [CAEAGLLayer class];
-}
-#endif
-
-- (id)initWithMyDefaults {
- fBackend = kGL_Backend;
- fUseWarp = false;
- fRedrawRequestPending = false;
- // FIXME: If iOS has argc & argv, pass them here.
- //fWind = create_sk_window(self, 0, NULL);
- //fWind->setConfig(SKWIND_CONFIG);
- fMatrix.reset();
- fLocalMatrix.reset();
- fNeedGestureEnded = false;
- fNeedFirstPinch = true;
- fZoomAround = false;
- fComplexClip = false;
-
- [self initGestures];
-
-#ifdef USE_GL
- CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
- eaglLayer.opaque = TRUE;
- eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithBool:NO],
- kEAGLDrawablePropertyRetainedBacking,
- SKGL_CONFIG,
- kEAGLDrawablePropertyColorFormat,
- nil];
-
-#ifdef USE_GL_1
- fGL.fContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
-#else
- fGL.fContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
-#endif
-
- if (!fGL.fContext || ![EAGLContext setCurrentContext:fGL.fContext])
- {
- [self release];
- return nil;
- }
-
- // Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
- glGenFramebuffersOES(1, &fGL.fFramebuffer);
- glBindFramebufferOES(GL_FRAMEBUFFER_OES, fGL.fFramebuffer);
-
- glGenRenderbuffersOES(1, &fGL.fRenderbuffer);
- glGenRenderbuffersOES(1, &fGL.fStencilbuffer);
-
- glBindRenderbufferOES(GL_RENDERBUFFER_OES, fGL.fRenderbuffer);
- glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, fGL.fRenderbuffer);
-
- glBindRenderbufferOES(GL_RENDERBUFFER_OES, fGL.fStencilbuffer);
- glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_STENCIL_ATTACHMENT_OES, GL_RENDERBUFFER_OES, fGL.fStencilbuffer);
-#endif
-
-#ifdef USE_ACCEL_TO_ROTATE
- fRotateMatrix.reset();
- [UIAccelerometer sharedAccelerometer].delegate = self;
- [UIAccelerometer sharedAccelerometer].updateInterval = 1 / 30.0;
-#endif
- return self;
-}
-
-- (id)initWithCoder:(NSCoder*)coder {
- if ((self = [super initWithCoder:coder])) {
- self = [self initWithMyDefaults];
- }
- return self;
-}
-
-- (id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- self = [self initWithMyDefaults];
- }
- return self;
-}
-
-#include "SkImageDecoder.h"
-#include "SkStream_NSData.h"
-
-static void zoom_around(SkCanvas* canvas, float cx, float cy, float zoom) {
- float clipW = SIZE_FOR_ZOOM_LENS;
- float clipH = SIZE_FOR_ZOOM_LENS;
-
- SkRect r;
- r.set(0, 0, clipW, clipH);
- r.offset(cx - clipW/2, cy - clipH/2);
-
- SkPaint paint;
- paint.setColor(0xFF66AAEE);
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(10);
-
- // draw our "frame" around the zoom lens
- canvas->drawRect(r, paint);
-
- // now clip and scale the lens
- canvas->clipRect(r);
- canvas->translate(cx, cy);
- canvas->scale(zoom, zoom);
- canvas->translate(-cx, -cy);
-}
-
-- (void)drawWithCanvas:(SkCanvas*)canvas {
- if (fComplexClip) {
- canvas->drawColor(SK_ColorBLUE);
-
- SkPath path;
- static const SkRect r[] = {
- { 50, 50, 250, 250 },
- { 150, 150, 500, 600 }
- };
- for (size_t i = 0; i < GR_ARRAY_COUNT(r); i++) {
- path.addRect(r[i]);
- }
- canvas->clipPath(path);
- }
-
- // This is to consolidate multiple inval requests
- fRedrawRequestPending = false;
-
- if (fFlingState.isActive()) {
- if (!fFlingState.evaluateMatrix(&fLocalMatrix)) {
- [self flushLocalMatrix];
- }
- }
-
- SkMatrix localMatrix = fLocalMatrix;
-#ifdef USE_ACCEL_TO_ROTATE
- localMatrix.preConcat(fRotateMatrix);
-#endif
-
- SkMatrix matrix;
- matrix.setConcat(localMatrix, fMatrix);
-
- const SkMatrix* localM = NULL;
- if (localMatrix.getType() & SkMatrix::kScale_Mask) {
- localM = &localMatrix;
- }
-#ifdef USE_ACCEL_TO_ROTATE
- localM = &localMatrix;
-#endif
- canvas->setExternalMatrix(localM);
-
-#ifdef SHOULD_COUNTER_INIT
- gShouldCounter = SHOULD_COUNTER_INIT;
-#endif
- {
- int saveCount = canvas->save();
- canvas->concat(matrix);
- // SkRect r = { 10, 10, 500, 600 }; canvas->clipRect(r);
- fWind->draw(canvas);
- canvas->restoreToCount(saveCount);
- }
-
- if (fZoomAround) {
- zoom_around(canvas, fZoomAroundX, fZoomAroundY, SCALE_FOR_ZOOM_LENS);
- canvas->concat(matrix);
- fWind->draw(canvas);
- }
-
-#ifdef FORCE_REDRAW
- fWind->inval(NULL);
-#endif
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-- (void)layoutSubviews {
- int W, H;
-
- gScreenScale = [UIScreen mainScreen].scale;
-
-#ifdef USE_GL
-
- CAEAGLLayer* eaglLayer = (CAEAGLLayer*)self.layer;
- if ([self respondsToSelector:@selector(setContentScaleFactor:)]) {
- self.contentScaleFactor = gScreenScale;
- }
-
- // Allocate color buffer backing based on the current layer size
- glBindRenderbufferOES(GL_RENDERBUFFER_OES, fGL.fRenderbuffer);
- [fGL.fContext renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer];
-
- glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &fGL.fWidth);
- glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &fGL.fHeight);
-
- glBindRenderbufferOES(GL_RENDERBUFFER_OES, fGL.fStencilbuffer);
- glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_STENCIL_INDEX8_OES, fGL.fWidth, fGL.fHeight);
-
-
- if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
- {
- NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
- }
-
- W = fGL.fWidth;
- H = fGL.fHeight;
-#else
- CGRect rect = [self bounds];
- W = (int)CGRectGetWidth(rect);
- H = (int)CGRectGetHeight(rect) - TITLE_HEIGHT;
-#endif
-
- printf("---- layoutSubviews %d %d\n", W, H);
- fWind->resize(W, H);
- fWind->inval(NULL);
-}
-
-#ifdef USE_GL
-
-static GrContext* gCtx;
-static GrContext* get_global_grctx() {
- // should be pthread-local at least
- if (NULL == gCtx) {
-#ifdef USE_GL_1
- gCtx = GrContext::Create(kOpenGL_Fixed_GrEngine, 0);
-#else
- gCtx = GrContext::Create(kOpenGL_Shaders_GrEngine, 0);
-#endif
- }
- return gCtx;
-}
-
-#include "SkDevice.h"
-#include "SkShader.h"
-#include "SkGrTexturePixelRef.h"
-#include "GrMesh.h"
-#include "SkRandom.h"
-
-#include "GrAtlas.h"
-#include "GrTextStrike.h"
-
-static void show_fontcache(GrContext* ctx, SkCanvas* canvas) {
-#if 0
- SkPaint paint;
- const int SIZE = 64;
- GrAtlas* plot[64][64];
-
- paint.setAntiAlias(true);
- paint.setTextSize(24);
- paint.setTextAlign(SkPaint::kCenter_Align);
-
- Gr_bzero(plot, sizeof(plot));
-
- GrFontCache* cache = ctx->getFontCache();
- GrTextStrike* strike = cache->getHeadStrike();
- int count = 0;
- while (strike) {
- GrAtlas* atlas = strike->getAtlas();
- while (atlas) {
- int x = atlas->getPlotX();
- int y = atlas->getPlotY();
-
- SkRandom rand((intptr_t)strike);
- SkColor c = rand.nextU() | 0x80808080;
- paint.setColor(c);
- paint.setAlpha(0x80);
-
- SkRect r;
- r.set(x * SIZE, y * SIZE, (x + 1)*SIZE, (y+1)*SIZE);
- r.inset(1, 1);
- canvas->drawRect(r, paint);
-
- paint.setColor(0xFF660000);
- SkString label;
- label.printf("%d", count);
- canvas->drawText(label.c_str(), label.size(), r.centerX(),
- r.fTop + r.height() * 2 / 3, paint);
-
- atlas = atlas->nextAtlas();
- }
- strike = strike->fNext;
- count += 1;
- }
-#endif
-}
-
-void test_patch(SkCanvas* canvas, const SkBitmap& bm, SkScalar scale);
-
-static void draw_mesh(SkCanvas* canvas, const SkBitmap& bm) {
- GrMesh fMesh;
-
- SkRect r;
- r.set(0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()));
-
- // fMesh.init(bounds, fBitmap.width() / 40, fBitmap.height() / 40, texture);
- fMesh.init(r, bm.width()/16, bm.height()/16, r);
-
- SkPaint paint;
- SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
- paint.setShader(s)->unref();
- fMesh.draw(canvas, paint);
-}
-
-static void scale_about(SkCanvas* canvas, float sx, float sy, float px, float py) {
- canvas->translate(px, py);
- canvas->scale(sx, sy);
- canvas->translate(-px, -py);
-}
-
-static float grInterp(float v0, float v1, float percent) {
- return v0 + percent * (v1 - v0);
-}
-
-static void draw_device(SkCanvas* canvas, SkDevice* dev, float w, float h, float warp) {
- canvas->save();
- float s = grInterp(1, 0.8, warp);
- scale_about(canvas, s, s, w/2, h/2);
- test_patch(canvas, dev->accessBitmap(false), warp);
- canvas->restore();
-}
-
-- (void)drawInGL {
-// printf("------ drawInGL\n");
- // This application only creates a single context which is already set current at this point.
- // This call is redundant, but needed if dealing with multiple contexts.
- [EAGLContext setCurrentContext:fGL.fContext];
-
- // This application only creates a single default framebuffer which is already bound at this point.
- // This call is redundant, but needed if dealing with multiple framebuffers.
- glBindFramebufferOES(GL_FRAMEBUFFER_OES, fGL.fFramebuffer);
-
- GLint scissorEnable;
- glGetIntegerv(GL_SCISSOR_TEST, &scissorEnable);
- glDisable(GL_SCISSOR_TEST);
- glClearColor(0,0,0,0);
- glClear(GL_COLOR_BUFFER_BIT);
- if (scissorEnable) {
- glEnable(GL_SCISSOR_TEST);
- }
- glViewport(0, 0, fWind->width(), fWind->height());
-
- GrContext* ctx = get_global_grctx();
-
- //SkGpuCanvas origCanvas(ctx);
- //origCanvas.setBitmapDevice(fWind->getBitmap());
- //gl->reset();
-
- SkCanvas glCanvas;
- SkGpuDevice* dev = new SkGpuDevice(ctx, SkGpuDevice::Current3DApiRenderTarget());
- glCanvas.setDevice(dev)->unref();
-
- SkCanvas rasterCanvas;
-
- SkCanvas* canvas;
- //SkDevice* dev = NULL;
-
- switch (fBackend) {
- case kRaster_Backend:
- canvas = &rasterCanvas;
- break;
- case kGL_Backend:
- canvas = &glCanvas;
- break;
- }
-
-// if (fUseWarp || fWarpState.isActive()) {
-// if (kGL_Backend == fBackend) {
-// dev = origCanvas.createDevice(fWind->getBitmap(), true);
-// canvas->setDevice(dev)->unref();
-// } else {
-// canvas->setBitmapDevice(fWind->getBitmap());
-// dev = canvas->getDevice();
-// }
-// } else {
-// canvas->setBitmapDevice(fWind->getBitmap());
-// dev = NULL;
-// }
-
- canvas->translate(0, TITLE_HEIGHT);
-
- // if we're not "retained", then we have to always redraw everything.
- // This call forces us to ignore the fDirtyRgn, and draw everywhere.
- // If we are "retained", we can skip this call (as the raster case does)
- fWind->forceInvalAll();
-
- FPS_StartDraw();
- [self drawWithCanvas:canvas];
- FPS_EndDraw();
-
-// if (dev) {
-// draw_device(&origCanvas, dev, fWind->width(), fWind->height(),
-// fWarpState.evaluate());
-// } else {
-// if (kRaster_Backend == fBackend) {
-// origCanvas.drawBitmap(fWind->getBitmap(), 0, 0, NULL);
-// }
-// // else GL - we're already on screen
-// }
-
- show_fontcache(ctx, canvas);
- ctx->flush(false);
-
- // This application only creates a single color renderbuffer which is already bound at this point.
- // This call is redundant, but needed if dealing with multiple renderbuffers.
- glBindRenderbufferOES(GL_RENDERBUFFER_OES, fGL.fRenderbuffer);
- [fGL.fContext presentRenderbuffer:GL_RENDERBUFFER_OES];
-
-#if GR_COLLECT_STATS
- static int frame = 0;
- if (!(frame % 100)) {
- get_global_grctx()->printStats();
- }
- get_global_grctx()->resetStats();
- ++frame;
-#endif
-
- FPS_Flush(fWind);
-
-#if 0
- gCtx->deleteAllTextures(GrTextureCache::kAbandonTexture_DeleteMode);
- gCtx->unref();
- gCtx = NULL;
-#endif
-}
-
-#else // raster case
-
-- (void)drawRect:(CGRect)rect {
- SkCanvas canvas;
- canvas.setBitmapDevice(fWind->getBitmap());
- FPS_StartDraw();
- [self drawWithCanvas:&canvas];
- FPS_EndDraw();
-
- CGContextRef cg = UIGraphicsGetCurrentContext();
- SkCGDrawBitmap(cg, fWind->getBitmap(), 0, TITLE_HEIGHT);
-
- FPS_Flush(fWind);
-
-}
-#endif
-
-- (void)setWarpState:(bool)useWarp {
- fWarpState.stop(); // we should reverse from where we are if active...
-
- const float duration = 0.5;
- fUseWarp = useWarp;
- if (useWarp) {
- fWarpState.start(0, 1, duration);
- } else {
- fWarpState.start(1, 0, duration);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-- (void)flushLocalMatrix {
- fMatrix.postConcat(fLocalMatrix);
- fLocalMatrix.reset();
- fFlingState.stop();
- fNeedGestureEnded = false;
- fNeedFirstPinch = true;
-}
-
-- (void)localMatrixWithGesture:(UIGestureRecognizer*)gesture {
- fNeedGestureEnded = true;
-
- switch (gesture.state) {
- case UIGestureRecognizerStateCancelled:
- case UIGestureRecognizerStateEnded:
- [self flushLocalMatrix];
- break;
- case UIGestureRecognizerStateChanged: {
- SkMatrix matrix;
- matrix.setConcat(fLocalMatrix, fMatrix);
- } break;
- default:
- break;
- }
-}
-
-- (void)commonHandleGesture:(UIGestureRecognizer*)sender {
- if (fFlingState.isActive()) {
- [self flushLocalMatrix];
- }
-
- switch (sender.state) {
- case UIGestureRecognizerStateBegan:
- [self flushLocalMatrix];
- break;
- default:
- break;
- }
-}
-
-- (float)limitTotalZoom:(float)scale {
- // this query works 'cause we know that we're square-scale w/ no skew/rotation
- const float curr = fMatrix[0];
-
- if (scale > 1 && curr * scale > MAX_ZOOM_SCALE) {
- scale = MAX_ZOOM_SCALE / curr;
- } else if (scale < 1 && curr * scale < MIN_ZOOM_SCALE) {
- scale = MIN_ZOOM_SCALE / curr;
- }
- return scale;
-}
-
-- (void)handleLongPressGesture:(UILongPressGestureRecognizer*)sender {
- [self commonHandleGesture:sender];
-
- if ([sender numberOfTouches] == 0) {
- fZoomAround = false;
- return;
- }
-
- CGPoint pt = [sender locationOfTouch:0 inView:self];
- switch (sender.state) {
- case UIGestureRecognizerStateBegan:
- case UIGestureRecognizerStateChanged:
- fZoomAround = true;
- fZoomAroundX = pt.x;
- fZoomAroundY = pt.y - Y_OFFSET_FOR_ZOOM_LENS;
- break;
- case UIGestureRecognizerStateEnded:
- case UIGestureRecognizerStateCancelled:
- fZoomAround = false;
- break;
- default:
- break;
- }
-}
-
-- (void)addAndReleaseGesture:(UIGestureRecognizer*)gesture {
- [self addGestureRecognizer:gesture];
- [gesture release];
-}
-
-
-
-//Gesture Handlers
-- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- for (UITouch *touch in touches) {
- CGPoint loc = [touch locationInView:self];
- fWind->handleClick(loc.x, loc.y, SkView::Click::kDown_State, touch);
- }
-}
-
-- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
- for (UITouch *touch in touches) {
- CGPoint loc = [touch locationInView:self];
- fWind->handleClick(loc.x, loc.y, SkView::Click::kMoved_State, touch);
- }
-}
-
-- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
- for (UITouch *touch in touches) {
- CGPoint loc = [touch locationInView:self];
- fWind->handleClick(loc.x, loc.y, SkView::Click::kUp_State, touch);
- }
-}
-
-- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
- for (UITouch *touch in touches) {
- CGPoint loc = [touch locationInView:self];
- fWind->handleClick(loc.x, loc.y, SkView::Click::kUp_State, touch);
- }
-}
-
-- (void)initGestures {
- UILongPressGestureRecognizer* longG = [UILongPressGestureRecognizer alloc];
- [longG initWithTarget:self action:@selector(handleLongPressGesture:)];
- [self addAndReleaseGesture:longG];
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-static float abs(float x) { return x < 0 ? -x : x; }
-
-static bool normalize(UIAcceleration* acc, float xy[]) {
- float mag2 = acc.x*acc.x + acc.y*acc.y + acc.z*acc.z;
- if (mag2 < 0.000001) {
- return false;
- }
- if (abs((float)acc.z) > 0.9 * sqrt(mag2)) {
- return false;
- }
-
- mag2 = acc.x*acc.x + acc.y*acc.y;
- if (mag2 < 0.000001) {
- return false;
- }
- float scale = 1 / sqrt(mag2);
- xy[0] = acc.x * scale;
- xy[1] = acc.y * scale;
- return true;
-}
-
-static void normalize(float xy[]) {
- float scale = 1 / sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
- xy[0] *= scale;
- xy[1] *= scale;
-}
-
-static float weighted_average(float newv, float oldv) {
- return newv * 0.25 + oldv * 0.75;
-}
-
-- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acc {
-
- float norm[2];
- if (normalize(acc, norm)) {
- float sinv = -norm[0];
- float cosv = -norm[1];
- // smooth
- norm[0] = weighted_average(sinv, -fRotateMatrix[1]);
- norm[1] = weighted_average(cosv, fRotateMatrix[0]);
- normalize(norm);
- fRotateMatrix.setSinCos(norm[0], norm[1], 400, 400);
- }
-#if 0
- NSDate *now = [NSDate date];
- NSTimeInterval intervalDate = [now timeIntervalSinceDate:now_prev];
-
- velX += (acceleration.x * intervalDate);
- distX += (velX * intervalDate);
- //do other axis here too
-
- // setup for next UIAccelerometer event
- now_prev = now;
-#endif
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-- (void)setSkTitle:(const char *)title {
- if (fTitle) {
- fTitle.title = [NSString stringWithUTF8String:title];
- }
-}
-
-- (BOOL)onHandleEvent:(const SkEvent&)evt {
- if (evt.isType(kREDRAW_UIVIEW_GL)) {
- [self drawInGL];
- return true;
- }
- return false;
-}
-
-- (void)postInvalWithRect:(const SkIRect*)r {
-#ifdef USE_GL
-
-#if 1
- if (!fRedrawRequestPending) {
- fRedrawRequestPending = true;
- /*
- performSelectorOnMainThread seems to starve updating other views
- (e.g. our FPS view in the titlebar), so we use the afterDelay
- version
- */
- if (0) {
- [self performSelectorOnMainThread:@selector(drawInGL) withObject:nil waitUntilDone:NO];
- } else {
- [self performSelector:@selector(drawInGL) withObject:nil afterDelay:0];
- }
- }
-#else
- if (!fRedrawRequestPending) {
- SkEvent* evt = new SkEvent(kREDRAW_UIVIEW_GL);
- evt->post(fWind->getSinkID());
- fRedrawRequestPending = true;
- }
-#endif
-
-#else
- if (r) {
- [self setNeedsDisplayInRect:CGRectMake(r->fLeft, r->fTop,
- r->width(), r->height())];
- } else {
- [self setNeedsDisplay];
- }
-#endif
-}
-
-@end