[email protected] | 9ca8a523 | 2012-08-07 22:34:30 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 5 | #include "ppapi/shared_impl/ppb_image_data_shared.h" |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 6 | |
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 7 | #include "base/logging.h" |
[email protected] | 9ca8a523 | 2012-08-07 22:34:30 | [diff] [blame] | 8 | #include "build/build_config.h" |
9 | |||||
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 10 | #if !defined(OS_NACL) && !defined(NACL_WIN64) |
[email protected] | cf69668 | 2011-03-17 03:05:55 | [diff] [blame] | 11 | #include "third_party/skia/include/core/SkTypes.h" |
[email protected] | 9ca8a523 | 2012-08-07 22:34:30 | [diff] [blame] | 12 | #endif |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 13 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 14 | namespace ppapi { |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 15 | |
16 | // static | ||||
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 17 | PP_ImageDataFormat PPB_ImageData_Shared::GetNativeImageDataFormat() { |
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 18 | #if defined(OS_NACL) |
19 | // In NaCl, just default to something. If we're wrong, it will be converted | ||||
20 | // later. | ||||
21 | // TODO(dmichael): Really proxy this. | ||||
22 | return PP_IMAGEDATAFORMAT_BGRA_PREMUL; | ||||
23 | #elif defined(NACL_WIN64) | ||||
24 | // In the NaCl Win64 helper, this shouldn't be called. If we start building | ||||
25 | // Chrome on Windows 64 for realz, we should really implement this. | ||||
26 | NOTIMPLEMENTED(); | ||||
27 | return PP_IMAGEDATAFORMAT_BGRA_PREMUL; | ||||
28 | #else | ||||
[email protected] | c2b7f79 | 2013-10-30 01:04:07 | [diff] [blame] | 29 | if (SK_B32_SHIFT == 0) |
30 | return PP_IMAGEDATAFORMAT_BGRA_PREMUL; | ||||
31 | else if (SK_R32_SHIFT == 0) | ||||
32 | return PP_IMAGEDATAFORMAT_RGBA_PREMUL; | ||||
33 | else | ||||
[email protected] | 665b5c54 | 2014-02-22 08:06:26 | [diff] [blame] | 34 | return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure |
[email protected] | 9ca8a523 | 2012-08-07 22:34:30 | [diff] [blame] | 35 | #endif |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 36 | } |
37 | |||||
38 | // static | ||||
[email protected] | 56c49bb | 2013-04-26 01:24:13 | [diff] [blame] | 39 | PP_Bool PPB_ImageData_Shared::IsImageDataFormatSupported( |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 40 | PP_ImageDataFormat format) { |
[email protected] | 56c49bb | 2013-04-26 01:24:13 | [diff] [blame] | 41 | return PP_FromBool(format == PP_IMAGEDATAFORMAT_BGRA_PREMUL || |
42 | format == PP_IMAGEDATAFORMAT_RGBA_PREMUL); | ||||
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 43 | } |
44 | |||||
[email protected] | ebdbb11 | 2013-05-16 16:56:34 | [diff] [blame] | 45 | // static |
46 | PP_Bool PPB_ImageData_Shared::IsImageDataDescValid( | ||||
47 | const PP_ImageDataDesc& desc) { | ||||
48 | return PP_FromBool(IsImageDataFormatSupported(desc.format) && | ||||
[email protected] | 665b5c54 | 2014-02-22 08:06:26 | [diff] [blame] | 49 | desc.size.width > 0 && desc.size.height > 0 && |
[email protected] | ebdbb11 | 2013-05-16 16:56:34 | [diff] [blame] | 50 | desc.stride > 0); |
51 | } | ||||
52 | |||||
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 53 | } // namespace ppapi |