sk_sp<SkSurface>
SkSurface_Compute::MakeComputeBackedSurface(SkWindow                       * const window,
                                            const SkWindow::AttachmentInfo &       attachmentInfo,
                                            GrGLInterface const            * const grInterface,
                                            GrContext                      * const grContext,
                                            sk_sp<SkContext_Compute>               compute)
{
  GrBackendRenderTargetDesc desc;

  desc.fWidth  = SkScalarRoundToInt(window->width());
  desc.fHeight = SkScalarRoundToInt(window->height());

  if (0 == desc.fWidth || 0 == desc.fHeight) {
    return nullptr;
  }

  // TODO: Query the actual framebuffer for sRGB capable. However, to
  // preserve old (fake-linear) behavior, we don't do this. Instead, rely
  // on the flag (currently driven via 'C' mode in SampleApp).
  //
  // Also, we may not have real sRGB support (ANGLE, in particular), so check for
  // that, and fall back to L32:
  //
  // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversion on write,
  // so pretend that it's non-sRGB 8888:
  desc.fConfig =
    grContext->caps()->srgbSupport() &&
    SkImageInfoIsGammaCorrect(window->info()) &&
    (attachmentInfo.fColorBits != 30)
    ? kSkiaGamma8888_GrPixelConfig : kSkia8888_GrPixelConfig;

  desc.fOrigin      = kBottomLeft_GrSurfaceOrigin;
  desc.fSampleCnt   = 0; //  attachmentInfo.fSampleCount;
  desc.fStencilBits = 0; //  attachmentInfo.fStencilBits;

  GrGLint buffer;

  GR_GL_GetIntegerv(grInterface,GR_GL_FRAMEBUFFER_BINDING,&buffer);
  desc.fRenderTargetHandle = buffer;

  sk_sp<SkColorSpace> colorSpace =
    grContext->caps()->srgbSupport() && SkImageInfoIsGammaCorrect(window->info())
    ? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;

  //
  //
  //

  if (!grContext) {
    return nullptr;
  }

  if (!SkSurface_Gpu::Valid(grContext,desc.fConfig,colorSpace.get())) {
    return nullptr;
  }

  return sk_make_sp<SkSurface_Compute>(compute,desc.fWidth,desc.fHeight);
}
Beispiel #2
0
void WindowContext::presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<GrRenderTarget> rt,
                                         int colorBits) {
    if (!this->isGpuContext() || colorBits > 24 ||
        kRGBA_F16_SkColorType == fDisplayParams.fColorType) {
        // We made/have an off-screen surface. Get the contents as an SkImage:
        SkImageInfo info = SkImageInfo::Make(fWidth, fHeight,
                                             fDisplayParams.fColorType,
                                             kUnknown_SkAlphaType,
                                             fDisplayParams.fColorSpace);
        SkBitmap bm;
        bm.allocPixels(info);
        renderSurface->getCanvas()->readPixels(&bm, 0, 0);
        SkPixmap pm;
        bm.peekPixels(&pm);
        sk_sp<SkImage> image(SkImage::MakeTextureFromPixmap(fContext, pm,
                             SkBudgeted::kNo));
        GrTexture* texture = as_IB(image)->peekTexture();
        SkASSERT(texture);

        // With ten-bit output, we need to manually apply the gamma of the output device
        // (unless we're in non-gamma correct mode, in which case our data is already
        // fake-sRGB, like we're expected to put in the 10-bit buffer):
        bool doGamma = (colorBits == 30) && SkImageInfoIsGammaCorrect(info);
        fContext->applyGamma(rt.get(), texture, doGamma ? 1.0f / 2.2f : 1.0f);
    }
}
Beispiel #3
0
GrRenderTarget* SkWindow::renderTarget(const AttachmentInfo& attachmentInfo,
                                       const GrGLInterface* interface, GrContext* grContext) {
    GrBackendRenderTargetDesc desc;
    desc.fWidth = SkScalarRoundToInt(this->width());
    desc.fHeight = SkScalarRoundToInt(this->height());
    // TODO: Query the actual framebuffer for sRGB capable. However, to
    // preserve old (fake-linear) behavior, we don't do this. Instead, rely
    // on the flag (currently driven via 'C' mode in SampleApp).
    //
    // Also, we may not have real sRGB support (ANGLE, in particular), so check for
    // that, and fall back to L32:
    desc.fConfig = grContext->caps()->srgbSupport() && SkImageInfoIsGammaCorrect(info())
                   ? kSkiaGamma8888_GrPixelConfig
                   : kSkia8888_GrPixelConfig;
    desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
    desc.fSampleCnt = attachmentInfo.fSampleCount;
    desc.fStencilBits = attachmentInfo.fStencilBits;
    GrGLint buffer;
    GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer);
    desc.fRenderTargetHandle = buffer;
    return grContext->textureProvider()->wrapBackendRenderTarget(desc);
}