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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1931293003: Revert of Make stencils be attachable to render targets created via… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« no previous file with comments | « src/gpu/gl/GrGLGpu.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 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 desc.fHeight = kHeight; 890 desc.fHeight = kHeight;
891 desc.fFlags = kRenderTarget_GrBackendTextureFlag; 891 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
892 desc.fTextureHandle = textureObject; 892 desc.fTextureHandle = textureObject;
893 893
894 auto surface = SkSurface::MakeFromBackendTexture(context, desc, nullptr) ; 894 auto surface = SkSurface::MakeFromBackendTexture(context, desc, nullptr) ;
895 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); 895 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB);
896 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); 896 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject);
897 } 897 }
898 } 898 }
899 #endif 899 #endif
900
901 #if SK_SUPPORT_GPU
902 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceWrappedTextureAsRenderTarget, repor ter, ctxInfo) {
903 GrGpu* gpu = ctxInfo.fGrContext->getGpu();
904 if (!gpu) {
905 return;
906 }
907 // Validate that we can draw paths to a canvas of a surface created with
908 // SkSurface::MakeFromBackendTextureAsRenderTarget. The code intends to enfo rce the use of
909 // stencil buffer. The original bug prevented the creation of stencil buffer , causing an assert
910 // while drawing paths.
911
912 static const int kW = 100;
913 static const int kH = 100;
914 static const uint32_t kOrigColor = SK_ColorRED;
915 const SkColor kShapeColor = SK_ColorGREEN;
916
917 SkPath clipPath;
918 clipPath.quadTo(SkIntToScalar(kW), SkIntToScalar(0), SkIntToScalar(kW), SkIn tToScalar(kH));
919 clipPath.lineTo(SkIntToScalar(0), SkIntToScalar(kH));
920 clipPath.lineTo(SkIntToScalar(0), SkIntToScalar(0));
921 clipPath.close();
922 SkPath path;
923 path.quadTo(SkIntToScalar(0), SkIntToScalar(kH), SkIntToScalar(kW), SkIntToS calar(kH));
924 path.lineTo(SkIntToScalar(kW), SkIntToScalar(0));
925 path.lineTo(SkIntToScalar(0), SkIntToScalar(0));
926 path.close();
927 SkPaint paint;
928 paint.setAntiAlias(true);
929 paint.setColor(kShapeColor);
930
931 SkImageInfo bitmapInfo = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, k Premul_SkAlphaType);
932 for (int sampleCnt : {0, 4, 8}) {
933 SkBitmap bitmap;
934 bitmap.allocPixels(bitmapInfo);
935 bitmap.eraseColor(kOrigColor);
936 GrBackendObject texHandle = gpu->createTestingOnlyBackendTexture(bitmap. getPixels(), kW, kH,
937 kRGBA_8 888_GrPixelConfig);
938
939 GrBackendTextureDesc wrappedDesc;
940 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig;
941 wrappedDesc.fWidth = kW;
942 wrappedDesc.fHeight = kH;
943 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
944 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
945 wrappedDesc.fTextureHandle = texHandle;
946 wrappedDesc.fSampleCnt = sampleCnt;
947
948 sk_sp<SkSurface> surface(
949 SkSurface::MakeFromBackendTextureAsRenderTarget(ctxInfo.fGrContext, wrappedDesc,
950 nullptr));
951 if (!surface) {
952 continue;
953 }
954
955 surface->getCanvas()->clipPath(clipPath, SkRegion::kIntersect_Op, true);
956 surface->getCanvas()->drawPath(path, paint);
957 SkAssertResult(surface->readPixels(bitmapInfo, bitmap.getPixels(),
958 bitmap.rowBytes(), 0, 0));
959 // Ensure that the shape color ends up to the surface.
960 REPORTER_ASSERT(reporter, kShapeColor == bitmap.getColor(kW / 2, kH / 2) );
961 SkColor backgroundColor = bitmap.getColor(kW - 1, 0);
962 if (!sampleCnt) {
963 // Ensure that the original texture color is preserved in pixels tha t aren't rendered to
964 // via the surface.
965 REPORTER_ASSERT(reporter, kOrigColor == backgroundColor);
966 }
967 gpu->deleteTestingOnlyBackendTexture(texHandle);
968 }
969 }
970 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698