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

Side by Side Diff: tests/SpecialSurfaceTest.cpp

Issue 1579323002: Add SkSpecialImage & SkSpecialSurface classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address code review comments Created 4 years, 11 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
« src/core/SkSpecialImage.h ('K') | « tests/SpecialImageTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkCanvas.h"
9 #include "SkSpecialImage.h"
10 #include "SkSpecialSurface.h"
11 #include "Test.h"
12
13 #if SK_SUPPORT_GPU
14 #include "GrContext.h"
15 #include "SkGr.h"
16 #endif
17
18 // Both 'kSmallerSize' and 'kFullSize' need to be a non-power-of-2 to exercise
19 // the gpu's loose fit behavior
20 static const int kSmallerSize = 10;
21 static const int kPad = 5;
22 static const int kFullSize = kSmallerSize + 2 * kPad;
23
24 // Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapsho t)
25 static void test_surface(SkSpecialSurface* surf, skiatest::Reporter* reporter, i nt offset) {
26
27 REPORTER_ASSERT(reporter, offset == surf->activeRect().fLeft);
28 REPORTER_ASSERT(reporter, offset == surf->activeRect().fTop);
29 REPORTER_ASSERT(reporter, kSmallerSize == surf->activeRect().width());
30 REPORTER_ASSERT(reporter, kSmallerSize == surf->activeRect().height());
31
32 SkCanvas* canvas = surf->getCanvas();
33 SK_ALWAYSBREAK(canvas);
34
35 canvas->clear(SK_ColorRED);
36
37 SkAutoTUnref<SkSpecialImage> img(surf->newImageSnapshot());
38 REPORTER_ASSERT(reporter, img);
39
40 REPORTER_ASSERT(reporter, surf->activeRect() == img->activeRect());
41
42 // the canvas was invalidated by the newImageSnapshot call
43 REPORTER_ASSERT(reporter, !surf->getCanvas());
44 }
45
46 DEF_TEST(SpecialSurface_Raster, reporter) {
47
48 SkImageInfo info = SkImageInfo::MakeN32(kSmallerSize, kSmallerSize, kOpaque_ SkAlphaType);
49 SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewRaster(info));
50
51 test_surface(surf, reporter, 0);
52 }
53
54 #if SK_SUPPORT_GPU
55
56 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, context) {
57 GrSurfaceDesc desc;
58 desc.fConfig = kSkia8888_GrPixelConfig;
59 desc.fFlags = kRenderTarget_GrSurfaceFlag;
60 desc.fWidth = kSmallerSize;
61 desc.fHeight = kSmallerSize;
62
63 SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewGpu(context, desc)) ;
64
65 test_surface(surf, reporter, 0);
66 }
67
68 // test the more flexible factory
69 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, context) {
70 GrSurfaceDesc desc;
71 desc.fConfig = kSkia8888_GrPixelConfig;
72 desc.fFlags = kRenderTarget_GrSurfaceFlag;
73 desc.fWidth = kFullSize;
74 desc.fHeight = kFullSize;
75
76 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture (desc));
77 SK_ALWAYSBREAK(temp);
78
79 const SkIRect activeRect = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmal lerSize);
80
81 SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewGpu(activeRect, tem p));
82
83 test_surface(surf, reporter, kPad);
84
85 // TODO: check that the clear didn't escape the active region
86 }
87
88 #endif
OLDNEW
« src/core/SkSpecialImage.h ('K') | « tests/SpecialImageTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698