aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/bitmapscroll.cpp155
-rw-r--r--gyp/core.gypi1
-rw-r--r--include/core/SkBitmap.h22
-rw-r--r--src/core/SkBitmap_scroll.cpp105
4 files changed, 0 insertions, 283 deletions
diff --git a/gm/bitmapscroll.cpp b/gm/bitmapscroll.cpp
deleted file mode 100644
index 0603c3c472..0000000000
--- a/gm/bitmapscroll.cpp
+++ /dev/null
@@ -1,155 +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 "gm.h"
-
-namespace skiagm {
-
-/** Create a bitmap image suitable for testing SkBitmap::scrollRect().
- *
- * @param quarterWidth bitmap will be 4x this many pixels wide
- * @param quarterHeight bitmap will be 4x this many pixels tall
- * @param bitmap the bitmap data is written into this object
- */
-static void make_bitmap(int quarterWidth, int quarterHeight, SkBitmap *bitmap) {
- SkPaint pRed, pWhite, pGreen, pBlue, pLine, pAlphaGray;
- pRed.setColor(0xFFFF9999);
- pWhite.setColor(0xFFFFFFFF);
- pGreen.setColor(0xFF99FF99);
- pBlue.setColor(0xFF9999FF);
- pLine.setColor(0xFF000000);
- pLine.setStyle(SkPaint::kStroke_Style);
- pAlphaGray.setColor(0x66888888);
-
- // Prepare bitmap, and a canvas that draws into it.
- bitmap->allocN32Pixels(quarterWidth*4, quarterHeight*4);
- SkCanvas canvas(*bitmap);
-
- SkScalar w = SkIntToScalar(quarterWidth);
- SkScalar h = SkIntToScalar(quarterHeight);
- canvas.drawRectCoords( 0, 0, w*2, h*2, pRed);
- canvas.drawRectCoords(w*2, 0, w*4, h*2, pGreen);
- canvas.drawRectCoords( 0, h*2, w*2, h*4, pBlue);
- canvas.drawRectCoords(w*2, h*2, w*4, h*4, pWhite);
- canvas.drawRectCoords(w, h, w*3, h*3, pAlphaGray);
- canvas.drawLine(w*2, 0, w*2, h*4, pLine);
- canvas.drawLine( 0, h*2, w*4, h*2, pLine);
- canvas.drawRectCoords(w, h, w*3, h*3, pLine);
-}
-
-class BitmapScrollGM : public GM {
- bool fInited;
- void init() {
- if (fInited) {
- return;
- }
- fInited = true;
- // Create the original bitmap.
- make_bitmap(quarterWidth, quarterHeight, &origBitmap);
- }
-
-public:
- BitmapScrollGM() {
- fInited = false;
- this->setBGColor(0xFFDDDDDD);
- }
-
-protected:
- SkString onShortName() override {
- return SkString("bitmapscroll");
- }
-
- SkISize onISize() override {
- return SkISize::Make(800, 600);
- }
-
- void onDraw(SkCanvas* canvas) override {
- this->init();
- SkIRect scrollCenterRegion = SkIRect::MakeXYWH(
- quarterWidth, quarterHeight, quarterWidth*2+1, quarterHeight*2+1);
- int x = quarterWidth;
- int y = quarterHeight;
- int xSpacing = quarterWidth * 20;
- int ySpacing = quarterHeight * 16;
-
- // Draw left-hand text labels.
- drawLabel(canvas, "scroll entire bitmap",
- x, y, x, y + ySpacing);
- drawLabel(canvas, "scroll part of bitmap",
- x, y + ySpacing, x, y + ySpacing*2);
- x += 30;
-
- // Draw various permutations of scrolled bitmaps, scrolling a bit
- // further each time.
- draw9(canvas, x, y, NULL, quarterWidth*1/2, quarterHeight*1/2);
- draw9(canvas, x, y+ySpacing, &scrollCenterRegion,
- quarterWidth*1/2, quarterHeight*1/2);
- x += xSpacing;
- draw9(canvas, x, y, NULL, quarterWidth*3/2, quarterHeight*3/2);
- draw9(canvas, x, y+ySpacing, &scrollCenterRegion,
- quarterWidth*3/2, quarterHeight*3/2);
- x += xSpacing;
- draw9(canvas, x, y, NULL, quarterWidth*5/2, quarterHeight*5/2);
- draw9(canvas, x, y+ySpacing, &scrollCenterRegion,
- quarterWidth*5/2, quarterHeight*5/2);
- x += xSpacing;
- draw9(canvas, x, y, NULL, quarterWidth*9/2, quarterHeight*9/2);
- draw9(canvas, x, y+ySpacing, &scrollCenterRegion,
- quarterWidth*9/2, quarterHeight*9/2);
- }
-
- void drawLabel(SkCanvas* canvas, const char *text, int startX, int startY,
- int endX, int endY) {
- SkPaint paint;
- sk_tool_utils::set_portable_typeface(&paint);
- paint.setColor(0xFF000000);
- SkPath path;
- path.moveTo(SkIntToScalar(startX), SkIntToScalar(startY));
- path.lineTo(SkIntToScalar(endX), SkIntToScalar(endY));
- canvas->drawTextOnPath(text, strlen(text), path, NULL, paint);
- }
-
- /** Stamp out 9 copies of origBitmap, scrolled in each direction (and
- * not scrolled at all).
- */
- void draw9(SkCanvas* canvas, int x, int y, SkIRect* subset,
- int scrollX, int scrollY) {
- for (int yMult=-1; yMult<=1; yMult++) {
- for (int xMult=-1; xMult<=1; xMult++) {
- // Figure out the (x,y) to draw this copy at
- SkScalar bitmapX = SkIntToScalar(
- x + quarterWidth * 5 * (xMult+1));
- SkScalar bitmapY = SkIntToScalar(
- y + quarterHeight * 5 * (yMult+1));
-
- // Scroll a new copy of the bitmap, and then draw it.
- // scrollRect() should always return true, even if it's a no-op
- SkBitmap scrolledBitmap;
- SkDEBUGCODE(bool copyToReturnValue = )origBitmap.copyTo(
- &scrolledBitmap, origBitmap.colorType());
- SkASSERT(copyToReturnValue);
- SkDEBUGCODE(bool scrollRectReturnValue = )scrolledBitmap.scrollRect(
- subset, scrollX * xMult, scrollY * yMult);
- SkASSERT(scrollRectReturnValue);
- canvas->drawBitmap(scrolledBitmap, bitmapX, bitmapY);
- }
- }
- }
-
-private:
- typedef GM INHERITED;
- static const int quarterWidth = 10;
- static const int quarterHeight = 14;
- SkBitmap origBitmap;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static GM* MyFactory(void*) { return new BitmapScrollGM; }
-static GMRegistry reg(MyFactory);
-
-}
diff --git a/gyp/core.gypi b/gyp/core.gypi
index b99f51c2ad..3a61933356 100644
--- a/gyp/core.gypi
+++ b/gyp/core.gypi
@@ -40,7 +40,6 @@
'<(skia_src_path)/core/SkBitmapProcState_sample.h',
'<(skia_src_path)/core/SkBitmapScaler.h',
'<(skia_src_path)/core/SkBitmapScaler.cpp',
- '<(skia_src_path)/core/SkBitmap_scroll.cpp',
'<(skia_src_path)/core/SkBlitBWMaskTemplate.h',
'<(skia_src_path)/core/SkBlitMask_D32.cpp',
'<(skia_src_path)/core/SkBlitRow_D16.cpp',
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index dbaca621af..a39c8688ae 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -493,28 +493,6 @@ public:
*/
void eraseArea(const SkIRect& area, SkColor c) const;
- /** Scroll (a subset of) the contents of this bitmap by dx/dy. If there are
- no pixels allocated (i.e. getPixels() returns null) the method will
- still update the inval region (if present). If the bitmap is immutable,
- do nothing and return false.
-
- @param subset The subset of the bitmap to scroll/move. To scroll the
- entire contents, specify [0, 0, width, height] or just
- pass null.
- @param dx The amount to scroll in X
- @param dy The amount to scroll in Y
- @param inval Optional (may be null). Returns the area of the bitmap that
- was scrolled away. E.g. if dx = dy = 0, then inval would
- be set to empty. If dx >= width or dy >= height, then
- inval would be set to the entire bounds of the bitmap.
- @return true if the scroll was doable. Will return false if the colortype is kUnkown or
- if the bitmap is immutable.
- If no pixels are present (i.e. getPixels() returns false)
- inval will still be updated, and true will be returned.
- */
- bool scrollRect(const SkIRect* subset, int dx, int dy,
- SkRegion* inval = NULL) const;
-
/**
* Return the SkColor of the specified pixel. In most cases this will
* require un-premultiplying the color. Alpha only colortypes (e.g. kAlpha_8_SkColorType)
diff --git a/src/core/SkBitmap_scroll.cpp b/src/core/SkBitmap_scroll.cpp
deleted file mode 100644
index 54158c2bec..0000000000
--- a/src/core/SkBitmap_scroll.cpp
+++ /dev/null
@@ -1,105 +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 "SkBitmap.h"
-#include "SkRegion.h"
-
-bool SkBitmap::scrollRect(const SkIRect* subset, int dx, int dy,
- SkRegion* inval) const
-{
- if (this->isImmutable() || kUnknown_SkColorType == this->colorType()) {
- return false;
- }
-
- if (subset) {
- SkBitmap tmp;
-
- return this->extractSubset(&tmp, *subset) &&
- // now call again with no rectangle
- tmp.scrollRect(NULL, dx, dy, inval);
- }
-
- int shift = this->bytesPerPixel() >> 1;
- int width = this->width();
- int height = this->height();
-
- // check if there's nothing to do
- if ((dx | dy) == 0 || width <= 0 || height <= 0) {
- if (inval) {
- inval->setEmpty();
- }
- return true;
- }
-
- // compute the inval region now, before we see if there are any pixels
- if (inval) {
- SkIRect r;
-
- r.set(0, 0, width, height);
- // initial the region with the entire bounds
- inval->setRect(r);
- // do the "scroll"
- r.offset(dx, dy);
-
- // check if we scrolled completely away
- if (!SkIRect::Intersects(r, inval->getBounds())) {
- // inval has already been updated...
- return true;
- }
-
- // compute the dirty area
- inval->op(r, SkRegion::kDifference_Op);
- }
-
- SkAutoLockPixels alp(*this);
- // if we have no pixels, just return (inval is already updated)
- // don't call readyToDraw(), since we don't require a colortable per se
- if (this->getPixels() == NULL) {
- return true;
- }
-
- char* dst = (char*)this->getPixels();
- const char* src = dst;
- int rowBytes = (int)this->rowBytes(); // need rowBytes to be signed
-
- if (dy <= 0) {
- src -= dy * rowBytes;
- height += dy;
- } else {
- dst += dy * rowBytes;
- height -= dy;
- // now jump src/dst to the last scanline
- src += (height - 1) * rowBytes;
- dst += (height - 1) * rowBytes;
- // now invert rowbytes so we copy backwards in the loop
- rowBytes = -rowBytes;
- }
-
- if (dx <= 0) {
- src -= dx << shift;
- width += dx;
- } else {
- dst += dx << shift;
- width -= dx;
- }
-
- // If the X-translation would push it completely beyond the region,
- // then there's nothing to draw.
- if (width <= 0) {
- return true;
- }
-
- width <<= shift; // now width is the number of bytes to move per line
- while (--height >= 0) {
- memmove(dst, src, width);
- dst += rowBytes;
- src += rowBytes;
- }
-
- this->notifyPixelsChanged();
- return true;
-}