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 // 9 // 10 // 11 12 #include "SkSurface_Compute.h" 13 #include "SkDevice_Compute.h" 14 #include "SkImage_Compute.h" 15 16 // 17 // 18 // 19 20 #if SK_SUPPORT_GPU_COMPUTE 21 22 // 23 // C++ 24 // 25 26 #include "gl/GrGLGpu.h" 27 #include "SkSurface_Gpu.h" 28 29 // 30 // 31 // 32 33 SkSurface_Compute::SkSurface_Compute(sk_sp<SkContext_Compute> compute, 34 int const width, int const height) 35 : INHERITED(width,height,nullptr), 36 compute(compute) 37 { 38 // 39 // resize interop 40 // 41 // skc_interop_size_set(compute->interop,width,height,NULL); TODO skc.h 42 } 43 44 SkSurface_Compute::~SkSurface_Compute() 45 { 46 ; 47 } 48 49 // 50 // 51 // 52 53 SkCanvas* 54 SkSurface_Compute::onNewCanvas() 55 { 56 uint32_t w = 0,h = 0; 57 58 // skc_interop_size_get(compute->interop,&w,&h); TODO skc.h 59 60 SkDevice_Compute * const device_compute = new SkDevice_Compute(compute,w,h); 61 SkCanvas * const canvas = new SkCanvas(device_compute,SkCanvas::kConservativeRasterClip_InitFlag); 62 63 // 64 // destroy device upon surface destruction 65 // 66 device = sk_sp<SkBaseDevice>(device_compute); 67 68 // 69 // move origin from upper left to lower left 70 // 71 SkMatrix matrix; 72 73 matrix.setScaleTranslate(1.0f,-1.0f,0.0f,(SkScalar)h); 74 75 canvas->setMatrix(matrix); 76 77 return canvas; 78 } 79 80 // 81 // 82 // 83 84 sk_sp<SkSurface> 85 SkSurface_Compute::onNewSurface(const SkImageInfo& info) 86 { 87 return sk_make_sp<SkSurface_Compute>(compute,info.width(),info.height()); 88 } 89 90 // 91 // 92 // 93 94 sk_sp<SkImage> 95 SkSurface_Compute::onNewImageSnapshot() 96 { 97 uint32_t w,h; 98 99 // skc_interop_size_get(compute->interop,&w,&h); TODO skc.h 100 101 GrGLuint snap; 102 103 // skc_interop_snap_create(compute->interop, TODO skc.h 104 // skc_surface_interop_surface_get(compute->surface), 105 // &snap); 106 107 return sk_make_sp<SkImage_Compute>(compute,snap,w,h); 108 } 109 110 // 111 // 112 // 113 114 void 115 SkSurface_Compute::onCopyOnWrite(ContentChangeMode mode) 116 { 117 ; 118 } 119 120 // 121 // 122 // 123 124 #if 0 125 126 sk_sp<SkSurface> 127 SkSurface_Compute::MakeComputeBackedSurface(SkWindow * const window, 128 const SkWindow::AttachmentInfo & attachmentInfo, 129 GrGLInterface const * const grInterface, 130 GrContext * const grContext, 131 sk_sp<SkContext_Compute> compute) 132 { 133 GrBackendRenderTargetDesc desc; 134 135 desc.fWidth = SkScalarRoundToInt(window->width()); 136 desc.fHeight = SkScalarRoundToInt(window->height()); 137 138 if (0 == desc.fWidth || 0 == desc.fHeight) { 139 return nullptr; 140 } 141 142 // TODO: Query the actual framebuffer for sRGB capable. However, to 143 // preserve old (fake-linear) behavior, we don't do this. Instead, rely 144 // on the flag (currently driven via 'C' mode in SampleApp). 145 // 146 // Also, we may not have real sRGB support (ANGLE, in particular), so check for 147 // that, and fall back to L32: 148 // 149 // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversion on write, 150 // so pretend that it's non-sRGB 8888: 151 desc.fConfig = 152 grContext->caps()->srgbSupport() && 153 SkImageInfoIsGammaCorrect(window->info()) && 154 (attachmentInfo.fColorBits != 30) 155 ? kSkiaGamma8888_GrPixelConfig : kSkia8888_GrPixelConfig; 156 157 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; 158 desc.fSampleCnt = 0; // attachmentInfo.fSampleCount; 159 desc.fStencilBits = 0; // attachmentInfo.fStencilBits; 160 161 GrGLint buffer; 162 163 GR_GL_GetIntegerv(grInterface,GR_GL_FRAMEBUFFER_BINDING,&buffer); 164 desc.fRenderTargetHandle = buffer; 165 166 sk_sp<SkColorSpace> colorSpace = 167 grContext->caps()->srgbSupport() && SkImageInfoIsGammaCorrect(window->info()) 168 ? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr; 169 170 // 171 // 172 // 173 174 if (!grContext) { 175 return nullptr; 176 } 177 178 if (!SkSurface_Gpu::Valid(grContext,desc.fConfig,colorSpace.get())) { 179 return nullptr; 180 } 181 182 return sk_make_sp<SkSurface_Compute>(compute,desc.fWidth,desc.fHeight); 183 } 184 185 #endif 186 187 // 188 // 189 // 190 191 #endif 192