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

Commit 237b0928 authored by Chris Blume's avatar Chris Blume
Browse files

Rename Vulkan functor items to match style

Several of the first-iteration file/class/member variable names did not
match the style of their surrounding neighbors. This CL fixes that.

Test: Compiles
Change-Id: I9374e6cab79c57413e728d253067306d15011f2c
parent 9a66ff3c
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -53,16 +53,16 @@ struct DrawVkInfo {
    VkFormat format;

    // Input: Color space transfer params
    float G;
    float A;
    float B;
    float C;
    float D;
    float E;
    float F;
    float g;
    float a;
    float b;
    float c;
    float d;
    float e;
    float f;

    // Input: Color space transformation from linear RGB to D50-adapted XYZ
    float matrix[9];
    float colorSpaceTransform[9];

    // Input: current clip rect
    int clipLeft;
+0 −1
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ cc_library_shared {
    srcs: [
        "draw_functor.cpp",
        "draw_gl_functor.cpp",
        "draw_vk_functor.cpp",
        "functor_utils.cpp",
        "jni_entry_point.cpp",
        "graphics_utils.cpp",
+0 −125
Original line number Diff line number Diff line
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
//******************************************************************************
// This is a copy of the coresponding android_webview/public/browser header.
// Any changes to the interface should be made there.
//
// The purpose of having the copy is twofold:
//  - it removes the need to have Chromium sources present in the tree in order
//    to build the plat_support library,
//  - it captures API that the corresponding Android release supports.
//******************************************************************************

#ifndef ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_VK_H_
#define ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_VK_H_

#include <vulkan/vulkan.h>

#ifdef __cplusplus
extern "C" {
#endif

static const int kAwDrawVKInfoVersion = 1;

// Holds the information required to trigger initialization of the Vulkan
// functor.
struct InitParams {
  // All params are input
  VkInstance instance;
  VkPhysicalDevice physical_device;
  VkDevice device;
  VkQueue queue;
  uint32_t graphics_queue_index;
  uint32_t instance_version;
  const char* const* enabled_extension_names;
  // Only one of device_features and device_features_2 should be non-null.
  // If both are null then no features are enabled.
  VkPhysicalDeviceFeatures* device_features;
  VkPhysicalDeviceFeatures2* device_features_2;
};

// Holds the information required to trigger an Vulkan composite operation.
struct CompositeParams {
  // Input: current width/height of destination surface.
  int width;
  int height;

  // Input: is the render target a FBO
  bool is_layer;

  // Input: current transform matrix
  float transform[16];

  // Input WebView should do its main compositing draws into this. It cannot do
  // anything that would require stopping the render pass.
  VkCommandBuffer secondary_command_buffer;

  // Input: The main color attachment index where secondary_command_buffer will
  // eventually be submitted.
  uint32_t color_attachment_index;

  // Input: A render pass which will be compatible to the one which the
  // secondary_command_buffer will be submitted into.
  VkRenderPass compatible_render_pass;

  // Input: Format of the destination surface.
  VkFormat format;

  // Input: Color space transfer params
  float G;
  float A;
  float B;
  float C;
  float D;
  float E;
  float F;

  // Input: Color space transformation from linear RGB to D50-adapted XYZ
  float matrix[9];

  // Input: current clip rect
  int clip_left;
  int clip_top;
  int clip_right;
  int clip_bottom;
};

// Holds the information for the post-submission callback of main composite
// draw.
struct PostCompositeParams {
  // Input: Fence for the composite command buffer to signal it has finished its
  // work on the GPU.
  int fd;
};

// Holds the information required to trigger an Vulkan operation.
struct AwDrawVKInfo {
  int version;  // The AwDrawVKInfo this struct was built with.

  // Input: tells the draw function what action to perform.
  enum Mode {
    kModeInit = 0,
    kModeReInit = 1,
    kModePreComposite = 2,
    kModeComposite = 3,
    kModePostComposite = 4,
    kModeSync = 5,
  } mode;

  // Input: The parameters for the functor being called
  union ParamUnion {
    struct InitParams init_params;
    struct CompositeParams composite_params;
    struct PostCompositeParams post_composite_params;
  } info;
};

typedef void(AwDrawVKFunction)(long view_context, AwDrawVKInfo* draw_info);

#ifdef __cplusplus
}  // extern "C"
#endif

#endif  // ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_VK_H_
+0 −142
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Provides a webviewchromium glue layer adapter from the internal Android
// Vulkan Functor data types into the types the chromium stack expects, and
// back.

#define LOG_TAG "webviewchromium_plat_support"

#include "draw_fn.h"
#include "draw_vk.h"

#include <jni.h>
#include <private/hwui/DrawVkInfo.h>
#include <utils/Functor.h>
#include <utils/Log.h>

#include "functor_utils.h"

#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))

namespace android {
namespace {

AwDrawVKFunction* g_aw_drawvk_function = NULL;

class DrawVKFunctor : public Functor {
 public:
  explicit DrawVKFunctor(jlong view_context) : view_context_(view_context) {}
  ~DrawVKFunctor() override {}

  // Functor
  status_t operator ()(int what, void* data) override {
    using uirenderer::DrawVkInfo;
    if (!g_aw_drawvk_function) {
      ALOGE("Cannot draw: no DrawVK Function installed");
      return DrawVkInfo::kStatusDone;
    }

    AwDrawVKInfo aw_info;
    aw_info.version = kAwDrawVKInfoVersion;
    switch (what) {
      case DrawVkInfo::kModeComposite: {
        aw_info.mode = AwDrawVKInfo::kModeComposite;
        DrawVkInfo* vk_info = reinterpret_cast<DrawVkInfo*>(data);

        // Map across the input values.
        CompositeParams& params = aw_info.info.composite_params;
        params.width = vk_info->width;
        params.height = vk_info->height;
        params.is_layer = vk_info->isLayer;
        for (size_t i = 0; i < 16; i++) {
            params.transform[i] = vk_info->transform[i];
        }
        params.secondary_command_buffer = vk_info->secondaryCommandBuffer;
        params.color_attachment_index = vk_info->colorAttachmentIndex;
        params.compatible_render_pass = vk_info->compatibleRenderPass;
        params.format = vk_info->format;
        params.G = vk_info->G;
        params.A = vk_info->A;
        params.B = vk_info->B;
        params.C = vk_info->C;
        params.D = vk_info->D;
        params.E = vk_info->E;
        params.F = vk_info->F;
        for (size_t i = 0; i < 9; i++) {
            params.matrix[i] = vk_info->matrix[i];
        }
        params.clip_left = vk_info->clipLeft;
        params.clip_top = vk_info->clipTop;
        params.clip_right = vk_info->clipRight;
        params.clip_bottom = vk_info->clipBottom;

        break;
      }
      case DrawVkInfo::kModePostComposite:
        break;
      case DrawVkInfo::kModeSync:
        aw_info.mode = AwDrawVKInfo::kModeSync;
        break;
      default:
        ALOGE("Unexpected DrawVKInfo type %d", what);
        return DrawVkInfo::kStatusDone;
    }

    // Invoke the DrawVK method.
    g_aw_drawvk_function(view_context_, &aw_info);

    return DrawVkInfo::kStatusDone;
  }

 private:
  intptr_t view_context_;
};

jlong CreateVKFunctor(JNIEnv*, jclass, jlong view_context) {
  RaiseFileNumberLimit();
  return reinterpret_cast<jlong>(new DrawVKFunctor(view_context));
}

void DestroyVKFunctor(JNIEnv*, jclass, jlong functor) {
  delete reinterpret_cast<DrawVKFunctor*>(functor);
}

void SetChromiumAwDrawVKFunction(JNIEnv*, jclass, jlong draw_function) {
  g_aw_drawvk_function = reinterpret_cast<AwDrawVKFunction*>(draw_function);
}

const char kClassName[] = "com/android/webview/chromium/DrawVKFunctor";
const JNINativeMethod kJniMethods[] = {
    { "nativeCreateVKFunctor", "(J)J",
        reinterpret_cast<void*>(CreateVKFunctor) },
    { "nativeDestroyVKFunctor", "(J)V",
        reinterpret_cast<void*>(DestroyVKFunctor) },
    { "nativeSetChromiumAwDrawVKFunction", "(J)V",
        reinterpret_cast<void*>(SetChromiumAwDrawVKFunction) },
};

}  // namespace

void RegisterDrawVKFunctor(JNIEnv* env) {
  jclass clazz = env->FindClass(kClassName);
  LOG_ALWAYS_FATAL_IF(!clazz, "Unable to find class '%s'", kClassName);

  int res = env->RegisterNatives(clazz, kJniMethods, NELEM(kJniMethods));
  LOG_ALWAYS_FATAL_IF(res < 0, "register native methods failed: res=%d", res);
}

}  // namespace android