我刚刚开始尝试使用Chrome自定义标签并遇到这个小问题。在设置运行Chrome自定义标签示例的环境时,我在设备上下载了Chrome测试版。但是,当我运行这个例子时,它不会起作用。
我提出了几个断点,一切似乎都有效,最重要的是,程序可以找到支持自定义标签的软件包:
struct CL_Sphere
{
rs::vec4 center,color,rad;
CL_Sphere(vec3 c, float rad, vec3 cc):center((vec4)c), color((vec4)cc), rad(vec4(rad,0,0,0)){}
};
class CLLib
{
private:
cl_device_id device_id = NULL;
cl_context context = NULL;
cl_command_queue command_queue = NULL;
cl_program program = NULL;
cl_platform_id platform_id = NULL;
cl_uint ret_num_devices;
cl_uint ret_num_platforms;
cl_int ret;
string source;
cl_mem memobjInput = NULL;
cl_mem memobjOutput = NULL;
cl_kernel kernel = NULL;
size_t workGroups;
size_t workItems;
size_t dimSize;
public:
size_t inputSize;
size_t outputSize;
void* bufferIn;
void* bufferOut;
CLLib(string filename, string kernelName)
{
/* Get Platform and Device Info */
ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &ret_num_devices);
/* Create OpenCL context */
context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret);
/* Create Command Queue */
command_queue = clCreateCommandQueue(context, device_id, 0, &ret);
bool read = readFile(filename, &source);
if(!read) throw "Failed to read a file";
size_t source_size = source.length() + 1;
char* source_str = new char[source_size];
strcpy_s(source_str, source_size * sizeof(char), source.c_str());
/* Create Kernel Program from the source */
program = clCreateProgramWithSource(context, 1, (const char **)&source_str,
(const size_t *)&source_size, &ret);
/* Build Kernel Program */
ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);
if (ret == CL_BUILD_PROGRAM_FAILURE) {
// Determine the size of the log
size_t log_size;
clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
// Allocate memory for the log
char *log = (char *) malloc(log_size);
// Get the log
clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, log_size, log, NULL);
// Print the log
printf("%s\n", log);
}
/* Create OpenCL Kernel */
kernel = clCreateKernel(program, kernelName.c_str(), &ret);
delete[] source_str;
}
void reinitDataContainers(size_t inputSize, size_t outputSize)
{
this->inputSize = inputSize;
this->outputSize = outputSize;
if(bufferIn){
free(bufferIn);
}
if(bufferOut){
free(bufferOut);
}
bufferIn = malloc(inputSize);
bufferOut = malloc(outputSize);
if(memobjInput){
ret = clReleaseMemObject(memobjInput);
}
if(memobjOutput){
ret = clReleaseMemObject(memobjOutput);
}
memobjInput = clCreateBuffer(context, CL_MEM_READ_WRITE, inputSize, 0, &ret);
memobjOutput = clCreateBuffer(context, CL_MEM_WRITE_ONLY, outputSize, 0, &ret);
}
void build(size_t dimSize, size_t workGroups, size_t workItems)
{
this->workGroups = workGroups;
this->workItems = workItems;
this->dimSize = dimSize;
clEnqueueWriteBuffer(command_queue, memobjInput, CL_TRUE, 0, inputSize, bufferIn, 0, NULL, NULL);
/* Set OpenCL Kernel Parameters */
ret = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&memobjInput);
ret = clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&memobjOutput);
}
void execute()
{
/* Execute OpenCL Kernel */
ret = clEnqueueNDRangeKernel(command_queue, kernel, dimSize, 0, &workGroups, &workItems, 0, NULL, NULL);
double curTime = Timer::getTimeNanoSeconds();
clEnqueueReadBuffer(command_queue, memobjOutput, CL_TRUE, 0, outputSize, bufferOut, 0, NULL, NULL);
//println("delta: "+ toString(Timer::getTimeNanoSeconds() - curTime));
}
void release()
{
/* Finalization */
ret = clFlush(command_queue);
ret = clFinish(command_queue);
ret = clReleaseKernel(kernel);
ret = clReleaseProgram(program);
ret = clReleaseMemObject(memobjInput);
ret = clReleaseMemObject(memobjOutput);
ret = clReleaseCommandQueue(command_queue);
ret = clReleaseContext(context);
free(bufferIn);
free(bufferOut);
}
}
'的packageName'设置为chrome beta但没有调用任何回调(onCustomTabsServiceConnected或onServiceDisconnected)。
我通过运行Chrome测试版并执行了几项设置操作来解决了这个问题。在那之后,我再次运行了这个例子并且它运行了。这似乎是一种错误......这种行为是否可以预期?
答案 0 :(得分:5)
这是预期的行为。当Chrome向用户显示任何内容时,它会要求先接受使用条款。在接受TOS之后,应该显示网页,并且应用程序能够绑定到服务。