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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Test.h"
9
10 #include "SkCanvas.h"
11 #include "SkRasterCanvasLayerAllocator.h"
12
13 class TestAllocator : public SkRasterCanvasLayerAllocator {
14 public:
15 TestAllocator() : flushCount(0), allocated(false) {}
16 virtual ~TestAllocator() {}
17
18 void* getNativeContext(void* buffer) override;
19 void flush() override;
20 void free(void* buffer, void* nativeContext) override;
21
22 int nativeLayerSentry;
23 int nativeContextSentry;
24 int flushCount;
25 bool allocated;
26
27 protected:
28 void* allocateLayer(const SkImageInfo& info, size_t* rowBytes) override;
29 };
30
31 void* TestAllocator::getNativeContext(void* buffer) {
32 return &this->nativeContextSentry;
33 }
34
35 void TestAllocator::flush() {
36 flushCount++;
37 }
38
39 void TestAllocator::free(void* buffer, void* nativeContext) {
40 SkASSERT(this->allocated);
41 this->allocated = false;
42 }
43
44 void* TestAllocator::allocateLayer(const SkImageInfo& info, size_t* rowBytes) {
45 SkASSERT(!this->allocated);
46 this->allocated = true;
47 return &this->nativeLayerSentry;
48 }
49
50 // Need to trigger:
51 // SkBitmapDevice::onCreateDevice() - hit in SkCanvas::internalSaveLayer()
52
53 DEF_TEST(TestAllocator, reporter) {
54 TestAllocator* allocator = new TestAllocator;
55 SkCanvas* canvas = allocator->CreateCanvas(SkImageInfo::MakeN32Premul(100, 1 00));
56
57 REPORTER_ASSERT(reporter,
58 canvas->getTopLayerNative() == &allocator->nativeContextSentry);
59 REPORTER_ASSERT(reporter,
60 canvas->accessTopLayerPixels(nullptr, nullptr) == &allocator->nativeLaye rSentry);
61
62 canvas->saveLayer(nullptr, nullptr);
63
64 REPORTER_ASSERT(reporter,
65 canvas->getTopLayerNative() == &allocator->nativeContextSentry);
66 REPORTER_ASSERT(reporter,
67 canvas->accessTopLayerPixels(nullptr, nullptr) == &allocator->nativeLaye rSentry);
68 }
69
OLDNEW
« 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