blob: 50cf3897d21bf23683a363888c6fcd61e93cd1dc [file] [log] [blame]
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkCLImageDiffer_DEFINED
9#define SkCLImageDiffer_DEFINED
10
11#include <CL/cl.h>
12#include "SkTDArray.h"
13
14#include "SkImageDiffer.h"
15
16class SkStream;
17
18/**
19 * An SkImageDiffer that requires initialization with an OpenCL device and context.
20 */
21class SkCLImageDiffer : public SkImageDiffer {
22public:
23 SkCLImageDiffer();
24
zachr@google.comd6585682013-07-17 19:29:19 +000025 virtual bool requiresOpenCL() SK_OVERRIDE { return true; }
26
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000027 /**
28 * Initializes the OpenCL resources this differ needs to work
29 * @param device An OpenCL device
30 * @param context An OpenCL context of the given device
31 * @return True on success, false otherwise
32 */
33 virtual bool init(cl_device_id device, cl_context context);
34
35protected:
36 /**
37 * Called by init after fDevice, fContext, and fCommandQueue are successfully initialized
38 * @return True on success, false otherwise
39 */
40 virtual bool onInit() = 0;
41
42 /**
43 * Loads an OpenCL kernel from the file with the given named entry point. This only works after
44 * init is called.
45 * @param file The file path of the kernel
46 * @param name The name of the entry point of the desired kernel in the file
47 * @param kernel A pointer to return the loaded kernel into
48 * @return True on success, false otherwise
49 */
50 bool loadKernelFile(const char file[], const char name[], cl_kernel* kernel);
51
52 /**
53 * Loads an OpenCL kernel from the stream with the given named entry point. This only works
54 * after init is called.
55 * @param stream The stream that contains the kernel
56 * @param name The name of the entry point of the desired kernel in the stream
57 * @param kernel A pointer to return the loaded kernel into
58 * @return True on success, false otherwise
59 */
60 bool loadKernelStream(SkStream* stream, const char name[], cl_kernel* kernel);
61
62 /**
63 * Loads an OpenCL kernel from the source string with the given named entry point. This only
64 * works after init is called.
65 * @param source The string that contains the kernel
66 * @param name The name of the entry point of the desired kernel in the source string
67 * @param kernel A pointer to return the loaded kernel into
68 * @return True on success, false otherwise
69 */
70 bool loadKernelSource(const char source[], const char name[], cl_kernel* kernel);
71
72 /**
73 * Loads a read only copy of the given bitmap into device memory and returns the block of
74 * memory. This only works after init is called.
75 * @param bitmap The bitmap to load into memory
76 * @param image A pointer to return the allocated image to
77 * @return True on success, false otherwise
78 */
79 bool makeImage2D(SkBitmap* bitmap, cl_mem* image);
80
81 cl_device_id fDevice;
82 cl_context fContext;
83 cl_command_queue fCommandQueue;
84
85private:
86
87 typedef SkImageDiffer INHERITED;
88};
89
commit-bot@chromium.orgbe19b9e2013-06-14 17:26:54 +000090#endif