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

Side by Side Diff: tests/DeviceTest.cpp

Issue 2161533003: Add makeSpecial calls to SkGpuDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Nervous compilers Created 4 years, 5 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
« no previous file with comments | « src/gpu/SkGpuDevice.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 "SkBitmapDevice.h"
9 #include "SkDevice.h"
10 #include "SkSpecialImage.h"
11
12 #if SK_SUPPORT_GPU
13 #include "SkGpuDevice.h"
14 #endif
15
16 #include "Test.h"
17
18 class DeviceTestingAccess {
19 public:
20 static sk_sp<SkSpecialImage> MakeSpecial(SkBaseDevice* dev, const SkBitmap& bm) {
21 return dev->makeSpecial(bm);
22 }
23
24 static sk_sp<SkSpecialImage> MakeSpecial(SkBaseDevice* dev, SkImage* img) {
25 return dev->makeSpecial(img);
26 }
27
28 static sk_sp<SkSpecialImage> SnapSpecial(SkBaseDevice* dev) {
29 return dev->snapSpecial();
30 }
31 };
32
33 // TODO: re-enable this when Raster methods are implemented
34 #if 0
35 DEF_TEST(SpecialImage_BitmapDevice, reporter) {
36 static const int kWidth = 100;
37 static const int kHeight = 90;
38
39 SkImageInfo ii = SkImageInfo::MakeN32Premul(2*kWidth, 2*kHeight);
40
41 SkAutoTUnref<SkBaseDevice> bmDev(SkBitmapDevice::Create(ii));
42
43 SkBitmap bm;
44 bm.tryAllocN32Pixels(kWidth, kHeight);
45
46 // Create a raster-backed special image from a raster-backed SkBitmap
47 sk_sp<SkSpecialImage> special = DeviceTestingAccess::MakeSpecial(bmDev.get() , bm);
48 SkASSERT(!special->isTextureBacked());
49 SkASSERT(kWidth == special->width());
50 SkASSERT(kHeight == special->height());
51 SkASSERT(bm.getGenerationID() == special->uniqueID());
52 SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
53
54 // Create a raster-backed special image from a raster-backed SkImage
55 sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
56 special = DeviceTestingAccess::MakeSpecial(bmDev.get(), image.get());
57 SkASSERT(!special->isTextureBacked());
58 SkASSERT(kWidth == special->width());
59 SkASSERT(kHeight == special->height());
60 SkASSERT(bm.getGenerationID() == special->uniqueID());
61 SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
62
63 // Snap the device as a raster-backed special image
64 special = DeviceTestingAccess::SnapSpecial(bmDev.get());
65 SkASSERT(!special->isTextureBacked());
66 SkASSERT(2*kWidth == special->width());
67 SkASSERT(2*kHeight == special->height());
68 SkASSERT(SkIRect::MakeWH(2*kWidth, 2*kHeight) == special->subset());
69 }
70 #endif
71
72
73 #if SK_SUPPORT_GPU
74
75 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_GPUDevice, reporter, ctxInfo) {
76 GrContext* context = ctxInfo.grContext();
77
78 static const int kWidth = 100;
79 static const int kHeight = 90;
80
81 SkImageInfo ii = SkImageInfo::MakeN32Premul(2*kWidth, 2*kHeight);
82
83 sk_sp<SkBaseDevice> gpuDev(SkGpuDevice::Make(context, SkBudgeted::kNo, ii,
84 0, nullptr, SkGpuDevice::kClear _InitContents));
85
86 SkBitmap bm;
87 SkAssertResult(bm.tryAllocN32Pixels(kWidth, kHeight));
88
89 // Create a gpu-backed special image from a raster-backed SkBitmap
90 sk_sp<SkSpecialImage> special = DeviceTestingAccess::MakeSpecial(gpuDev.get( ), bm);
91 SkASSERT(special->isTextureBacked());
92 SkASSERT(kWidth == special->width());
93 SkASSERT(kHeight == special->height());
94 SkASSERT(bm.getGenerationID() == special->uniqueID());
95 SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
96
97 // Create a gpu-backed special image from a raster-backed SkImage
98 sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
99 special = DeviceTestingAccess::MakeSpecial(gpuDev.get(), image.get());
100 SkASSERT(special->isTextureBacked());
101 SkASSERT(kWidth == special->width());
102 SkASSERT(kHeight == special->height());
103 // TODO: Hmmm, this is a bit unexpected
104 SkASSERT(image->uniqueID() != special->uniqueID());
105 SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
106
107 // Create a gpu-backed special image from a gpu-backed SkImage
108 image = image->makeTextureImage(context);
109 special = DeviceTestingAccess::MakeSpecial(gpuDev.get(), image.get());
110 SkASSERT(special->isTextureBacked());
111 SkASSERT(kWidth == special->width());
112 SkASSERT(kHeight == special->height());
113 SkASSERT(image->uniqueID() == special->uniqueID());
114 SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
115
116 // Snap the device as a gpu-backed special image
117 special = DeviceTestingAccess::SnapSpecial(gpuDev.get());
118 SkASSERT(special->isTextureBacked());
119 SkASSERT(2*kWidth == special->width());
120 SkASSERT(2*kHeight == special->height());
121 SkASSERT(SkIRect::MakeWH(2*kWidth, 2*kHeight) == special->subset());
122 }
123
124 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698