diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-13 16:35:37 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-13 16:35:37 +0000 |
commit | 4c1f091b6835a771dc86f5a784dce693de4f4555 (patch) | |
tree | da9617fa51807098bb5827d52713e96d04e19889 | |
parent | 8f0ca06ef44f7b94da549fbb0c5fab27092c5116 (diff) |
kill unused SkFlipPixelRef
Review URL: https://codereview.appspot.com/6949043
git-svn-id: http://skia.googlecode.com/svn/trunk@6781 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | gyp/SampleApp.gyp | 2 | ||||
-rw-r--r-- | gyp/images.gyp | 2 | ||||
-rw-r--r-- | include/images/SkFlipPixelRef.h | 102 | ||||
-rw-r--r-- | samplecode/SamplePageFlip.cpp | 180 | ||||
-rw-r--r-- | src/images/SkFlipPixelRef.cpp | 125 | ||||
-rw-r--r-- | src/images/SkImages.cpp | 2 |
6 files changed, 0 insertions, 413 deletions
diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp index 5668428784..8e8fec2fc7 100644 --- a/gyp/SampleApp.gyp +++ b/gyp/SampleApp.gyp @@ -71,7 +71,6 @@ '../samplecode/SampleMovie.cpp', '../samplecode/SampleOvalTest.cpp', '../samplecode/SampleOverflow.cpp', - '../samplecode/SamplePageFlip.cpp', '../samplecode/SamplePatch.cpp', '../samplecode/SamplePath.cpp', '../samplecode/SamplePathClip.cpp', @@ -156,7 +155,6 @@ 'sources!': [ # require UNIX functions '../samplecode/SampleEncode.cpp', - '../samplecode/SamplePageFlip.cpp', ], }], [ 'skia_os == "mac"', { diff --git a/gyp/images.gyp b/gyp/images.gyp index 1441359e9b..1bfd2d30b9 100644 --- a/gyp/images.gyp +++ b/gyp/images.gyp @@ -19,7 +19,6 @@ ], 'sources': [ '../include/images/SkBitmapFactory.h', - '../include/images/SkFlipPixelRef.h', '../include/images/SkImageDecoder.h', '../include/images/SkImageEncoder.h', '../include/images/SkImageRef.h', @@ -32,7 +31,6 @@ '../src/images/bmpdecoderhelper.h', '../src/images/SkBitmapFactory.cpp', '../src/images/SkFDStream.cpp', - '../src/images/SkFlipPixelRef.cpp', '../src/images/SkImageDecoder.cpp', '../src/images/SkImageDecoder_Factory.cpp', '../src/images/SkImageDecoder_libjpeg.cpp', diff --git a/include/images/SkFlipPixelRef.h b/include/images/SkFlipPixelRef.h deleted file mode 100644 index ac437805d6..0000000000 --- a/include/images/SkFlipPixelRef.h +++ /dev/null @@ -1,102 +0,0 @@ - -/* - * Copyright 2008 The Android Open Source Project - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - - -#ifndef SkFlipPixelRef_DEFINED -#define SkFlipPixelRef_DEFINED - -#include "SkBitmap.h" -#include "SkPageFlipper.h" -#include "SkPixelRef.h" -#include "SkThread.h" - -class SkRegion; - -class SkFlipPixelRef : public SkPixelRef { -public: - SkFlipPixelRef(SkBitmap::Config, int width, int height); - virtual ~SkFlipPixelRef(); - - bool isDirty() const { return fFlipper.isDirty(); } - const SkRegion& dirtyRgn() const { return fFlipper.dirtyRgn(); } - - void inval() { fFlipper.inval(); } - void inval(const SkIRect& rect) { fFlipper.inval(rect); } - void inval(const SkRegion& rgn) { fFlipper.inval(rgn); } - void inval(const SkRect& r, bool doAA) { fFlipper.inval(r, doAA); } - - const SkRegion& beginUpdate(SkBitmap* device); - void endUpdate(); - - SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkFlipPixelRef) - -protected: - virtual void* onLockPixels(SkColorTable**); - virtual void onUnlockPixels(); - - SkFlipPixelRef(SkFlattenableReadBuffer&); - virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; - -private: - void getFrontBack(const void** front, void** back) const { - if (front) { - *front = fPage0; - } - if (back) { - *back = fPage1; - } - } - - void swapPages(); - - // Helper to copy pixels from srcAddr to the dst bitmap, clipped to clip. - // srcAddr points to memory with the same config as dst. - static void CopyBitsFromAddr(const SkBitmap& dst, const SkRegion& clip, - const void* srcAddr); - - SkMutex fMutex; - SkPageFlipper fFlipper; - - void* fStorage; - void* fPage0; // points into fStorage; - void* fPage1; // points into fStorage; - size_t fSize; // size of 1 page. fStorage holds 2 pages - SkBitmap::Config fConfig; - - typedef SkPixelRef INHERITED; -}; - -class SkAutoFlipUpdate : SkNoncopyable { -public: - SkAutoFlipUpdate(SkFlipPixelRef* ref) : fRef(ref) { - fDirty = &ref->beginUpdate(&fBitmap); - } - ~SkAutoFlipUpdate() { - if (fRef) { - fRef->endUpdate(); - } - } - - const SkBitmap& bitmap() const { return fBitmap; } - const SkRegion& dirty() const { return *fDirty; } - - // optional. This gets automatically called in the destructor (only once) - void endUpdate() { - if (fRef) { - fRef->endUpdate(); - fRef = NULL; - } - } - -private: - SkFlipPixelRef* fRef; - SkBitmap fBitmap; - const SkRegion* fDirty; -}; - -#endif diff --git a/samplecode/SamplePageFlip.cpp b/samplecode/SamplePageFlip.cpp deleted file mode 100644 index 1020189cab..0000000000 --- a/samplecode/SamplePageFlip.cpp +++ /dev/null @@ -1,180 +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 "SampleCode.h" -#include "SkView.h" -#include "SkCanvas.h" -#include "SkGraphics.h" -#include "SkRandom.h" -#include "SkFlipPixelRef.h" -#include "SkPageFlipper.h" - -#include <pthread.h> - -#define WIDTH 160 -#define HEIGHT 200 - -static bool gDone; - -static void bounce(SkScalar* x, SkScalar* dx, const int max) { - *x += *dx; - if (*x < 0) { - *x = 0; - if (*dx < 0) { - *dx = -*dx; - } - } else if (*x > SkIntToScalar(max)) { - *x = SkIntToScalar(max); - if (*dx > 0) { - *dx = -*dx; - } - } -} - -static void* draw_proc(void* context) { - const int OVALW = 32; - const int OVALH = 32; - - const SkBitmap* bm = static_cast<const SkBitmap*>(context); - SkFlipPixelRef* ref = static_cast<SkFlipPixelRef*>(bm->pixelRef()); - - const int DSCALE = 1; - SkScalar dx = SkIntToScalar(7) / DSCALE; - SkScalar dy = SkIntToScalar(5) / DSCALE; - SkScalar x = 0; - SkScalar y = 0; - - SkPaint paint; - - paint.setAntiAlias(true); - paint.setColor(SK_ColorRED); - - SkRect oval; - oval.setEmpty(); - - SkRect clipR = SkRect::MakeWH(SkIntToScalar(bm->width()), SkIntToScalar(bm->height())); - clipR.inset(SK_Scalar1/4, SK_Scalar1/4); - - while (!gDone) { - ref->inval(oval, true); - oval.set(x, y, x + SkIntToScalar(OVALW), y + SkIntToScalar(OVALH)); - ref->inval(oval, true); - - SkAutoFlipUpdate update(ref); - - if (!update.dirty().isEmpty()) { - // this must be local to the loop, since it needs to forget the pixels - // its writing to after each iteration, since we do the swap - SkCanvas canvas(update.bitmap()); - canvas.clipRegion(update.dirty()); - canvas.drawColor(0, SkXfermode::kClear_Mode); - canvas.clipRect(clipR, SkRegion::kIntersect_Op, true); - - canvas.drawOval(oval, paint); - } - bounce(&x, &dx, WIDTH-OVALW); - bounce(&y, &dy, HEIGHT-OVALH); - } - return NULL; -} - -static const SkBitmap::Config gConfigs[] = { - SkBitmap::kARGB_8888_Config, - SkBitmap::kRGB_565_Config, - SkBitmap::kARGB_4444_Config, - SkBitmap::kA8_Config -}; - -class PageFlipView : public SampleView { - bool fOnce; -public: - - enum { N = SK_ARRAY_COUNT(gConfigs) }; - - pthread_t fThreads[N]; - SkBitmap fBitmaps[N]; - - PageFlipView() { - gDone = false; - fOnce = false; - this->setBGColor(0xFFDDDDDD); - } - - void init() { - if (fOnce) { - return; - } - fOnce = true; - - for (int i = 0; i < N; i++) { - int status; - pthread_attr_t attr; - - status = pthread_attr_init(&attr); - SkASSERT(0 == status); - - fBitmaps[i].setConfig(gConfigs[i], WIDTH, HEIGHT); - SkFlipPixelRef* pr = new SkFlipPixelRef(gConfigs[i], WIDTH, HEIGHT); - fBitmaps[i].setPixelRef(pr)->unref(); - fBitmaps[i].eraseColor(SK_ColorTRANSPARENT); - - status = pthread_create(&fThreads[i], &attr, draw_proc, &fBitmaps[i]); - SkASSERT(0 == status); - } - } - - virtual ~PageFlipView() { - if (!fOnce) { - return; - } - gDone = true; - for (int i = 0; i < N; i++) { - void* ret; - int status = pthread_join(fThreads[i], &ret); - SkASSERT(0 == status); - } - } - -protected: - // overrides from SkEventSink - virtual bool onQuery(SkEvent* evt) { - if (SampleCode::TitleQ(*evt)) { - SampleCode::TitleR(evt, "PageFlip"); - return true; - } - return this->INHERITED::onQuery(evt); - } - - virtual void onDrawContent(SkCanvas* canvas) { - this->init(); - SkScalar x = SkIntToScalar(10); - SkScalar y = SkIntToScalar(10); - for (int i = 0; i < N; i++) { - canvas->drawBitmap(fBitmaps[i], x, y); - x += SkIntToScalar(fBitmaps[i].width() + 20); - } - this->inval(NULL); - } - - virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) { - this->inval(NULL); - return this->INHERITED::onFindClickHandler(x, y); - } - - virtual bool onClick(Click* click) { - return this->INHERITED::onClick(click); - } - -private: - typedef SampleView INHERITED; -}; - -////////////////////////////////////////////////////////////////////////////// - -static SkView* MyFactory() { return new PageFlipView; } -static SkViewRegister reg(MyFactory); - diff --git a/src/images/SkFlipPixelRef.cpp b/src/images/SkFlipPixelRef.cpp deleted file mode 100644 index 2e73ece5ac..0000000000 --- a/src/images/SkFlipPixelRef.cpp +++ /dev/null @@ -1,125 +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 "SkFlipPixelRef.h" -#include "SkFlattenableBuffers.h" -#include "SkRegion.h" - -SkFlipPixelRef::SkFlipPixelRef(SkBitmap::Config config, int width, int height) -: fFlipper(width, height) { - fConfig = config; - fSize = SkBitmap::ComputeSize(config, width, height); - fStorage = sk_malloc_throw(fSize << 1); - fPage0 = fStorage; - fPage1 = (char*)fStorage + fSize; -} - -SkFlipPixelRef::~SkFlipPixelRef() { - sk_free(fStorage); -} - -const SkRegion& SkFlipPixelRef::beginUpdate(SkBitmap* device) { - void* writeAddr; - const void* readAddr; - this->getFrontBack(&readAddr, &writeAddr); - - device->setConfig(fConfig, fFlipper.width(), fFlipper.height()); - device->setPixels(writeAddr); - - SkRegion copyBits; - const SkRegion& dirty = fFlipper.update(©Bits); - - SkFlipPixelRef::CopyBitsFromAddr(*device, copyBits, readAddr); - return dirty; -} - -void SkFlipPixelRef::endUpdate() { - this->swapPages(); -} - -/////////////////////////////////////////////////////////////////////////////// - -void* SkFlipPixelRef::onLockPixels(SkColorTable** ct) { - fMutex.acquire(); - *ct = NULL; - return fPage0; -} - -void SkFlipPixelRef::onUnlockPixels() { - fMutex.release(); -} - -void SkFlipPixelRef::swapPages() { - fMutex.acquire(); - SkTSwap<void*>(fPage0, fPage1); - this->notifyPixelsChanged(); - fMutex.release(); -} - -void SkFlipPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { - this->INHERITED::flatten(buffer); - // only need to write page0 - buffer.writeByteArray(fPage0, fSize); -} - -SkFlipPixelRef::SkFlipPixelRef(SkFlattenableReadBuffer& buffer) - : INHERITED(buffer, NULL) { - fSize = buffer.getArrayCount(); - fStorage = sk_malloc_throw(fSize << 1); - fPage0 = fStorage; - fPage1 = (char*)fStorage + fSize; - buffer.readByteArray(fPage0); -} - -/////////////////////////////////////////////////////////////////////////////// - -static void copyRect(const SkBitmap& dst, const SkIRect& rect, - const void* srcAddr, int shift) { - const size_t offset = rect.fTop * dst.rowBytes() + (rect.fLeft << shift); - char* dstP = static_cast<char*>(dst.getPixels()) + offset; - const char* srcP = static_cast<const char*>(srcAddr) + offset; - const size_t rb = dst.rowBytes(); - const size_t bytes = rect.width() << shift; - - int height = rect.height(); - while (--height >= 0) { - memcpy(dstP, srcP, bytes); - dstP += rb; - srcP += rb; - } -} - -static int getShift(SkBitmap::Config config) { - switch (config) { - case SkBitmap::kARGB_8888_Config: - return 2; - case SkBitmap::kRGB_565_Config: - case SkBitmap::kARGB_4444_Config: - return 1; - case SkBitmap::kIndex8_Config: - case SkBitmap::kA8_Config: - return 0; - default: - return -1; // signal not supported - } -} - -void SkFlipPixelRef::CopyBitsFromAddr(const SkBitmap& dst, const SkRegion& clip, - const void* srcAddr) { - const int shift = getShift(dst.config()); - if (shift < 0) { - return; - } - - const SkIRect bounds = {0, 0, dst.width(), dst.height()}; - SkRegion::Cliperator iter(clip, bounds); - - while (!iter.done()) { - copyRect(dst, iter.rect(), srcAddr, shift); - iter.next(); - } -} diff --git a/src/images/SkImages.cpp b/src/images/SkImages.cpp index 28dfd7f615..0bcc33fa51 100644 --- a/src/images/SkImages.cpp +++ b/src/images/SkImages.cpp @@ -6,11 +6,9 @@ */ #include "SkFlattenable.h" -#include "SkFlipPixelRef.h" #include "SkImageRef_GlobalPool.h" #include "SkImages.h" void SkImages::InitializeFlattenables() { - SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkFlipPixelRef) SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkImageRef_GlobalPool) } |