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

Side by Side Diff: tests/TextureStorageAllocator.cpp

Issue 1623653002: skia: Add support for CHROMIUM_image backed textures. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Minor cleanup. Created 4 years, 10 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/gpu/SkGpuDevice.h ('K') | « src/image/SkSurface_Gpu.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 "Test.h"
9 #if SK_SUPPORT_GPU
10 #include "gl/GrGLGpu.h"
11 #include "SkSurface_Gpu.h"
12 #include "../include/gpu/gl/SkGLContext.h"
13 #include "../include/gpu/GrTypes.h"
14
15 class TestStorageAllocator : public GrTextureStorageAllocator {
16 public:
17 bool supportsPixelConfig(GrPixelConfig config) override {
18 return true;
19 }
20 bool allocateTextureStorage(GrBackendObject texture, unsigned width, unsigned height) override {
21 if (!m_allowAllocation)
22 return false;
23 GrColor pixels[width * height];
24 for (unsigned y = 0; y < height; ++y) {
25 for (unsigned x = 0; x < width; ++x) {
26 pixels[y * width + x] = 0;
27 }
28 }
29
30 GrGLuint id;
31 GrGLenum target = GR_GL_TEXTURE_2D;
32 GR_GL_CALL(m_gl, GenTextures(1, &id));
33 GR_GL_CALL(m_gl, BindTexture(target, id));
34 GR_GL_CALL(m_gl, TexImage2D(target, 0, GR_GL_RGBA, width, height, 0, GR_GL_R GBA,
35 GR_GL_UNSIGNED_BYTE, pixels));
36 GrGLTextureInfo* info = reinterpret_cast<GrGLTextureInfo*>(texture);
37 info->fID = id;
38 info->fTarget = target;
39 m_mostRecentlyAllocatedStorage = id;
40
41 return true;
42 }
43 void deallocateTextureStorage(GrBackendObject texture) override {
44 GrGLTextureInfo* info = reinterpret_cast<GrGLTextureInfo*>(texture);
45 GR_GL_CALL(m_gl, DeleteTextures(1, &(info->fID)));
46 }
47
48 GrGLuint m_mostRecentlyAllocatedStorage;
49 const GrGLInterface* m_gl;
50 bool m_allowAllocation;
51 };
52
53 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTexture, reporter, context, glContext) {
54 static const int kWidth = 13;
55 static const int kHeight = 13;
56
57 const GrGLInterface* gl = glContext->gl();
58 TestStorageAllocator allocator;
59 allocator.m_allowAllocation = true;
60 allocator.m_gl = gl;
61 SkSurface* surface = SkSurface_Gpu::NewRenderTarget(
62 context, SkSurface_Gpu::kNo_Budgeted, SkImageInfo::MakeN32Premul(kWi dth, kHeight), 0,
63 NULL, &allocator);
64 REPORTER_ASSERT(reporter, surface);
65 GrGLuint id = allocator.m_mostRecentlyAllocatedStorage;
66
67 SkImage* image = surface->newImageSnapshot();
68 REPORTER_ASSERT(reporter, image->isTextureBacked());
69 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(1,1);
70 GrColor dest = 0x11223344;
71 REPORTER_ASSERT(reporter, image->readPixels(imageInfo, &dest, 4 * kWidth, 0, 0));
72 REPORTER_ASSERT(reporter, GrColorUnpackG(dest) == 0);
73
74 surface->getCanvas()->clear(SK_ColorGREEN);
75 SkImage* image2 = surface->newImageSnapshot();
76 REPORTER_ASSERT(reporter, image2->isTextureBacked());
77 REPORTER_ASSERT(reporter, allocator.m_mostRecentlyAllocatedStorage != id);
78
79 REPORTER_ASSERT(reporter, image2->readPixels(imageInfo, &dest, 4 * kWidth, 0 , 0));
80 REPORTER_ASSERT(reporter, GrColorUnpackG(dest) == 255);
81 }
82
83 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTextureFailure, reporter, context, glCo ntext) {
84 static const int kWidth = 13;
85 static const int kHeight = 13;
86
87 const GrGLInterface* gl = glContext->gl();
88 TestStorageAllocator allocator;
89 allocator.m_allowAllocation = false;
90 allocator.m_gl = gl;
91 SkSurface* surface = SkSurface_Gpu::NewRenderTarget(
92 context, SkSurface_Gpu::kNo_Budgeted, SkImageInfo::MakeN32Premul(kWi dth, kHeight), 0,
93 NULL, &allocator);
94 REPORTER_ASSERT(reporter, !surface);
95 }
96
97 #endif
OLDNEW
« src/gpu/SkGpuDevice.h ('K') | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698