A bunch more cleanups
Switch a few places to using android::canvas
instead of SkCanvas as well which eliminated
some JNI
Change-Id: I8f98b56442a06362b82b984cd1bd3a92398d8dbc
diff --git a/libs/hwui/Canvas.h b/libs/hwui/Canvas.h
index 7ad0683..aa24673 100644
--- a/libs/hwui/Canvas.h
+++ b/libs/hwui/Canvas.h
@@ -29,7 +29,7 @@
public:
virtual ~Canvas() {};
- static Canvas* create_canvas(SkBitmap* bitmap);
+ static Canvas* create_canvas(const SkBitmap& bitmap);
/**
* Create a new Canvas object which delegates to an SkCanvas.
@@ -52,7 +52,7 @@
*/
virtual SkCanvas* asSkCanvas() = 0;
- virtual void setBitmap(SkBitmap* bitmap, bool copyState) = 0;
+ virtual void setBitmap(const SkBitmap& bitmap) = 0;
virtual bool isOpaque() = 0;
virtual int width() = 0;
@@ -87,7 +87,8 @@
virtual bool quickRejectRect(float left, float top, float right, float bottom) const = 0;
virtual bool quickRejectPath(const SkPath& path) const = 0;
- virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op) = 0;
+ virtual bool clipRect(float left, float top, float right, float bottom,
+ SkRegion::Op op = SkRegion::kIntersect_Op) = 0;
virtual bool clipPath(const SkPath* path, SkRegion::Op op) = 0;
virtual bool clipRegion(const SkRegion* region, SkRegion::Op op) = 0;
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index 53fd1ad..ff698f5 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -138,7 +138,7 @@
// ----------------------------------------------------------------------------
virtual SkCanvas* asSkCanvas() override;
- virtual void setBitmap(SkBitmap* bitmap, bool copyState) override {
+ virtual void setBitmap(const SkBitmap& bitmap) override {
LOG_ALWAYS_FATAL("DisplayListRenderer is not backed by a bitmap.");
}
diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp
index 71088b7..dfa847c 100644
--- a/libs/hwui/SkiaCanvas.cpp
+++ b/libs/hwui/SkiaCanvas.cpp
@@ -31,7 +31,7 @@
// Holds an SkCanvas reference plus additional native data.
class SkiaCanvas : public Canvas {
public:
- explicit SkiaCanvas(SkBitmap* bitmap);
+ explicit SkiaCanvas(const SkBitmap& bitmap);
/**
* Create a new SkiaCanvas.
@@ -49,7 +49,7 @@
return mCanvas.get();
}
- virtual void setBitmap(SkBitmap* bitmap, bool copyState) override;
+ virtual void setBitmap(const SkBitmap& bitmap) override;
virtual bool isOpaque() override;
virtual int width() override;
@@ -145,19 +145,7 @@
SkAutoTDelete<SkDeque> mSaveStack; // lazily allocated, tracks partial saves.
};
-// Construct an SkCanvas from the bitmap.
-static SkCanvas* createCanvas(SkBitmap* bitmap) {
- if (bitmap) {
- return SkNEW_ARGS(SkCanvas, (*bitmap));
- }
-
- // Create an empty bitmap device to prevent callers from crashing
- // if they attempt to draw into this canvas.
- SkBitmap emptyBitmap;
- return new SkCanvas(emptyBitmap);
-}
-
-Canvas* Canvas::create_canvas(SkBitmap* bitmap) {
+Canvas* Canvas::create_canvas(const SkBitmap& bitmap) {
return new SkiaCanvas(bitmap);
}
@@ -165,8 +153,8 @@
return new SkiaCanvas(skiaCanvas);
}
-SkiaCanvas::SkiaCanvas(SkBitmap* bitmap) {
- mCanvas.reset(createCanvas(bitmap));
+SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) {
+ mCanvas.reset(new SkCanvas(bitmap));
}
// ----------------------------------------------------------------------------
@@ -191,11 +179,11 @@
SkCanvas* m_dstCanvas;
};
-void SkiaCanvas::setBitmap(SkBitmap* bitmap, bool copyState) {
- SkCanvas* newCanvas = createCanvas(bitmap);
+void SkiaCanvas::setBitmap(const SkBitmap& bitmap) {
+ SkCanvas* newCanvas = new SkCanvas(bitmap);
SkASSERT(newCanvas);
- if (copyState) {
+ if (!bitmap.isNull()) {
// Copy the canvas matrix & clip state.
newCanvas->setMatrix(mCanvas->getTotalMatrix());
if (NULL != mCanvas->getDevice() && NULL != newCanvas->getDevice()) {
diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp
index cc87241..d15fa39 100644
--- a/libs/hwui/renderthread/RenderProxy.cpp
+++ b/libs/hwui/renderthread/RenderProxy.cpp
@@ -293,11 +293,11 @@
return (void*) success;
}
-bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap) {
+bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) {
SETUP_TASK(copyLayerInto);
args->context = mContext;
args->layer = layer;
- args->bitmap = bitmap;
+ args->bitmap = &bitmap;
return (bool) postAndWait(task);
}
diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h
index 29c6f08..cc475fa 100644
--- a/libs/hwui/renderthread/RenderProxy.h
+++ b/libs/hwui/renderthread/RenderProxy.h
@@ -83,7 +83,7 @@
ANDROID_API DeferredLayerUpdater* createTextureLayer();
ANDROID_API void buildLayer(RenderNode* node);
- ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);
+ ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer);
ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer);
ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer);