Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Unified Diff: tests/LayerAllocatorTest.cpp

Issue 1763143002: WIP RasterCanvasLayerAllocator (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: test and some further work Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/core/SkRasterCanvasLayerAllocator.h ('K') | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/LayerAllocatorTest.cpp
diff --git a/tests/LayerAllocatorTest.cpp b/tests/LayerAllocatorTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d171129d81f1428848e89fb6b3e2a38bb2e8d30f
--- /dev/null
+++ b/tests/LayerAllocatorTest.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
+
+#include "SkCanvas.h"
+#include "SkRasterCanvasLayerAllocator.h"
+
+class TestAllocator : public SkRasterCanvasLayerAllocator {
+public:
+ TestAllocator() : flushCount(0), allocated(false) {}
+ virtual ~TestAllocator() {}
+
+ void* getNativeContext(void* buffer) override;
+ void flush() override;
+ void free(void* buffer, void* nativeContext) override;
+
+ int nativeLayerSentry;
+ int nativeContextSentry;
+ int flushCount;
+ bool allocated;
+
+protected:
+ void* allocateLayer(const SkImageInfo& info, size_t* rowBytes) override;
+};
+
+void* TestAllocator::getNativeContext(void* buffer) {
+ return &this->nativeContextSentry;
+}
+
+void TestAllocator::flush() {
+ flushCount++;
+}
+
+void TestAllocator::free(void* buffer, void* nativeContext) {
+ SkASSERT(this->allocated);
+ this->allocated = false;
+}
+
+void* TestAllocator::allocateLayer(const SkImageInfo& info, size_t* rowBytes) {
+ SkASSERT(!this->allocated);
+ this->allocated = true;
+ return &this->nativeLayerSentry;
+}
+
+// Need to trigger:
+// SkBitmapDevice::onCreateDevice() - hit in SkCanvas::internalSaveLayer()
+
+DEF_TEST(TestAllocator, reporter) {
+ TestAllocator* allocator = new TestAllocator;
+ SkCanvas* canvas = allocator->CreateCanvas(SkImageInfo::MakeN32Premul(100, 100));
+
+ REPORTER_ASSERT(reporter,
+ canvas->getTopLayerNative() == &allocator->nativeContextSentry);
+ REPORTER_ASSERT(reporter,
+ canvas->accessTopLayerPixels(nullptr, nullptr) == &allocator->nativeLayerSentry);
+
+ canvas->saveLayer(nullptr, nullptr);
+
+ REPORTER_ASSERT(reporter,
+ canvas->getTopLayerNative() == &allocator->nativeContextSentry);
+ REPORTER_ASSERT(reporter,
+ canvas->accessTopLayerPixels(nullptr, nullptr) == &allocator->nativeLayerSentry);
+}
+
« include/core/SkRasterCanvasLayerAllocator.h ('K') | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698