aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-06 21:07:10 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-06 21:07:10 +0000
commit72c9672ce274a3b6cb40800d66374edf25b157a3 (patch)
treec7b5298b2f1ece7d390b393763dc99274fad55fe /src
parent47059542e7aa153926377456a6c611e55c8e428c (diff)
Add tiled rendering as an option to GM.
Use an SkGPipe to play back drawing into tiles. This will help us to debug differences in drawing while tiled. Pass --tiledPipe to gm to use the tiled pipe. Review URL: https://codereview.appspot.com/6295050 git-svn-id: http://skia.googlecode.com/svn/trunk@4199 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/pipe/SkGPipeRead.cpp13
-rw-r--r--src/pipe/utils/SamplePipeControllers.cpp72
-rw-r--r--src/pipe/utils/SamplePipeControllers.h43
3 files changed, 126 insertions, 2 deletions
diff --git a/src/pipe/SkGPipeRead.cpp b/src/pipe/SkGPipeRead.cpp
index 976abbf10a..ddc0cc41d9 100644
--- a/src/pipe/SkGPipeRead.cpp
+++ b/src/pipe/SkGPipeRead.cpp
@@ -545,12 +545,21 @@ SkGPipeState::~SkGPipeState() {
#include "SkGPipe.h"
+SkGPipeReader::SkGPipeReader() {
+ fCanvas = NULL;
+ fState = NULL;
+}
+
SkGPipeReader::SkGPipeReader(SkCanvas* target) {
- SkSafeRef(target);
- fCanvas = target;
+ fCanvas = NULL;
+ this->setCanvas(target);
fState = NULL;
}
+void SkGPipeReader::setCanvas(SkCanvas *target) {
+ SkRefCnt_SafeAssign(fCanvas, target);
+}
+
SkGPipeReader::~SkGPipeReader() {
SkSafeUnref(fCanvas);
delete fState;
diff --git a/src/pipe/utils/SamplePipeControllers.cpp b/src/pipe/utils/SamplePipeControllers.cpp
new file mode 100644
index 0000000000..487a2b8356
--- /dev/null
+++ b/src/pipe/utils/SamplePipeControllers.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SamplePipeControllers.h"
+#include "SkCanvas.h"
+#include "SkDevice.h"
+#include "SkGPipe.h"
+
+PipeController::PipeController(SkCanvas* target)
+:fReader(target) {
+ fBlock = NULL;
+ fBlockSize = fBytesWritten = 0;
+}
+
+PipeController::~PipeController() {
+ sk_free(fBlock);
+}
+
+void* PipeController::requestBlock(size_t minRequest, size_t *actual) {
+ sk_free(fBlock);
+ fBlockSize = minRequest * 4;
+ fBlock = sk_malloc_throw(fBlockSize);
+ fBytesWritten = 0;
+ *actual = fBlockSize;
+ return fBlock;
+}
+
+void PipeController::notifyWritten(size_t bytes) {
+ fStatus = fReader.playback(this->getData(), bytes);
+ SkASSERT(SkGPipeReader::kError_Status != fStatus);
+ fBytesWritten += bytes;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+TiledPipeController::TiledPipeController(const SkBitmap& bitmap)
+: INHERITED(NULL) {
+ int32_t top = 0;
+ int32_t bottom;
+ int32_t height = bitmap.height() / NumberOfTiles;
+ SkIRect rect;
+ for (int i = 0; i < NumberOfTiles; i++) {
+ bottom = i + 1 == NumberOfTiles ? bitmap.height() : top + height;
+ rect.setLTRB(0, top, bitmap.width(), bottom);
+ top = bottom;
+
+ bool extracted = bitmap.extractSubset(&fBitmaps[i], rect);
+ SkASSERT(extracted);
+ SkDevice* device = new SkDevice(fBitmaps[i]);
+ SkCanvas* canvas = new SkCanvas(device);
+ device->unref();
+ canvas->translate(SkIntToScalar(-rect.left()),
+ SkIntToScalar(-rect.top()));
+ if (0 == i) {
+ fReader.setCanvas(canvas);
+ } else {
+ fReaders[i - 1].setCanvas(canvas);
+ }
+ canvas->unref();
+ }
+}
+
+void TiledPipeController::notifyWritten(size_t bytes) {
+ for (int i = 0; i < NumberOfTiles - 1; i++) {
+ fReaders[i].playback(this->getData(), bytes);
+ }
+ this->INHERITED::notifyWritten(bytes);
+}
diff --git a/src/pipe/utils/SamplePipeControllers.h b/src/pipe/utils/SamplePipeControllers.h
new file mode 100644
index 0000000000..ace6274bae
--- /dev/null
+++ b/src/pipe/utils/SamplePipeControllers.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2012 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 "SkGPipe.h"
+
+class SkCanvas;
+
+class PipeController : public SkGPipeController {
+public:
+ PipeController(SkCanvas* target);
+ virtual ~PipeController();
+ virtual void* requestBlock(size_t minRequest, size_t* actual) SK_OVERRIDE;
+ virtual void notifyWritten(size_t bytes) SK_OVERRIDE;
+protected:
+ const void* getData() { return (const char*) fBlock + fBytesWritten; }
+ SkGPipeReader fReader;
+private:
+ void* fBlock;
+ size_t fBlockSize;
+ size_t fBytesWritten;
+ SkGPipeReader::Status fStatus;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+class TiledPipeController : public PipeController {
+public:
+ TiledPipeController(const SkBitmap&);
+ virtual ~TiledPipeController() {};
+ virtual void notifyWritten(size_t bytes) SK_OVERRIDE;
+private:
+ enum {
+ NumberOfTiles = 10
+ };
+ SkGPipeReader fReaders[NumberOfTiles - 1];
+ SkBitmap fBitmaps[NumberOfTiles];
+ typedef PipeController INHERITED;
+};