aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'gpu')
-rw-r--r--gpu/include/GrContext.h39
-rw-r--r--gpu/include/SkGpuCanvas.h72
-rw-r--r--gpu/include/SkGr.h238
-rw-r--r--gpu/include/SkGrTexturePixelRef.h50
-rw-r--r--gpu/src/GrContext.cpp38
-rw-r--r--gpu/src/GrPrintf_skia.cpp39
-rw-r--r--gpu/src/skia/SkGpuCanvas.cpp60
-rw-r--r--gpu/src/skia/SkGpuDevice.cpp1048
-rw-r--r--gpu/src/skia/SkGpuDevice.h176
-rw-r--r--gpu/src/skia/SkGr.cpp206
-rw-r--r--gpu/src/skia/SkGrFontScaler.cpp142
-rw-r--r--gpu/src/skia/SkGrTexturePixelRef.cpp30
-rw-r--r--gpu/src/skia/skgr_files.mk7
13 files changed, 43 insertions, 2102 deletions
diff --git a/gpu/include/GrContext.h b/gpu/include/GrContext.h
index f9d5ed5090..68f8f7eac0 100644
--- a/gpu/include/GrContext.h
+++ b/gpu/include/GrContext.h
@@ -1,19 +1,19 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
+/*
+ Copyright 2010 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
#ifndef GrContext_DEFINED
#define GrContext_DEFINED
@@ -37,6 +37,11 @@ public:
static GrContext* Create(GrGpu::Engine engine,
GrGpu::Platform3DContext context3D);
+ /**
+ * Helper to create a opengl-shader based context
+ */
+ static GrContext* CreateGLShaderContext();
+
virtual ~GrContext();
/**
@@ -319,4 +324,4 @@ private:
};
#endif
-
+
diff --git a/gpu/include/SkGpuCanvas.h b/gpu/include/SkGpuCanvas.h
deleted file mode 100644
index e8e6e7ae10..0000000000
--- a/gpu/include/SkGpuCanvas.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-
-#ifndef SkGpuCanvas_DEFINED
-#define SkGpuCanvas_DEFINED
-
-#include "SkCanvas.h"
-
-class GrContext;
-
-/**
- * Subclass of canvas that creates devices compatible with the GrContext pass
- * to the canvas' constructor.
- */
-class SkGpuCanvas : public SkCanvas {
-public:
- /**
- * The GrContext object is reference counted. When passed to our
- * constructor, its reference count is incremented. In our destructor, the
- * GrGpu's reference count will be decremented.
- */
- explicit SkGpuCanvas(GrContext*);
- virtual ~SkGpuCanvas();
-
- /**
- * Return our GrContext instance
- */
- GrContext* context() const { return fContext; }
-
- /**
- * Override from SkCanvas. Returns true, and if not-null, sets size to
- * be the width/height of our viewport.
- */
- virtual bool getViewport(SkIPoint* size) const;
-
- /**
- * Override from SkCanvas. Returns a new device of the correct subclass,
- * as determined by the GrGpu passed to our constructor.
- */
- virtual SkDevice* createDevice(SkBitmap::Config, int width, int height,
- bool isOpaque, bool isLayer);
-
-#if 0
- virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
- SaveFlags flags = kARGB_ClipLayer_SaveFlag) {
- return this->save(flags);
- }
-#endif
-
-private:
- GrContext* fContext;
-
- typedef SkCanvas INHERITED;
-};
-
-#endif
-
-
diff --git a/gpu/include/SkGr.h b/gpu/include/SkGr.h
deleted file mode 100644
index 4e9801f699..0000000000
--- a/gpu/include/SkGr.h
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-
-#ifndef SkGr_DEFINED
-#define SkGr_DEFINED
-
-#include <stddef.h>
-
-// tetrark headers
-#include "GrConfig.h"
-#include "GrContext.h"
-#include "GrFontScaler.h"
-#include "GrPathIter.h"
-#include "GrClipIterator.h"
-
-// skia headers
-#include "SkBitmap.h"
-#include "SkPath.h"
-#include "SkPoint.h"
-#include "SkRegion.h"
-#include "SkShader.h"
-
-#if (GR_DEBUG && defined(SK_RELEASE)) || (GR_RELEASE && defined(SK_DEBUG))
-// #error "inconsistent GR_DEBUG and SK_DEBUG"
-#endif
-
-#if GR_SCALAR_IS_FIXED
- #ifdef SK_SCALAR_IS_FIXED
- #define SK_SCALAR_IS_GR_SCALAR 1
- #else
- #define SK_SCALAR_IS_GR_SCALAR 0
- #endif
- #define SkScalarToGrScalar(x) SkScalarToFixed(x)
-
-#elif GR_SCALAR_IS_FLOAT
-
- #ifdef SK_SCALAR_IS_FLOAT
- #define SK_SCALAR_IS_GR_SCALAR 1
- #else
- #define SK_SCALAR_IS_GR_SCALAR 0
- #endif
- #define SkScalarToGrScalar(x) SkScalarToFloat(x)
-
-#else
- #error "Ganesh scalar type not defined"
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// Sk to Gr Type conversions
-
-// Verify that SkPoint and GrPoint are compatible if using the same scalar type
-#if 0/*SK_SCALAR_IS_GR_SCALAR*/
- GR_STATIC_ASSERT(sizeof(SkPoint) == sizeof(GrPoint));
- GR_STATIC_ASSERT(offsetof(SkPoint,fX) == offsetof(GrPoint,fX)));
- GR_STATIC_ASSERT(offsetof(SkPoint,fY) == offsetof(GrPoint,fY)));
-#endif
-
-GR_STATIC_ASSERT((int)GrSamplerState::kClamp_WrapMode == (int)SkShader::kClamp_TileMode);
-GR_STATIC_ASSERT((int)GrSamplerState::kRepeat_WrapMode ==(
- int)SkShader::kRepeat_TileMode);
-GR_STATIC_ASSERT((int)GrSamplerState::kMirror_WrapMode ==
- (int)SkShader::kMirror_TileMode);
-
-#define sk_tile_mode_to_grwrap(X) ((GrSamplerState::WrapMode)(X))
-
-GR_STATIC_ASSERT((int)GrGpu::kZero_BlendCoeff == (int)SkXfermode::kZero_Coeff);
-GR_STATIC_ASSERT((int)GrGpu::kOne_BlendCoeff == (int)SkXfermode::kOne_Coeff);
-GR_STATIC_ASSERT((int)GrGpu::kSC_BlendCoeff == (int)SkXfermode::kSC_Coeff);
-GR_STATIC_ASSERT((int)GrGpu::kISC_BlendCoeff == (int)SkXfermode::kISC_Coeff);
-GR_STATIC_ASSERT((int)GrGpu::kDC_BlendCoeff == (int)SkXfermode::kDC_Coeff);
-GR_STATIC_ASSERT((int)GrGpu::kIDC_BlendCoeff == (int)SkXfermode::kIDC_Coeff);
-GR_STATIC_ASSERT((int)GrGpu::kSA_BlendCoeff == (int)SkXfermode::kSA_Coeff);
-GR_STATIC_ASSERT((int)GrGpu::kISA_BlendCoeff == (int)SkXfermode::kISA_Coeff);
-GR_STATIC_ASSERT((int)GrGpu::kDA_BlendCoeff == (int)SkXfermode::kDA_Coeff);
-GR_STATIC_ASSERT((int)GrGpu::kIDA_BlendCoeff == (int)SkXfermode::kIDA_Coeff);
-
-#define sk_blend_to_grblend(X) ((GrGpu::BlendCoeff)(X))
-
-GR_STATIC_ASSERT((int)SkPath::kMove_Verb == (int)GrPathIter::kMove_Command);
-GR_STATIC_ASSERT((int)SkPath::kLine_Verb == (int)GrPathIter::kLine_Command);
-GR_STATIC_ASSERT((int)SkPath::kQuad_Verb == (int)GrPathIter::kQuadratic_Command);
-GR_STATIC_ASSERT((int)SkPath::kCubic_Verb == (int)GrPathIter::kCubic_Command);
-GR_STATIC_ASSERT((int)SkPath::kClose_Verb == (int)GrPathIter::kClose_Command);
-GR_STATIC_ASSERT((int)SkPath::kDone_Verb == (int)GrPathIter::kEnd_Command);
-
-#define sk_path_verb_to_gr_path_command(X) ((GrPathIter::Command)(X))
-
-///////////////////////////////////////////////////////////////////////////////
-
-#include "SkColorPriv.h"
-
-static inline GrRect Sk2Gr(const SkRect& src) {
- return GrRect(SkScalarToGrScalar(src.fLeft),
- SkScalarToGrScalar(src.fTop),
- SkScalarToGrScalar(src.fRight),
- SkScalarToGrScalar(src.fBottom));
-}
-
-class SkGr {
-public:
- static inline SkIRect& SetIRect(SkIRect* dst, const GrIRect& src) {
- GR_STATIC_ASSERT(sizeof(*dst) == sizeof(src));
- memcpy(dst, &src, sizeof(*dst));
- return *dst;
- }
-
- static inline GrIRect& SetIRect(GrIRect* dst, const SkIRect& src) {
- GR_STATIC_ASSERT(sizeof(*dst) == sizeof(src));
- memcpy(dst, &src, sizeof(*dst));
- return *dst;
- }
-
- /**
- * Convert the SkBitmap::Config to the corresponding PixelConfig, or
- * kUnknown_PixelConfig if the conversion cannot be done.
- */
- static GrTexture::PixelConfig BitmapConfig2PixelConfig(SkBitmap::Config,
- bool isOpaque);
-
- static GrTexture::PixelConfig Bitmap2PixelConfig(const SkBitmap& bm) {
- return BitmapConfig2PixelConfig(bm.config(), bm.isOpaque());
- }
-
- static void SkMatrix2GrMatrix(const SkMatrix& m, GrMatrix* g) {
- g->setAll(SkScalarToGrScalar(m[0]),
- SkScalarToGrScalar(m[1]),
- SkScalarToGrScalar(m[2]),
- SkScalarToGrScalar(m[3]),
- SkScalarToGrScalar(m[4]),
- SkScalarToGrScalar(m[5]),
- SkScalarToGrScalar(m[6]),
- SkScalarToGrScalar(m[7]),
- SkScalarToGrScalar(m[8]));
- }
-
- static GrColor SkColor2GrColor(SkColor c) {
- SkPMColor pm = SkPreMultiplyColor(c);
- unsigned r = SkGetPackedR32(pm);
- unsigned g = SkGetPackedG32(pm);
- unsigned b = SkGetPackedB32(pm);
- unsigned a = SkGetPackedA32(pm);
- return GrColorPackRGBA(r, g, b, a);
- }
-
- /**
- * This abandons all texture caches (for bitmaps and text) associated with
- * the gpu, and frees any associated skia caches. It differs from
- * deleteAllTextures in that it assumes that the gpu has lots its context,
- * and thus the associated HW textures are no longer valid
- */
- static void AbandonAllTextures(GrContext*);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// Classes
-
-class SkGrPathIter : public GrPathIter {
-public:
- SkGrPathIter(const SkPath& path) : fIter(path, false), fPath(path) {}
- virtual Command next(GrPoint pts[]);
- virtual Command next();
- virtual void rewind();
- virtual ConvexHint hint() const;
-private:
-
-#if !SK_SCALAR_IS_GR_SCALAR
- SkPoint fPoints[4];
-#endif
- SkPath::Iter fIter;
- const SkPath& fPath;
-};
-
-class SkGrClipIterator : public GrClipIterator {
-public:
- void reset(const SkRegion& clip) {
- fIter.reset(clip);
- this->invalidateBoundsCache();
- }
-
- // overrides
-
- virtual bool isDone() { return fIter.done(); }
- virtual void getRect(GrIRect* rect) {
- SkGr::SetIRect(rect, fIter.rect());
- }
- virtual void next() { fIter.next(); }
- virtual void rewind() { fIter.rewind(); }
- virtual void computeBounds(GrIRect* bounds);
-
-private:
- SkRegion::Iterator fIter;
-};
-
-class SkGlyphCache;
-
-class SkGrFontScaler : public GrFontScaler {
-public:
- explicit SkGrFontScaler(SkGlyphCache* strike);
- virtual ~SkGrFontScaler();
-
- // overrides
- virtual const GrKey* getKey();
- virtual bool getPackedGlyphBounds(GrGlyph::PackedID, GrIRect* bounds);
- virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
- int rowBytes, void* image);
- virtual bool getGlyphPath(uint16_t glyphID, GrPath*);
-
-private:
- SkGlyphCache* fStrike;
- GrKey* fKey;
-// DECLARE_INSTANCE_COUNTER(SkGrFontScaler);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// Helper functions
-
-GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx,
- GrTextureKey* key,
- const GrSamplerState& sampler,
- const SkBitmap& bitmap);
-
-void sk_gr_set_paint(GrContext* ctx, const SkPaint& paint, bool justAlpha = false);
-
-#endif
diff --git a/gpu/include/SkGrTexturePixelRef.h b/gpu/include/SkGrTexturePixelRef.h
deleted file mode 100644
index 1f5133f86d..0000000000
--- a/gpu/include/SkGrTexturePixelRef.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-
-#ifndef SkGrTexturePixelRef_DEFINED
-#define SkGrTexturePixelRef_DEFINED
-
-#include "SkPixelRef.h"
-#include "GrGpu.h"
-
-class SkGrTexturePixelRef : public SkPixelRef {
-public:
- SkGrTexturePixelRef(GrTexture*);
- virtual ~SkGrTexturePixelRef();
-
- // override from SkPixelRef
- virtual SkGpuTexture* getTexture() { return (SkGpuTexture*)fTexture; }
-
-protected:
- // override from SkPixelRef
- virtual void* onLockPixels(SkColorTable** ptr) {
- if (ptr) {
- *ptr = NULL;
- }
- return NULL;
- }
-
- // override from SkPixelRef
- virtual void onUnlockPixels() {}
-
-private:
- GrTexture* fTexture;
- typedef SkPixelRef INHERITED;
-};
-
-#endif
-
diff --git a/gpu/src/GrContext.cpp b/gpu/src/GrContext.cpp
index 6e94ef787f..942afa3021 100644
--- a/gpu/src/GrContext.cpp
+++ b/gpu/src/GrContext.cpp
@@ -1,19 +1,19 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
+/*
+ Copyright 2010 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
#include "GrContext.h"
#include "GrTextureCache.h"
@@ -49,6 +49,10 @@ GrContext* GrContext::Create(GrGpu::Engine engine,
return ctx;
}
+GrContext* GrContext::CreateGLShaderContext() {
+ return GrContext::Create(GrGpu::kOpenGL_Shaders_Engine, NULL);
+}
+
GrContext::~GrContext() {
fGpu->unref();
delete fTextureCache;
@@ -1037,4 +1041,4 @@ int GrContext::maxQuadsInIndexBuffer() const {
-
+
diff --git a/gpu/src/GrPrintf_skia.cpp b/gpu/src/GrPrintf_skia.cpp
deleted file mode 100644
index fa8b6a7647..0000000000
--- a/gpu/src/GrPrintf_skia.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-
-#include "GrTypes.h"
-
-#include <stdarg.h>
-#include <stdio.h>
-
-#include "SkTypes.h"
-
-void GrPrintf(const char format[], ...) {
- const size_t MAX_BUFFER_SIZE = 512;
-
- char buffer[MAX_BUFFER_SIZE + 1];
- va_list args;
-
- va_start(args, format);
- vsnprintf(buffer, MAX_BUFFER_SIZE, format, args);
- va_end(args);
-
- // skia has already mapped this to do the "right thing"
- SkDebugf("%s", buffer);
-}
-
-
diff --git a/gpu/src/skia/SkGpuCanvas.cpp b/gpu/src/skia/SkGpuCanvas.cpp
deleted file mode 100644
index 19bda4d943..0000000000
--- a/gpu/src/skia/SkGpuCanvas.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-
-#include "GrContext.h"
-
-#include "SkGpuCanvas.h"
-#include "SkGpuDevice.h"
-
-///////////////////////////////////////////////////////////////////////////////
-
-SkGpuCanvas::SkGpuCanvas(GrContext* context) {
- SkASSERT(context);
- fContext = context;
- fContext->ref();
-}
-
-SkGpuCanvas::~SkGpuCanvas() {
- // call this now, while our override of restore() is in effect
- this->restoreToCount(1);
- fContext->flush(false);
- fContext->unref();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-bool SkGpuCanvas::getViewport(SkIPoint* size) const {
- if (size) {
- SkDevice* device = this->getDevice();
- if (device) {
- size->set(device->width(), device->height());
- } else {
- size->set(0, 0);
- }
- }
- return true;
-}
-
-SkDevice* SkGpuCanvas::createDevice(SkBitmap::Config config, int width, int height,
- bool isOpaque, bool isLayer) {
- SkBitmap bm;
- bm.setConfig(config, width, height);
- bm.setIsOpaque(isOpaque);
- return new SkGpuDevice(this, bm, isLayer);
-}
-
-
diff --git a/gpu/src/skia/SkGpuDevice.cpp b/gpu/src/skia/SkGpuDevice.cpp
deleted file mode 100644
index 832fc6ea75..0000000000
--- a/gpu/src/skia/SkGpuDevice.cpp
+++ /dev/null
@@ -1,1048 +0,0 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-
-#include "GrContext.h"
-#include "GrTextContext.h"
-
-#include "SkGpuCanvas.h"
-#include "SkGpuDevice.h"
-#include "SkGrTexturePixelRef.h"
-
-#include "SkDrawProcs.h"
-#include "SkGlyphCache.h"
-
-#define CACHE_LAYER_TEXTURES 1
-
-#if 0
- extern bool (*gShouldDrawProc)();
- #define CHECK_SHOULD_DRAW(draw) \
- do { \
- if (gShouldDrawProc && !gShouldDrawProc()) return; \
- this->prepareRenderTarget(draw); \
- } while (0)
-#else
- #define CHECK_SHOULD_DRAW(draw) this->prepareRenderTarget(draw)
-#endif
-
-class SkAutoExtMatrix {
-public:
- SkAutoExtMatrix(const SkMatrix* extMatrix) {
- if (extMatrix) {
- SkGr::SkMatrix2GrMatrix(*extMatrix, &fMatrix);
- fExtMatrix = &fMatrix;
- } else {
- fExtMatrix = NULL;
- }
- }
- const GrMatrix* extMatrix() const { return fExtMatrix; }
-
-private:
- GrMatrix fMatrix;
- GrMatrix* fExtMatrix; // NULL or &fMatrix
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-SkGpuDevice::SkAutoCachedTexture::
- SkAutoCachedTexture(SkGpuDevice* device,
- const SkBitmap& bitmap,
- const GrSamplerState& sampler,
- GrTexture** texture) {
- GrAssert(texture);
- fTex = NULL;
- *texture = this->set(device, bitmap, sampler);
-}
-
-SkGpuDevice::SkAutoCachedTexture::SkAutoCachedTexture() {
- fTex = NULL;
-}
-
-GrTexture* SkGpuDevice::SkAutoCachedTexture::set(SkGpuDevice* device,
- const SkBitmap& bitmap,
- const GrSamplerState& sampler) {
- if (fTex) {
- fDevice->unlockCachedTexture(fTex);
- }
- fDevice = device;
- GrTexture* texture = (GrTexture*)bitmap.getTexture();
- if (texture) {
- // return the native texture
- fTex = NULL;
- device->context()->setTexture(texture);
- } else {
- // look it up in our cache
- fTex = device->lockCachedTexture(bitmap, sampler, &texture, false);
- }
- return texture;
-}
-
-SkGpuDevice::SkAutoCachedTexture::~SkAutoCachedTexture() {
- if (fTex) {
- fDevice->unlockCachedTexture(fTex);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-bool gDoTraceDraw;
-
-struct GrSkDrawProcs : public SkDrawProcs {
-public:
- GrContext* fContext;
- GrTextContext* fTextContext;
- GrFontScaler* fFontScaler; // cached in the skia glyphcache
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-SkGpuDevice::SkGpuDevice(SkGpuCanvas* canvas, const SkBitmap& bitmap, bool isLayer)
- : SkDevice(canvas, bitmap, false) {
-
- fNeedPrepareRenderTarget = false;
- fDrawProcs = NULL;
-
- fContext = canvas->context();
-
- fCache = NULL;
- fTexture = NULL;
- fRenderTarget = NULL;
- fNeedClear = false;
-
- if (isLayer) {
- SkBitmap::Config c = bitmap.config();
- if (c != SkBitmap::kRGB_565_Config) {
- c = SkBitmap::kARGB_8888_Config;
- }
- SkBitmap bm;
- bm.setConfig(c, this->width(), this->height());
-
-#if CACHE_LAYER_TEXTURES
-
- fCache = this->lockCachedTexture(bm, GrSamplerState::ClampNoFilter(),
- &fTexture, true);
- if (fCache) {
- SkASSERT(NULL != fTexture);
- SkASSERT(fTexture->isRenderTarget());
- }
-#else
- const GrGpu::TextureDesc desc = {
- GrGpu::kRenderTarget_TextureFlag,
- GrGpu::kNone_AALevel,
- this->width(),
- this->height(),
- SkGr::Bitmap2PixelConfig(bm)
- };
-
- fTexture = fContext->createUncachedTexture(desc, NULL, 0);
-#endif
- if (NULL != fTexture) {
- fRenderTarget = fTexture->asRenderTarget();
-
- GrAssert(NULL != fRenderTarget);
-
- // we defer the actual clear until our gainFocus()
- fNeedClear = true;
-
- // wrap the bitmap with a pixelref to expose our texture
- SkGrTexturePixelRef* pr = new SkGrTexturePixelRef(fTexture);
- this->setPixelRef(pr, 0)->unref();
- } else {
- GrPrintf("--- failed to create gpu-offscreen [%d %d]\n",
- this->width(), this->height());
- }
- }
-
- if (NULL == fRenderTarget) {
- GrAssert(NULL == fCache);
- GrAssert(NULL == fTexture);
-
- fRenderTarget = fContext->currentRenderTarget();
- fRenderTarget->ref();
- fContext->setDefaultRenderTargetSize(this->width(), this->height());
- }
-}
-
-SkGpuDevice::~SkGpuDevice() {
- if (fDrawProcs) {
- delete fDrawProcs;
- }
-
- if (fCache) {
- GrAssert(NULL != fTexture);
- GrAssert(fRenderTarget == fTexture->asRenderTarget());
- // IMPORTANT: reattach the rendertarget/tex back to the cache.
- fContext->reattachAndUnlockCachedTexture((GrTextureEntry*)fCache);
- } else if (NULL != fTexture) {
- GrAssert(!CACHE_LAYER_TEXTURES);
- GrAssert(fRenderTarget == fTexture->asRenderTarget());
- fTexture->unref();
- } else if (NULL != fRenderTarget) {
- fRenderTarget->unref();
- }
-}
-
-void SkGpuDevice::bindDeviceToTargetHandle(intptr_t handle) {
- if (fCache) {
- GrAssert(NULL != fTexture);
- GrAssert(fRenderTarget == fTexture->asRenderTarget());
- // IMPORTANT: reattach the rendertarget/tex back to the cache.
- fContext->reattachAndUnlockCachedTexture((GrTextureEntry*)fCache);
- } else if (NULL != fTexture) {
- GrAssert(!CACHE_LAYER_TEXTURES);
- fTexture->unref();
- } else if (NULL != fRenderTarget) {
- fRenderTarget->unref();
- }
-
- fCache = NULL;
- fTexture = NULL;
- fRenderTarget = fContext->createPlatformRenderTarget(handle,
- this->width(),
- this->height());
-}
-
-intptr_t SkGpuDevice::getLayerTextureHandle() const {
- if (fTexture) {
- return fTexture->getTextureHandle();
- } else {
- return 0;
- }
-}
-///////////////////////////////////////////////////////////////////////////////
-
-void SkGpuDevice::makeRenderTargetCurrent() {
- fContext->setRenderTarget(fRenderTarget);
- fContext->flush(true);
- fNeedPrepareRenderTarget = true;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-bool SkGpuDevice::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
- SkIRect bounds;
- bounds.set(0, 0, this->width(), this->height());
- if (!bounds.intersect(srcRect)) {
- return false;
- }
-
- const int w = bounds.width();
- const int h = bounds.height();
- SkBitmap tmp;
- // note we explicitly specify our rowBytes to be snug (no gap between rows)
- tmp.setConfig(SkBitmap::kARGB_8888_Config, w, h, w * 4);
- if (!tmp.allocPixels()) {
- return false;
- }
-
- SkAutoLockPixels alp(tmp);
- fContext->setRenderTarget(fRenderTarget);
- // we aren't setting the clip or matrix, so mark as dirty
- // we don't need to set them for this call and don't have them anyway
- fNeedPrepareRenderTarget = true;
-
- if (!fContext->readPixels(bounds.fLeft, bounds.fTop,
- bounds.width(), bounds.height(),
- GrTexture::kRGBA_8888_PixelConfig,
- tmp.getPixels())) {
- return false;
- }
-
- tmp.swap(*bitmap);
- return true;
-}
-
-void SkGpuDevice::writePixels(const SkBitmap& bitmap, int x, int y) {
- SkAutoLockPixels alp(bitmap);
- if (!bitmap.readyToDraw()) {
- return;
- }
- GrTexture::PixelConfig config = SkGr::BitmapConfig2PixelConfig(bitmap.config(),
- bitmap.isOpaque());
- fContext->setRenderTarget(fRenderTarget);
- // we aren't setting the clip or matrix, so mark as dirty
- // we don't need to set them for this call and don't have them anyway
- fNeedPrepareRenderTarget = true;
-
- fContext->writePixels(x, y, bitmap.width(), bitmap.height(),
- config, bitmap.getPixels(), bitmap.rowBytes());
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-static void convert_matrixclip(GrContext* context, const SkMatrix& matrix,
- const SkRegion& clip) {
- GrMatrix grmat;
- SkGr::SkMatrix2GrMatrix(matrix, &grmat);
- context->setViewMatrix(grmat);
-
- SkGrClipIterator iter;
- iter.reset(clip);
- GrClip grc(&iter);
- if (context->getClip() == grc) {
- } else {
- context->setClip(grc);
- }
-}
-
-// call this ever each draw call, to ensure that the context reflects our state,
-// and not the state from some other canvas/device
-void SkGpuDevice::prepareRenderTarget(const SkDraw& draw) {
- if (fNeedPrepareRenderTarget ||
- fContext->currentRenderTarget() != fRenderTarget) {
-
- fContext->setRenderTarget(fRenderTarget);
- convert_matrixclip(fContext, *draw.fMatrix, *draw.fClip);
- fNeedPrepareRenderTarget = false;
- }
-}
-
-void SkGpuDevice::setMatrixClip(const SkMatrix& matrix, const SkRegion& clip) {
- this->INHERITED::setMatrixClip(matrix, clip);
-
- convert_matrixclip(fContext, matrix, clip);
-}
-
-void SkGpuDevice::gainFocus(SkCanvas* canvas, const SkMatrix& matrix,
- const SkRegion& clip) {
- fContext->setRenderTarget(fRenderTarget);
-
- this->INHERITED::gainFocus(canvas, matrix, clip);
-
- convert_matrixclip(fContext, matrix, clip);
-
- if (fNeedClear) {
- fContext->eraseColor(0x0);
- fNeedClear = false;
- }
-}
-
-bool SkGpuDevice::bindDeviceAsTexture(SkPoint* max) {
- if (NULL != fTexture) {
- fContext->setTexture(fTexture);
- if (NULL != max) {
- max->set(SkFixedToScalar((width() << 16) /
- fTexture->allocWidth()),
- SkFixedToScalar((height() << 16) /
- fTexture->allocHeight()));
- }
- return true;
- }
- return false;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-// must be in the same order as SkXfermode::Coeff in SkXfermode.h
-
-SkGpuDevice::AutoPaintShader::AutoPaintShader() {
- fSuccess = false;
- fTexture = NULL;
-}
-
-SkGpuDevice::AutoPaintShader::AutoPaintShader(SkGpuDevice* device,
- const SkPaint& paint,
- const SkMatrix& matrix) {
- fSuccess = false;
- fTexture = NULL;
- this->init(device, paint, matrix);
-}
-
-void SkGpuDevice::AutoPaintShader::init(SkGpuDevice* device,
- const SkPaint& paint,
- const SkMatrix& ctm) {
- fSuccess = true;
- GrContext* ctx = device->context();
- sk_gr_set_paint(ctx, paint); // should we pass true for justAlpha if we have a shader/texture?
-
- SkShader* shader = paint.getShader();
- if (NULL == shader) {
- return;
- }
-
- if (!shader->setContext(device->accessBitmap(false), paint, ctm)) {
- fSuccess = false;
- return;
- }
-
- GrSamplerState::SampleMode sampleMode;
- SkBitmap bitmap;
- SkMatrix matrix;
- SkShader::TileMode tileModes[2];
- SkScalar twoPointParams[3];
- SkShader::BitmapType bmptype = shader->asABitmap(&bitmap, &matrix,
- tileModes, twoPointParams);
-
- switch (bmptype) {
- case SkShader::kNone_BitmapType:
- SkDebugf("shader->asABitmap() == kNone_BitmapType");
- return;
- case SkShader::kDefault_BitmapType:
- sampleMode = GrSamplerState::kNormal_SampleMode;
- break;
- case SkShader::kRadial_BitmapType:
- sampleMode = GrSamplerState::kRadial_SampleMode;
- break;
- case SkShader::kSweep_BitmapType:
- sampleMode = GrSamplerState::kSweep_SampleMode;
- break;
- case SkShader::kTwoPointRadial_BitmapType:
- sampleMode = GrSamplerState::kRadial2_SampleMode;
- break;
- default:
- SkASSERT("Unexpected return from asABitmap");
- return;
- }
-
- bitmap.lockPixels();
- if (!bitmap.getTexture() && !bitmap.readyToDraw()) {
- return;
- }
-
- // see if we've already cached the bitmap from the shader
- GrSamplerState samplerState(sk_tile_mode_to_grwrap(tileModes[0]),
- sk_tile_mode_to_grwrap(tileModes[1]),
- sampleMode,
- paint.isFilterBitmap());
-
- if (GrSamplerState::kRadial2_SampleMode == sampleMode) {
- samplerState.setRadial2Params(twoPointParams[0],
- twoPointParams[1],
- twoPointParams[2] < 0);
- }
-
- GrTexture* texture = fCachedTexture.set(device, bitmap, samplerState);
- if (NULL == texture) {
- return;
- }
-
- // the lock has already called setTexture for us
- ctx->setSamplerState(samplerState);
-
- // since our texture coords will be in local space, we wack the texture
- // matrix to map them back into 0...1 before we load it
- SkMatrix localM;
- if (shader->getLocalMatrix(&localM)) {
- SkMatrix inverse;
- if (localM.invert(&inverse)) {
- matrix.preConcat(inverse);
- }
- }
- if (SkShader::kDefault_BitmapType == bmptype) {
- GrScalar sx = (GR_Scalar1 * texture->contentWidth()) /
- (bitmap.width() * texture->allocWidth());
- GrScalar sy = (GR_Scalar1 * texture->contentHeight()) /
- (bitmap.height() * texture->allocHeight());
- matrix.postScale(sx, sy);
-
- } else if (SkShader::kRadial_BitmapType == bmptype) {
- GrScalar s = (GR_Scalar1 * texture->contentWidth()) /
- (bitmap.width() * texture->allocWidth());
- matrix.postScale(s, s);
- }
- GrMatrix grmat;
- SkGr::SkMatrix2GrMatrix(matrix, &grmat);
- ctx->setTextureMatrix(grmat);
-
- // since we're going to use a shader/texture, we don't want the color,
- // just its alpha
- ctx->setAlpha(paint.getAlpha());
- // report that we have setup the texture
- fSuccess = true;
- fTexture = texture;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-
-void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw);
-
- AutoPaintShader shader(this, paint, *draw.fMatrix);
- if (shader.failed()) {
- return;
- }
- fContext->drawFull(shader.useTex());
-}
-
-// must be in SkCanvas::PointMode order
-static const GrGpu::PrimitiveType gPointMode2PrimtiveType[] = {
- GrGpu::kPoints_PrimitiveType,
- GrGpu::kLines_PrimitiveType,
- GrGpu::kLineStrip_PrimitiveType
-};
-
-void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
- size_t count, const SkPoint pts[], const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw);
-
- SkScalar width = paint.getStrokeWidth();
- if (width < 0) {
- return;
- }
-
- // we only handle hairlines here, else we let the SkDraw call our drawPath()
- if (width > 0) {
- draw.drawPoints(mode, count, pts, paint, true);
- return;
- }
-
- AutoPaintShader shader(this, paint, *draw.fMatrix);
- if (shader.failed()) {
- return;
- }
-
- GrVertexLayout layout = shader.useTex() ?
- GrDrawTarget::kPositionAsTexCoord_VertexLayoutBit :
- 0;
-#if SK_SCALAR_IS_GR_SCALAR
- fContext->setVertexSourceToArray(pts, layout);
- fContext->drawNonIndexed(gPointMode2PrimtiveType[mode], 0, count);
-#else
- GrPoint* v;
- fContext->reserveAndLockGeometry(layout, count, 0, (void**)&v, NULL);
- for (int i = 0; i < count; ++i) {
- v[i].set(SkScalarToGrScalar(pts[i].fX), SkScalarToGrScalar(pts[i].fY));
- }
- fContext->drawNonIndexed(gPointMode2PrimtiveType[mode], layout, 0, count);
- fContext->releaseReservedGeometry();
-#endif
-
-}
-
-void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
- const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw);
-
- bool doStroke = paint.getStyle() == SkPaint::kStroke_Style;
- SkScalar width = paint.getStrokeWidth();
-
- /*
- We have special code for hairline strokes, miter-strokes, and fills.
- Anything else we just call our path code. (i.e. non-miter thick stroke)
- */
- if (doStroke && width > 0 && paint.getStrokeJoin() != SkPaint::kMiter_Join) {
- SkPath path;
- path.addRect(rect);
- this->drawPath(draw, path, paint, NULL, true);
- return;
- }
-
- AutoPaintShader shader(this, paint, *draw.fMatrix);
- if (shader.failed()) {
- return;
- }
-
- fContext->drawRect(Sk2Gr(rect), shader.useTex(), doStroke ? width : -1);
-}
-
-void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& path,
- const SkPaint& paint, const SkMatrix* prePathMatrix,
- bool pathIsMutable) {
- CHECK_SHOULD_DRAW(draw);
-
- AutoPaintShader shader(this, paint, *draw.fMatrix);
- if (shader.failed()) {
- return;
- }
-
- const SkPath* pathPtr = &path;
- SkPath tmpPath;
-
- if (prePathMatrix) {
- if (pathIsMutable) {
- const_cast<SkPath*>(pathPtr)->transform(*prePathMatrix);
- } else {
- path.transform(*prePathMatrix, &tmpPath);
- pathPtr = &tmpPath;
- }
- }
-
- SkPath fillPath;
- GrContext::PathFills fill = GrContext::kHairLine_PathFill;
-
- if (paint.getFillPath(*pathPtr, &fillPath)) {
- switch (fillPath.getFillType()) {
- case SkPath::kWinding_FillType:
- fill = GrContext::kWinding_PathFill;
- break;
- case SkPath::kEvenOdd_FillType:
- fill = GrContext::kEvenOdd_PathFill;
- break;
- case SkPath::kInverseWinding_FillType:
- fill = GrContext::kInverseWinding_PathFill;
- break;
- case SkPath::kInverseEvenOdd_FillType:
- fill = GrContext::kInverseEvenOdd_PathFill;
- break;
- default:
- SkDebugf("Unsupported path fill type");
- return;
- }
- }
-
- SkGrPathIter iter(fillPath);
- fContext->drawPath(&iter, fill, shader.useTex());
-}
-
-/*
- * This value must not exceed the GPU's texture dimension limit, but it can
- * be smaller, if that helps avoid very large single textures hurting the
- * cache.
- */
-#define MAX_TEXTURE_DIM 512
-
-void SkGpuDevice::drawBitmap(const SkDraw& draw,
- const SkBitmap& bitmap,
- const SkIRect* srcRectPtr,
- const SkMatrix& m,
- const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw);
-
- SkIRect srcRect;
- if (NULL == srcRectPtr) {
- srcRect.set(0, 0, bitmap.width(), bitmap.height());
- } else {
- srcRect = *srcRectPtr;
- }
-
- if (bitmap.getTexture() || (bitmap.width() <= MAX_TEXTURE_DIM &&
- bitmap.height() <= MAX_TEXTURE_DIM)) {
- // take the fast case
- this->internalDrawBitmap(draw, bitmap, srcRect, m, paint);
- return;
- }
-
- // undo the translate done by SkCanvas
- int DX = SkMax32(0, srcRect.fLeft);
- int DY = SkMax32(0, srcRect.fTop);
- // compute clip bounds in local coordinates
- SkIRect clipRect;
- {
- SkRect r;
- r.set(draw.fClip->getBounds());
- SkMatrix matrix, inverse;
- matrix.setConcat(*draw.fMatrix, m);
- if (!matrix.invert(&inverse)) {
- return;
- }
- inverse.mapRect(&r);
- r.roundOut(&clipRect);
- // apply the canvas' translate to our local clip
- clipRect.offset(DX, DY);
- }
-
- int nx = bitmap.width() / MAX_TEXTURE_DIM;
- int ny = bitmap.height() / MAX_TEXTURE_DIM;
- for (int x = 0; x <= nx; x++) {
- for (int y = 0; y <= ny; y++) {
- SkIRect tileR;
- tileR.set(x * MAX_TEXTURE_DIM, y * MAX_TEXTURE_DIM,
- (x + 1) * MAX_TEXTURE_DIM, (y + 1) * MAX_TEXTURE_DIM);
- if (!SkIRect::Intersects(tileR, clipRect)) {
- continue;
- }
-
- SkIRect srcR = tileR;
- if (!srcR.intersect(srcRect)) {
- continue;
- }
-
- SkBitmap tmpB;
- if (bitmap.extractSubset(&tmpB, tileR)) {
- // now offset it to make it "local" to our tmp bitmap
- srcR.offset(-tileR.fLeft, -tileR.fTop);
-
- SkMatrix tmpM(m);
- {
- int dx = tileR.fLeft - DX + SkMax32(0, srcR.fLeft);
- int dy = tileR.fTop - DY + SkMax32(0, srcR.fTop);
- tmpM.preTranslate(SkIntToScalar(dx), SkIntToScalar(dy));
- }
- this->internalDrawBitmap(draw, tmpB, srcR, tmpM, paint);
- }
- }
- }
-}
-
-/*
- * This is called by drawBitmap(), which has to handle images that may be too
- * large to be represented by a single texture.
- *
- * internalDrawBitmap assumes that the specified bitmap will fit in a texture.
- */
-void SkGpuDevice::internalDrawBitmap(const SkDraw& draw,
- const SkBitmap& bitmap,
- const SkIRect& srcRect,
- const SkMatrix& m,
- const SkPaint& paint) {
- SkASSERT(bitmap.width() <= MAX_TEXTURE_DIM &&
- bitmap.height() <= MAX_TEXTURE_DIM);
-
- SkAutoLockPixels alp(bitmap);
- if (!bitmap.getTexture() && !bitmap.readyToDraw()) {
- return;
- }
-
- GrSamplerState sampler(paint.isFilterBitmap()); // defaults to clamp
- // the lock has already called setTexture for us
- fContext->setSamplerState(sampler);
-
- GrTexture* texture;
- SkAutoCachedTexture act(this, bitmap, sampler, &texture);
- if (NULL == texture) {
- return;
- }
-
- GrVertexLayout layout = GrDrawTarget::kSeparateTexCoord_VertexLayoutBit;
-
- GrPoint* vertex;
- if (!fContext->reserveAndLockGeometry(layout, 4,
- 0, (void**)&vertex, NULL)) {
- return;
- }
-
- {
- GrMatrix grmat;
- SkGr::SkMatrix2GrMatrix(m, &grmat);
- vertex[0].setIRectFan(0, 0, srcRect.width(), srcRect.height(),
- 2*sizeof(GrPoint));
- grmat.mapPointsWithStride(vertex, 2*sizeof(GrPoint), 4);
- }
-
- SkScalar left = SkFixedToScalar((srcRect.fLeft << 16) /
- texture->allocWidth());
- SkScalar right = SkFixedToScalar((srcRect.fRight << 16) /
- texture->allocWidth());
- SkScalar top = SkFixedToScalar((srcRect.fTop << 16) /
- texture->allocHeight());
- SkScalar bottom = SkFixedToScalar((srcRect.fBottom << 16) /
- texture->allocHeight());
- vertex[1].setRectFan(left, top, right, bottom, 2*sizeof(GrPoint));
-
- fContext->setTextureMatrix(GrMatrix::I());
- // now draw the mesh
- sk_gr_set_paint(fContext, paint, true);
- fContext->drawNonIndexed(GrGpu::kTriangleFan_PrimitiveType, 0, 4);
- fContext->releaseReservedGeometry();
-}
-
-static void gl_drawSprite(GrContext* ctx,
- int x, int y, int w, int h, const SkPoint& max,
- const SkPaint& paint) {
- GrAutoViewMatrix avm(ctx, GrMatrix::I());
-
- ctx->setSamplerState(GrSamplerState::ClampNoFilter());
- ctx->setTextureMatrix(GrMatrix::I());
-
- GrPoint* vertex;
- GrVertexLayout layout = GrGpu::kSeparateTexCoord_VertexLayoutBit;
- if (!ctx->reserveAndLockGeometry(layout, 4, 0, (void**)&vertex, NULL)) {
- return;
- }
-
- vertex[1].setRectFan(0, 0, max.fX, max.fY, 2*sizeof(GrPoint));
-
- vertex[0].setIRectFan(x, y, x + w, y + h, 2*sizeof(GrPoint));
-
- sk_gr_set_paint(ctx, paint, true);
- // should look to use glDrawTexi() has we do for text...
- ctx->drawNonIndexed(GrGpu::kTriangleFan_PrimitiveType, 0, 4);
- ctx->releaseReservedGeometry();
-}
-
-void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
- int left, int top, const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw);
-
- SkAutoLockPixels alp(bitmap);
- if (!bitmap.getTexture() && !bitmap.readyToDraw()) {
- return;
- }
-
- SkPoint max;
- GrTexture* texture;
- SkAutoCachedTexture act(this, bitmap, GrSamplerState::ClampNoFilter(),
- &texture);
-
- max.set(SkFixedToScalar((texture->contentWidth() << 16) /
- texture->allocWidth()),
- SkFixedToScalar((texture->contentHeight() << 16) /
- texture->allocHeight()));
- gl_drawSprite(fContext, left, top, bitmap.width(), bitmap.height(), max, paint);
-}
-
-void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* dev,
- int x, int y, const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw);
-
- SkPoint max;
- if (((SkGpuDevice*)dev)->bindDeviceAsTexture(&max)) {
- const SkBitmap& bm = dev->accessBitmap(false);
- int w = bm.width();
- int h = bm.height();
- gl_drawSprite(fContext, x, y, w, h, max, paint);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-// must be in SkCanvas::VertexMode order
-static const GrGpu::PrimitiveType gVertexMode2PrimitiveType[] = {
- GrGpu::kTriangles_PrimitiveType,
- GrGpu::kTriangleStrip_PrimitiveType,
- GrGpu::kTriangleFan_PrimitiveType,
-};
-
-void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
- int vertexCount, const SkPoint vertices[],
- const SkPoint texs[], const SkColor colors[],
- SkXfermode* xmode,
- const uint16_t indices[], int indexCount,
- const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw);
-
- sk_gr_set_paint(fContext, paint);
-
- TexCache* cache = NULL;
-
- bool useTexture = false;
-
- AutoPaintShader autoShader;
-
- if (texs) {
- autoShader.init(this, paint, *draw.fMatrix);
-
- if (autoShader.failed()) {
- return;
- }
- useTexture = autoShader.useTex();
- }
-
- bool releaseVerts = false;
- GrVertexLayout layout = 0;
- if (useTexture) {
- layout |= GrDrawTarget::kSeparateTexCoord_VertexLayoutBit;
- }
- if (NULL != colors) {
- layout |= GrDrawTarget::kColor_VertexLayoutBit;
- }
-
- #if SK_SCALAR_IS_GR_SCALAR
- if (!layout) {
- fContext->setVertexSourceToArray(vertices, layout);
- } else
- #endif
- {
- void* verts;
- releaseVerts = true;
- if (!fContext->reserveAndLockGeometry(layout, vertexCount, 0,
- &verts, NULL)) {
- return;
- }
- int texOffset, colorOffset;
- uint32_t stride = GrDrawTarget::VertexSizeAndOffsets(layout,
- &texOffset,
- &colorOffset);
- for (int i = 0; i < vertexCount; ++i) {
- GrPoint* p = (GrPoint*)((intptr_t)verts + i * stride);
- p->set(SkScalarToGrScalar(vertices[i].fX),
- SkScalarToGrScalar(vertices[i].fY));
- if (texOffset > 0) {
- GrPoint* t = (GrPoint*)((intptr_t)p + texOffset);
- t->set(SkScalarToGrScalar(texs[i].fX),
- SkScalarToGrScalar(texs[i].fY));
- }
- if (colorOffset > 0) {
- uint32_t* color = (uint32_t*) ((intptr_t)p + colorOffset);
- *color = SkGr::SkColor2GrColor(colors[i]);
- }
- }
- }
- if (indices) {
- fContext->setIndexSourceToArray(indices);
- fContext->drawIndexed(gVertexMode2PrimitiveType[vmode], 0, 0,
- vertexCount, indexCount);
- } else {
- fContext->drawNonIndexed(gVertexMode2PrimitiveType[vmode],
- 0, vertexCount);
- }
- if (cache) {
- this->unlockCachedTexture(cache);
- }
- if (releaseVerts) {
- fContext->releaseReservedGeometry();
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-static void GlyphCacheAuxProc(void* data) {
- delete (GrFontScaler*)data;
-}
-
-static GrFontScaler* get_gr_font_scaler(SkGlyphCache* cache) {
- void* auxData;
- GrFontScaler* scaler = NULL;
- if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) {
- scaler = (GrFontScaler*)auxData;
- }
- if (NULL == scaler) {
- scaler = new SkGrFontScaler(cache);
- cache->setAuxProc(GlyphCacheAuxProc, scaler);
- }
- return scaler;
-}
-
-static void SkGPU_Draw1Glyph(const SkDraw1Glyph& state,
- SkFixed fx, SkFixed fy,
- const SkGlyph& glyph) {
- SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0);
-
- GrSkDrawProcs* procs = (GrSkDrawProcs*)state.fDraw->fProcs;
-
- if (NULL == procs->fFontScaler) {
- procs->fFontScaler = get_gr_font_scaler(state.fCache);
- }
- procs->fTextContext->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), fx, 0),
- SkIntToFixed(SkFixedFloor(fx)), fy,
- procs->fFontScaler);
-}
-
-SkDrawProcs* SkGpuDevice::initDrawForText(const SkPaint& paint,
- GrTextContext* context) {
-
- // deferred allocation
- if (NULL == fDrawProcs) {
- fDrawProcs = new GrSkDrawProcs;
- fDrawProcs->fD1GProc = SkGPU_Draw1Glyph;
- fDrawProcs->fContext = fContext;
- }
-
- // init our (and GL's) state
- fDrawProcs->fTextContext = context;
- fDrawProcs->fFontScaler = NULL;
- return fDrawProcs;
-}
-
-void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
- size_t byteLength, SkScalar x, SkScalar y,
- const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw);
-
- if (draw.fMatrix->getType() & SkMatrix::kPerspective_Mask) {
- // this guy will just call our drawPath()
- draw.drawText((const char*)text, byteLength, x, y, paint);
- } else {
- SkAutoExtMatrix aem(draw.fExtMatrix);
- SkDraw myDraw(draw);
- sk_gr_set_paint(fContext, paint);
- GrTextContext context(fContext, aem.extMatrix());
- myDraw.fProcs = this->initDrawForText(paint, &context);
- this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint);
- }
-}
-
-void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
- size_t byteLength, const SkScalar pos[],
- SkScalar constY, int scalarsPerPos,
- const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw);
-
- if (draw.fMatrix->getType() & SkMatrix::kPerspective_Mask) {
- // this guy will just call our drawPath()
- draw.drawPosText((const char*)text, byteLength, pos, constY,
- scalarsPerPos, paint);
- } else {
- SkAutoExtMatrix aem(draw.fExtMatrix);
- SkDraw myDraw(draw);
- sk_gr_set_paint(fContext, paint);
- GrTextContext context(fContext, aem.extMatrix());
- myDraw.fProcs = this->initDrawForText(paint, &context);
- this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY,
- scalarsPerPos, paint);
- }
-}
-
-void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text,
- size_t len, const SkPath& path,
- const SkMatrix* m, const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw);
-
- SkASSERT(draw.fDevice == this);
- draw.drawTextOnPath((const char*)text, len, path, m, paint);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-SkGpuDevice::TexCache* SkGpuDevice::lockCachedTexture(const SkBitmap& bitmap,
- const GrSamplerState& sampler,
- GrTexture** texture,
- bool forDeviceRenderTarget) {
- GrContext* ctx = this->context();
- uint32_t p0, p1;
- if (forDeviceRenderTarget) {
- p0 = p1 = -1;
- } else {
- p0 = bitmap.getGenerationID();
- p1 = bitmap.pixelRefOffset();
- }
-
- GrTexture* newTexture = NULL;
- GrTextureKey key(p0, p1, bitmap.width(), bitmap.height());
- GrTextureEntry* entry = ctx->findAndLockTexture(&key, sampler);
-
- if (NULL == entry) {
-
- if (forDeviceRenderTarget) {
- const GrGpu::TextureDesc desc = {
- GrGpu::kRenderTarget_TextureFlag,
- GrGpu::kNone_AALevel,
- bitmap.width(),
- bitmap.height(),
- SkGr::Bitmap2PixelConfig(bitmap)
- };
- entry = ctx->createAndLockTexture(&key, sampler, desc, NULL, 0);
-
- } else {
- entry = sk_gr_create_bitmap_texture(ctx, &key, sampler, bitmap);
- }
- if (NULL == entry) {
- GrPrintf("---- failed to create texture for cache [%d %d]\n",
- bitmap.width(), bitmap.height());
- }
- }
-
- if (NULL != entry) {
- newTexture = entry->texture();
- ctx->setTexture(newTexture);
- if (texture) {
- *texture = newTexture;
- }
- // IMPORTANT: We can't allow another SkGpuDevice to get this
- // cache entry until this one is destroyed!
- if (forDeviceRenderTarget) {
- ctx->detachCachedTexture(entry);
- }
- }
- return (TexCache*)entry;
-}
-
-void SkGpuDevice::unlockCachedTexture(TexCache* cache) {
- this->context()->unlockTexture((GrTextureEntry*)cache);
-}
-
-
diff --git a/gpu/src/skia/SkGpuDevice.h b/gpu/src/skia/SkGpuDevice.h
deleted file mode 100644
index e42e99709d..0000000000
--- a/gpu/src/skia/SkGpuDevice.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-
-#ifndef SkGpuDevice_DEFINED
-#define SkGpuDevice_DEFINED
-
-#include "SkGr.h"
-#include "SkDevice.h"
-#include "SkRegion.h"
-
-struct SkDrawProcs;
-class SkGpuCanvas;
-struct GrSkDrawProcs;
-class GrTextContext;
-
-/**
- * Subclass of SkDevice, which directs all drawing to the GrGpu owned by the
- * canvas.
- */
-class SkGpuDevice : public SkDevice {
-public:
- SkGpuDevice(SkGpuCanvas*, const SkBitmap& bitmap, bool isLayer);
- virtual ~SkGpuDevice();
-
- GrContext* context() const { return fContext; }
-
- /**
- * If this device was built for rendering as a layer (i.e. offscreen),
- * then this will return the platform-specific handle to that GPU resource.
- * For example, in OpenGL, this will return the FBO's texture ID.
- * If this device was not built for rendering as a layer, then 0
- * is returned.
- */
- intptr_t getLayerTextureHandle() const;
-
- /**
- * Attaches the device to a rendering surface. This device will then render
- * to the surface.
- * For example, in OpenGL, the device will interpret handle as an FBO ID
- * and drawing to the device would direct GL to the FBO.
- */
- void bindDeviceToTargetHandle(intptr_t handle);
-
- // call to set the clip to the specified rect
- void scissor(const SkIRect&);
-
- /**
- * Override from SkGpuDevice, so we can set our FBO to be the render target
- * The canvas parameter must be a SkGpuCanvas
- */
- virtual void gainFocus(SkCanvas*, const SkMatrix&, const SkRegion&);
-
- virtual SkGpuTexture* accessTexture() { return (SkGpuTexture*)fTexture; }
-
- // overrides from SkDevice
-
- virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
- virtual void writePixels(const SkBitmap& bitmap, int x, int y);
-
- virtual void setMatrixClip(const SkMatrix& matrix, const SkRegion& clip);
-
- virtual void drawPaint(const SkDraw&, const SkPaint& paint);
- virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
- const SkPoint[], const SkPaint& paint);
- virtual void drawRect(const SkDraw&, const SkRect& r,
- const SkPaint& paint);
- virtual void drawPath(const SkDraw&, const SkPath& path,
- const SkPaint& paint, const SkMatrix* prePathMatrix,
- bool pathIsMutable);
- virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
- const SkIRect* srcRectOrNull,
- const SkMatrix& matrix, const SkPaint& paint);
- virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
- int x, int y, const SkPaint& paint);
- virtual void drawText(const SkDraw&, const void* text, size_t len,
- SkScalar x, SkScalar y, const SkPaint& paint);
- virtual void drawPosText(const SkDraw&, const void* text, size_t len,
- const SkScalar pos[], SkScalar constY,
- int scalarsPerPos, const SkPaint& paint);
- virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
- const SkPath& path, const SkMatrix* matrix,
- const SkPaint& paint);
- virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
- const SkPoint verts[], const SkPoint texs[],
- const SkColor colors[], SkXfermode* xmode,
- const uint16_t indices[], int indexCount,
- const SkPaint& paint);
- virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y,
- const SkPaint&);
-
- virtual void flush() { fContext->flush(false); }
-
- /**
- * Make's this device's rendertarget current in the underlying 3D API.
- * Also implicitly flushes.
- */
- virtual void makeRenderTargetCurrent();
-
-protected:
- class TexCache;
- TexCache* lockCachedTexture(const SkBitmap& bitmap,
- const GrSamplerState& sampler,
- GrTexture** texture,
- bool forDeviceRenderTarget = false);
- void unlockCachedTexture(TexCache*);
-
- class SkAutoCachedTexture {
- public:
- SkAutoCachedTexture();
- SkAutoCachedTexture(SkGpuDevice* device,
- const SkBitmap& bitmap,
- const GrSamplerState& sampler,
- GrTexture** texture);
- ~SkAutoCachedTexture();
-
- GrTexture* set(SkGpuDevice*, const SkBitmap&, const GrSamplerState&);
-
- private:
- SkGpuDevice* fDevice;
- TexCache* fTex;
- };
- friend class SkAutoTexCache;
-
-private:
- GrContext* fContext;
- GrSkDrawProcs* fDrawProcs;
-
- // state for our offscreen render-target
- TexCache* fCache;
- GrTexture* fTexture;
- GrRenderTarget* fRenderTarget;
- bool fNeedClear;
- bool fNeedPrepareRenderTarget;
-
- SkDrawProcs* initDrawForText(const SkPaint&, GrTextContext*);
- bool bindDeviceAsTexture(SkPoint* max);
-
- void prepareRenderTarget(const SkDraw&);
- void internalDrawBitmap(const SkDraw&, const SkBitmap&,
- const SkIRect&, const SkMatrix&, const SkPaint&);
-
- class AutoPaintShader {
- public:
- AutoPaintShader();
- AutoPaintShader(SkGpuDevice*, const SkPaint& paint, const SkMatrix&);
-
- void init(SkGpuDevice*, const SkPaint& paint, const SkMatrix&);
-
- bool failed() const { return !fSuccess; }
- bool useTex() const { return fTexture != 0; }
- private:
- GrTexture* fTexture;
- SkAutoCachedTexture fCachedTexture;
- bool fSuccess;
- };
- friend class AutoPaintShader;
-
- typedef SkDevice INHERITED;
-};
-
-#endif
-
diff --git a/gpu/src/skia/SkGr.cpp b/gpu/src/skia/SkGr.cpp
deleted file mode 100644
index 8849db767a..0000000000
--- a/gpu/src/skia/SkGr.cpp
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-
-#include "SkGr.h"
-
-/* Fill out buffer with the compressed format Ganesh expects from a colortable
- based bitmap. [palette (colortable) + indices].
-
- At the moment Ganesh only supports 8bit version. If Ganesh allowed we others
- we could detect that the colortable.count is <= 16, and then repack the
- indices as nibbles to save RAM, but it would take more time (i.e. a lot
- slower than memcpy), so skipping that for now.
-
- Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big
- as the colortable.count says it is.
- */
-static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
- SkASSERT(SkBitmap::kIndex8_Config == bitmap.config());
-
- SkAutoLockPixels apl(bitmap);
- if (!bitmap.readyToDraw()) {
- SkASSERT(!"bitmap not ready to draw!");
- return;
- }
-
- SkColorTable* ctable = bitmap.getColorTable();
- char* dst = (char*)buffer;
-
- memcpy(dst, ctable->lockColors(), ctable->count() * sizeof(SkPMColor));
- ctable->unlockColors(false);
-
- // always skip a full 256 number of entries, even if we memcpy'd fewer
- dst += GrGpu::kColorTableSize;
-
- if (bitmap.width() == bitmap.rowBytes()) {
- memcpy(dst, bitmap.getPixels(), bitmap.getSize());
- } else {
- // need to trim off the extra bytes per row
- size_t width = bitmap.width();
- size_t rowBytes = bitmap.rowBytes();
- const char* src = (const char*)bitmap.getPixels();
- for (int y = 0; y < bitmap.height(); y++) {
- memcpy(dst, src, width);
- src += rowBytes;
- dst += width;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx,
- GrTextureKey* key,
- const GrSamplerState& sampler,
- const SkBitmap& origBitmap) {
- SkAutoLockPixels alp(origBitmap);
- if (!origBitmap.readyToDraw()) {
- return NULL;
- }
-
- SkBitmap tmpBitmap;
-
- const SkBitmap* bitmap = &origBitmap;
-
- GrGpu::TextureDesc desc = {
- 0,
- GrGpu::kNone_AALevel,
- bitmap->width(),
- bitmap->height(),
- SkGr::Bitmap2PixelConfig(*bitmap)
- };
-
- if (SkBitmap::kIndex8_Config == bitmap->config()) {
- // build_compressed_data doesn't do npot->pot expansion
- // and paletted textures can't be sub-updated
- if (ctx->supportsIndex8PixelConfig(sampler,
- bitmap->width(), bitmap->height())) {
- size_t imagesize = bitmap->width() * bitmap->height() +
- GrGpu::kColorTableSize;
- SkAutoMalloc storage(imagesize);
-
- build_compressed_data(storage.get(), origBitmap);
-
- // our compressed data will be trimmed, so pass width() for its
- // "rowBytes", since they are the same now.
- return ctx->createAndLockTexture(key, sampler, desc, storage.get(),
- bitmap->width());
-
- } else {
- origBitmap.copyTo(&tmpBitmap, SkBitmap::kARGB_8888_Config);
- // now bitmap points to our temp, which has been promoted to 32bits
- bitmap = &tmpBitmap;
- }
- }
-
- desc.fFormat = SkGr::Bitmap2PixelConfig(*bitmap);
- return ctx->createAndLockTexture(key, sampler, desc, bitmap->getPixels(),
- bitmap->rowBytes());
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-void sk_gr_set_paint(GrContext* ctx, const SkPaint& paint, bool justAlpha) {
- ctx->setDither(paint.isDither());
- ctx->setAntiAlias(paint.isAntiAlias());
-
- if (justAlpha) {
- ctx->setAlpha(paint.getAlpha());
- } else {
- ctx->setColor(SkGr::SkColor2GrColor(paint.getColor()));
- }
-
- SkXfermode::Coeff sm = SkXfermode::kOne_Coeff;
- SkXfermode::Coeff dm = SkXfermode::kISA_Coeff;
-
- SkXfermode* mode = paint.getXfermode();
- if (mode) {
- mode->asCoeff(&sm, &dm);
- }
- ctx->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm));
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-SkGrPathIter::Command SkGrPathIter::next(GrPoint pts[]) {
- GrAssert(NULL != pts);
-#if SK_SCALAR_IS_GR_SCALAR
- return sk_path_verb_to_gr_path_command(fIter.next((SkPoint*)pts));
-#else
- Command cmd = sk_path_verb_to_gr_path_command(fIter.next(fPoints));
- int n = NumCommandPoints(cmd);
- for (int i = 0; i < n; ++i) {
- pts[i].fX = SkScalarToGrScalar(fPoints[i].fX);
- pts[i].fY = SkScalarToGrScalar(fPoints[i].fY);
- }
- return cmd;
-#endif
-}
-
-SkGrPathIter::Command SkGrPathIter::next() {
- return sk_path_verb_to_gr_path_command(fIter.next(NULL));
-}
-
-void SkGrPathIter::rewind() {
- fIter.setPath(fPath, false);
-}
-
-GrPathIter::ConvexHint SkGrPathIter::hint() const {
- return fPath.isConvex() ? GrPathIter::kConvex_ConvexHint :
- GrPathIter::kNone_ConvexHint;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-void SkGrClipIterator::computeBounds(GrIRect* bounds) {
- const SkRegion* rgn = fIter.rgn();
- if (rgn) {
- SkGr::SetIRect(bounds, rgn->getBounds());
- } else {
- bounds->setEmpty();
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-GrTexture::PixelConfig SkGr::BitmapConfig2PixelConfig(SkBitmap::Config config,
- bool isOpaque) {
- switch (config) {
- case SkBitmap::kA8_Config:
- return GrTexture::kAlpha_8_PixelConfig;
- case SkBitmap::kIndex8_Config:
- return GrTexture::kIndex_8_PixelConfig;
- case SkBitmap::kRGB_565_Config:
- return GrTexture::kRGB_565_PixelConfig;
- case SkBitmap::kARGB_4444_Config:
- return GrTexture::kRGBA_4444_PixelConfig;
- case SkBitmap::kARGB_8888_Config:
- if (isOpaque) {
- return GrTexture::kRGBX_8888_PixelConfig;
- } else {
- return GrTexture::kRGBA_8888_PixelConfig;
- }
- default:
- return GrTexture::kUnknown_PixelConfig;
- }
-}
-
-void SkGr::AbandonAllTextures(GrContext* ctx) {
- ctx->abandonAllTextures();
-}
-
-
diff --git a/gpu/src/skia/SkGrFontScaler.cpp b/gpu/src/skia/SkGrFontScaler.cpp
deleted file mode 100644
index 5c88717b88..0000000000
--- a/gpu/src/skia/SkGrFontScaler.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-
-#include "SkGr.h"
-#include "SkDescriptor.h"
-#include "SkGlyphCache.h"
-
-class SkGrDescKey : public GrKey {
-public:
- explicit SkGrDescKey(const SkDescriptor& desc);
- virtual ~SkGrDescKey();
-
-protected:
- // overrides
- virtual bool lt(const GrKey& rh) const;
- virtual bool eq(const GrKey& rh) const;
-
-private:
- SkDescriptor* fDesc;
- enum {
- kMaxStorageInts = 16
- };
- uint32_t fStorage[kMaxStorageInts];
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-SkGrDescKey::SkGrDescKey(const SkDescriptor& desc) : GrKey(desc.getChecksum()) {
- size_t size = desc.getLength();
- if (size <= sizeof(fStorage)) {
- fDesc = (SkDescriptor*)fStorage;
- } else {
- fDesc = SkDescriptor::Alloc(size);
- }
- memcpy(fDesc, &desc, size);
-}
-
-SkGrDescKey::~SkGrDescKey() {
- if (fDesc != (SkDescriptor*)fStorage) {
- SkDescriptor::Free(fDesc);
- }
-}
-
-bool SkGrDescKey::lt(const GrKey& rh) const {
- const SkDescriptor* srcDesc = ((const SkGrDescKey*)&rh)->fDesc;
- size_t lenLH = fDesc->getLength();
- size_t lenRH = srcDesc->getLength();
- int cmp = memcmp(fDesc, srcDesc, SkMin32(lenLH, lenRH));
- if (0 == cmp) {
- return lenLH < lenRH;
- } else {
- return cmp < 0;
- }
-}
-
-bool SkGrDescKey::eq(const GrKey& rh) const {
- const SkDescriptor* srcDesc = ((const SkGrDescKey*)&rh)->fDesc;
- return fDesc->equals(*srcDesc);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-SkGrFontScaler::SkGrFontScaler(SkGlyphCache* strike) {
- fStrike = strike;
- fKey = NULL;
-}
-
-SkGrFontScaler::~SkGrFontScaler() {
- GrSafeUnref(fKey);
-}
-
-const GrKey* SkGrFontScaler::getKey() {
- if (NULL == fKey) {
- fKey = new SkGrDescKey(fStrike->getDescriptor());
- }
- return fKey;
-}
-
-bool SkGrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed,
- GrIRect* bounds) {
- const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
- GrGlyph::UnpackFixedX(packed),
- GrGlyph::UnpackFixedY(packed));
- bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight);
- return true;
-
-}
-
-bool SkGrFontScaler::getPackedGlyphImage(GrGlyph::PackedID packed,
- int width, int height,
- int dstRB, void* dst) {
- const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
- GrGlyph::UnpackFixedX(packed),
- GrGlyph::UnpackFixedY(packed));
- GrAssert(glyph.fWidth == width);
- GrAssert(glyph.fHeight == height);
- const void* src = fStrike->findImage(glyph);
- if (NULL == src) {
- return false;
- }
-
- int srcRB = glyph.rowBytes();
- if (srcRB == dstRB) {
- memcpy(dst, src, dstRB * height);
- } else {
- for (int y = 0; y < height; y++) {
- memcpy(dst, src, width);
- src = (const char*)src + srcRB;
- dst = (char*)dst + dstRB;
- }
- }
- return true;
-}
-
-bool SkGrFontScaler::getGlyphPath(uint16_t glyphID, GrPath* path) {
-
- const SkGlyph& glyph = fStrike->getGlyphIDMetrics(glyphID);
- const SkPath* skPath = fStrike->findPath(glyph);
- if (skPath) {
- SkGrPathIter iter(*skPath);
- path->resetFromIter(&iter);
- return true;
- }
- return false;
-}
-
-
-
diff --git a/gpu/src/skia/SkGrTexturePixelRef.cpp b/gpu/src/skia/SkGrTexturePixelRef.cpp
deleted file mode 100644
index da9ac1a692..0000000000
--- a/gpu/src/skia/SkGrTexturePixelRef.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-
-#include "SkGrTexturePixelRef.h"
-#include "GrTexture.h"
-
-SkGrTexturePixelRef::SkGrTexturePixelRef(GrTexture* tex) {
- fTexture = tex;
- GrSafeRef(tex);
-}
-
-SkGrTexturePixelRef::~SkGrTexturePixelRef() {
- GrSafeUnref(fTexture);
-}
-
-
diff --git a/gpu/src/skia/skgr_files.mk b/gpu/src/skia/skgr_files.mk
deleted file mode 100644
index 41896c005e..0000000000
--- a/gpu/src/skia/skgr_files.mk
+++ /dev/null
@@ -1,7 +0,0 @@
-SOURCE := \
- SkGpuCanvas.cpp \
- SkGpuDevice.cpp \
- SkGr.cpp \
- SkGrTexturePixelRef.cpp \
- SkGrFontScaler.cpp
-