1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Copyright 2012 Francisco Jerez
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Permission is hereby granted, free of charge, to any person obtaining a
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// copy of this software and associated documentation files (the "Software"),
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to deal in the Software without restriction, including without limitation
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// and/or sell copies of the Software, and to permit persons to whom the
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Software is furnished to do so, subject to the following conditions:
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The above copyright notice and this permission notice shall be included in
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// all copies or substantial portions of the Software.
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// SOFTWARE.
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "api/util.hpp"
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "core/sampler.hpp"
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgusing namespace clover;
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgPUBLIC cl_sampler
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclCreateSampler(cl_context ctx, cl_bool norm_mode,
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                cl_addressing_mode addr_mode, cl_filter_mode filter_mode,
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                cl_int *errcode_ret) try {
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!ctx)
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      throw error(CL_INVALID_CONTEXT);
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ret_error(errcode_ret, CL_SUCCESS);
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return new sampler(*ctx, norm_mode, addr_mode, filter_mode);
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} catch (error &e) {
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ret_error(errcode_ret, e);
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return NULL;
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgPUBLIC cl_int
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclRetainSampler(cl_sampler s) {
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!s)
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      throw error(CL_INVALID_SAMPLER);
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   s->retain();
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return CL_SUCCESS;
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgPUBLIC cl_int
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclReleaseSampler(cl_sampler s) {
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!s)
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      throw error(CL_INVALID_SAMPLER);
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (s->release())
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      delete s;
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return CL_SUCCESS;
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgPUBLIC cl_int
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclGetSamplerInfo(cl_sampler s, cl_sampler_info param,
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                 size_t size, void *buf, size_t *size_ret) {
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!s)
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      throw error(CL_INVALID_SAMPLER);
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   switch (param) {
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case CL_SAMPLER_REFERENCE_COUNT:
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return scalar_property<cl_uint>(buf, size, size_ret, s->ref_count());
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case CL_SAMPLER_CONTEXT:
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return scalar_property<cl_context>(buf, size, size_ret, &s->ctx);
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case CL_SAMPLER_NORMALIZED_COORDS:
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return scalar_property<cl_bool>(buf, size, size_ret, s->norm_mode());
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case CL_SAMPLER_ADDRESSING_MODE:
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return scalar_property<cl_addressing_mode>(buf, size, size_ret,
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                                 s->addr_mode());
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case CL_SAMPLER_FILTER_MODE:
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return scalar_property<cl_filter_mode>(buf, size, size_ret,
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             s->filter_mode());
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   default:
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return CL_INVALID_VALUE;
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
91