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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 2250663002: Add alphaType() to SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@special-image-alpha-type
Patch Set: Remove virtuals from SkImage, slight cleanup Created 4 years, 4 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 | « tests/ImageTest.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
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include <functional> 8 #include <functional>
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, ctxInfo) { 121 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, ctxInfo) {
122 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 122 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
123 SkImageInfo requestInfo; 123 SkImageInfo requestInfo;
124 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, &req uestInfo)); 124 auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, &req uestInfo));
125 test_canvas_peek(reporter, surface, requestInfo, false); 125 test_canvas_peek(reporter, surface, requestInfo, false);
126 } 126 }
127 } 127 }
128 #endif 128 #endif
129 129
130 static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<Sk Surface>& surface, 130 static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<Sk Surface>& surface,
131 bool expectOpaque) { 131 SkAlphaType expectedAlphaType) {
132 REPORTER_ASSERT(reporter, surface); 132 REPORTER_ASSERT(reporter, surface);
133 if (surface) { 133 if (surface) {
134 sk_sp<SkImage> image(surface->makeImageSnapshot()); 134 sk_sp<SkImage> image(surface->makeImageSnapshot());
135 REPORTER_ASSERT(reporter, image); 135 REPORTER_ASSERT(reporter, image);
136 if (image) { 136 if (image) {
137 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque )); 137 REPORTER_ASSERT(reporter, image->alphaType() == expectedAlphaType);
138 } 138 }
139 } 139 }
140 } 140 }
141 DEF_TEST(SurfaceSnapshotAlphaType, reporter) { 141 DEF_TEST(SurfaceSnapshotAlphaType, reporter) {
142 for (auto& surface_func : { &create_surface, &create_direct_surface }) { 142 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
143 for (auto& isOpaque : { true, false }) { 143 for (auto& at: { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkA lphaType }) {
144 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA lphaType; 144 auto surface(surface_func(at, nullptr));
145 auto surface(surface_func(alphaType, nullptr)); 145 test_snapshot_alphatype(reporter, surface, at);
146 test_snapshot_alphatype(reporter, surface, isOpaque);
147 } 146 }
148 } 147 }
149 } 148 }
150 #if SK_SUPPORT_GPU 149 #if SK_SUPPORT_GPU
151 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ctxIn fo) { 150 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ctxIn fo) {
152 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 151 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
153 for (auto& isOpaque : { true, false }) { 152 // GPU doesn't support creating unpremul surfaces, so only test opaque + premul
154 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA lphaType; 153 for (auto& at : { kOpaque_SkAlphaType, kPremul_SkAlphaType }) {
155 auto surface(surface_func(ctxInfo.grContext(), alphaType, nullptr)); 154 auto surface(surface_func(ctxInfo.grContext(), at, nullptr));
156 test_snapshot_alphatype(reporter, surface, isOpaque); 155 test_snapshot_alphatype(reporter, surface, at);
157 } 156 }
158 } 157 }
159 } 158 }
160 #endif 159 #endif
161 160
162 static GrBackendObject get_surface_backend_texture_handle( 161 static GrBackendObject get_surface_backend_texture_handle(
163 SkSurface* s, SkSurface::BackendHandleAccess a) { 162 SkSurface* s, SkSurface::BackendHandleAccess a) {
164 return s->getTextureHandle(a); 163 return s->getTextureHandle(a);
165 } 164 }
166 static GrBackendObject get_surface_backend_render_target_handle( 165 static GrBackendObject get_surface_backend_render_target_handle(
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 // our surface functions. 903 // our surface functions.
905 GrRenderTarget* rt = surface->getCanvas()->internal_private_accessTo pLayerDrawContext() 904 GrRenderTarget* rt = surface->getCanvas()->internal_private_accessTo pLayerDrawContext()
906 ->accessRenderTarget(); 905 ->accessRenderTarget();
907 REPORTER_ASSERT(reporter, 906 REPORTER_ASSERT(reporter,
908 ctxInfo.grContext()->resourceProvider()->attachStenc ilAttachment(rt)); 907 ctxInfo.grContext()->resourceProvider()->attachStenc ilAttachment(rt));
909 gpu->deleteTestingOnlyBackendTexture(textureObject); 908 gpu->deleteTestingOnlyBackendTexture(textureObject);
910 } 909 }
911 } 910 }
912 } 911 }
913 #endif 912 #endif
OLDNEW
« no previous file with comments | « tests/ImageTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698