Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6da7f63 authored by Bo Liu's avatar Bo Liu
Browse files

Add color space params to webview gl functor

Bug: 111436479
Test: Compiles
Change-Id: I6713afbb871a5c7027bac1e0f52ce2a841f38e25
parent 07182c86
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ void GLFunctorDrawable::onDraw(SkCanvas* canvas) {
    info.width = fboSize.width();
    info.height = fboSize.height();
    mat4.asColMajorf(&info.transform[0]);
    info.color_space_ptr = canvas->imageInfo().colorSpace();

    // ensure that the framebuffer that the webview will render into is bound before we clear
    // the stencil and/or draw the functor.
+3 −2
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ void VkInteropFunctorDrawable::onDraw(SkCanvas* canvas) {
        info.width = mFBInfo.width();
        info.height = mFBInfo.height();
        mat4.asColMajorf(&info.transform[0]);
        info.color_space_ptr = canvas->imageInfo().colorSpace();

        glViewport(0, 0, info.width, info.height);

@@ -179,8 +180,8 @@ void VkInteropFunctorDrawable::onDraw(SkCanvas* canvas) {
    canvas->resetMatrix();

    auto functorImage = SkImage::MakeFromAHardwareBuffer(
            reinterpret_cast<AHardwareBuffer*>(mFrameBuffer.get()), kPremul_SkAlphaType, nullptr,
            kBottomLeft_GrSurfaceOrigin);
            reinterpret_cast<AHardwareBuffer*>(mFrameBuffer.get()), kPremul_SkAlphaType,
            canvas->imageInfo().refColorSpace(), kBottomLeft_GrSurfaceOrigin);
    canvas->drawImage(functorImage, 0, 0, &paint);
    canvas->restore();
}
+5 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
#ifndef ANDROID_HWUI_DRAW_GL_INFO_H
#define ANDROID_HWUI_DRAW_GL_INFO_H

#include <SkColorSpace.h>

namespace android {
namespace uirenderer {

@@ -41,6 +43,9 @@ struct DrawGlInfo {
    // Input: current transform matrix, in OpenGL format
    float transform[16];

    // Input: Color space.
    const SkColorSpace* color_space_ptr;

    // Output: dirty region to redraw
    float dirtyLeft;
    float dirtyTop;
+12 −1
Original line number Diff line number Diff line
@@ -20,7 +20,8 @@ extern "C" {
// android to chromium are versioned.
//
// 1 is Android Q. This matches kAwDrawGLInfoVersion version 3.
static const int kAwDrawFnVersion = 1;
// 2 Adds transfer_function_* and color_space_toXYZD50 to AwDrawFn_DrawGLParams.
static const int kAwDrawFnVersion = 2;

struct AwDrawFn_OnSyncParams {
  int version;
@@ -64,6 +65,16 @@ struct AwDrawFn_DrawGLParams {
  // Input: current transformation matrix in surface pixels.
  // Uses the column-based OpenGL matrix format.
  float transform[16];

  // Input: Color space parameters.
  float transfer_function_g;
  float transfer_function_a;
  float transfer_function_b;
  float transfer_function_c;
  float transfer_function_d;
  float transfer_function_e;
  float transfer_function_f;
  float color_space_toXYZD50[9];
};

struct AwDrawFn_InitVkParams {
+14 −0
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ void onDestroyed(int functor, void* data) {

void draw_gl(int functor, void* data,
             const uirenderer::DrawGlInfo& draw_gl_params) {
  float gabcdef[7];
  draw_gl_params.color_space_ptr->transferFn(gabcdef);
  AwDrawFn_DrawGLParams params = {
      .version = kAwDrawFnVersion,
      .clip_left = draw_gl_params.clipLeft,
@@ -64,12 +66,24 @@ void draw_gl(int functor, void* data,
      .width = draw_gl_params.width,
      .height = draw_gl_params.height,
      .is_layer = draw_gl_params.isLayer,
      .transfer_function_g = gabcdef[0],
      .transfer_function_a = gabcdef[1],
      .transfer_function_b = gabcdef[2],
      .transfer_function_c = gabcdef[3],
      .transfer_function_d = gabcdef[4],
      .transfer_function_e = gabcdef[5],
      .transfer_function_f = gabcdef[6],
  };
  COMPILE_ASSERT(NELEM(params.transform) == NELEM(draw_gl_params.transform),
                 mismatched_transform_matrix_sizes);
  for (int i = 0; i < NELEM(params.transform); ++i) {
    params.transform[i] = draw_gl_params.transform[i];
  }
  COMPILE_ASSERT(sizeof(params.color_space_toXYZD50) == sizeof(skcms_Matrix3x3),
                 gamut_transform_size_mismatch);
  draw_gl_params.color_space_ptr->toXYZD50(
      reinterpret_cast<skcms_Matrix3x3*>(&params.color_space_toXYZD50));

  SupportData* support = static_cast<SupportData*>(data);
  support->callbacks.draw_gl(functor, support->data, &params);
}