Merge "Add color space params to webview gl functor"

This commit is contained in:
TreeHugger Robot
2019-01-25 13:40:41 +00:00
committed by Android (Google) Code Review
5 changed files with 35 additions and 3 deletions

View File

@@ -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.

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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);
}