Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: components/nacl/renderer/ppb_nacl_private_impl.cc

Issue 399983002: Pepper: Refactor cpu feature attributes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes for bbudge Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/nacl/renderer/platform_info.cc ('k') | components/nacl/renderer/sandbox_arch.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/nacl/renderer/ppb_nacl_private_impl.h" 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h"
6 6
7 #include <numeric> 7 #include <numeric>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "components/nacl/common/nacl_messages.h" 21 #include "components/nacl/common/nacl_messages.h"
22 #include "components/nacl/common/nacl_nonsfi_util.h" 22 #include "components/nacl/common/nacl_nonsfi_util.h"
23 #include "components/nacl/common/nacl_switches.h" 23 #include "components/nacl/common/nacl_switches.h"
24 #include "components/nacl/common/nacl_types.h" 24 #include "components/nacl/common/nacl_types.h"
25 #include "components/nacl/renderer/file_downloader.h" 25 #include "components/nacl/renderer/file_downloader.h"
26 #include "components/nacl/renderer/histogram.h" 26 #include "components/nacl/renderer/histogram.h"
27 #include "components/nacl/renderer/json_manifest.h" 27 #include "components/nacl/renderer/json_manifest.h"
28 #include "components/nacl/renderer/manifest_downloader.h" 28 #include "components/nacl/renderer/manifest_downloader.h"
29 #include "components/nacl/renderer/manifest_service_channel.h" 29 #include "components/nacl/renderer/manifest_service_channel.h"
30 #include "components/nacl/renderer/nexe_load_manager.h" 30 #include "components/nacl/renderer/nexe_load_manager.h"
31 #include "components/nacl/renderer/platform_info.h"
31 #include "components/nacl/renderer/pnacl_translation_resource_host.h" 32 #include "components/nacl/renderer/pnacl_translation_resource_host.h"
32 #include "components/nacl/renderer/progress_event.h" 33 #include "components/nacl/renderer/progress_event.h"
33 #include "components/nacl/renderer/sandbox_arch.h"
34 #include "components/nacl/renderer/trusted_plugin_channel.h" 34 #include "components/nacl/renderer/trusted_plugin_channel.h"
35 #include "content/public/common/content_client.h" 35 #include "content/public/common/content_client.h"
36 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
37 #include "content/public/common/sandbox_init.h" 37 #include "content/public/common/sandbox_init.h"
38 #include "content/public/renderer/pepper_plugin_instance.h" 38 #include "content/public/renderer/pepper_plugin_instance.h"
39 #include "content/public/renderer/render_thread.h" 39 #include "content/public/renderer/render_thread.h"
40 #include "content/public/renderer/render_view.h" 40 #include "content/public/renderer/render_view.h"
41 #include "content/public/renderer/renderer_ppapi_host.h" 41 #include "content/public/renderer/renderer_ppapi_host.h"
42 #include "native_client/src/public/imc_types.h" 42 #include "native_client/src/public/imc_types.h"
43 #include "net/base/data_url.h" 43 #include "net/base/data_url.h"
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 if (json_data.isMember("pnacl-ld-name")) { 1212 if (json_data.isMember("pnacl-ld-name")) {
1213 Json::Value json_name = json_data["pnacl-ld-name"]; 1213 Json::Value json_name = json_data["pnacl-ld-name"];
1214 if (json_name.isString()) { 1214 if (json_name.isString()) {
1215 std::string ld_tool_name_str = json_name.asString(); 1215 std::string ld_tool_name_str = json_name.asString();
1216 *ld_tool_name = ppapi::StringVar::StringToPPVar(ld_tool_name_str); 1216 *ld_tool_name = ppapi::StringVar::StringToPPVar(ld_tool_name_str);
1217 } 1217 }
1218 } 1218 }
1219 return PP_TRUE; 1219 return PP_TRUE;
1220 } 1220 }
1221 1221
1222 // Helper to std::accumulate that creates a comma-separated list from the input.
1223 std::string CommaAccumulator(const std::string &lhs, const std::string &rhs) {
1224 if (lhs.empty())
1225 return rhs;
1226 return lhs + "," + rhs;
1227 }
1228
1229 PP_Var GetCpuFeatureAttrs() { 1222 PP_Var GetCpuFeatureAttrs() {
1230 // PNaCl's translator from pexe to nexe can be told exactly what 1223 return ppapi::StringVar::StringToPPVar(GetCpuFeatures());
1231 // capabilities the user's machine has because the pexe to nexe
1232 // translation is specific to the machine, and CPU information goes
1233 // into the translation cache. This allows the translator to generate
1234 // faster code.
1235 //
1236 // Care must be taken to avoid instructions which aren't supported by
1237 // the NaCl sandbox. Ideally the translator would do this, but there's
1238 // no point in not doing the whitelist here.
1239 //
1240 // TODO(jfb) Some features are missing, either because the NaCl
1241 // sandbox doesn't support them, because base::CPU doesn't
1242 // detect them, or because they don't help vector shuffles
1243 // (and we omit them because it simplifies testing). Add the
1244 // other features.
1245 //
1246 // TODO(jfb) The following is x86-specific. The base::CPU class
1247 // doesn't handle other architectures very well, and we
1248 // should at least detect the presence of ARM's integer
1249 // divide.
1250 std::vector<std::string> attrs;
1251 base::CPU cpu;
1252
1253 // On x86, SSE features are ordered: the most recent one implies the
1254 // others. Care is taken here to only specify the latest SSE version,
1255 // whereas non-SSE features don't follow this model: POPCNT is
1256 // effectively always implied by SSE4.2 but has to be specified
1257 // separately.
1258 //
1259 // TODO: AVX2, AVX, SSE 4.2.
1260 if (cpu.has_sse41()) attrs.push_back("+sse4.1");
1261 // TODO: SSE 4A, SSE 4.
1262 else if (cpu.has_ssse3()) attrs.push_back("+ssse3");
1263 // TODO: SSE 3
1264 else if (cpu.has_sse2()) attrs.push_back("+sse2");
1265
1266 // TODO: AES, POPCNT, LZCNT, ...
1267
1268 return ppapi::StringVar::StringToPPVar(std::accumulate(
1269 attrs.begin(), attrs.end(), std::string(), CommaAccumulator));
1270 } 1224 }
1271 1225
1272 void PostMessageToJavaScriptMainThread(PP_Instance instance, 1226 void PostMessageToJavaScriptMainThread(PP_Instance instance,
1273 const std::string& message) { 1227 const std::string& message) {
1274 content::PepperPluginInstance* plugin_instance = 1228 content::PepperPluginInstance* plugin_instance =
1275 content::PepperPluginInstance::Get(instance); 1229 content::PepperPluginInstance::Get(instance);
1276 if (plugin_instance) { 1230 if (plugin_instance) {
1277 PP_Var message_var = ppapi::StringVar::StringToPPVar(message); 1231 PP_Var message_var = ppapi::StringVar::StringToPPVar(message);
1278 plugin_instance->PostMessageToJavaScript(message_var); 1232 plugin_instance->PostMessageToJavaScript(message_var);
1279 ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(message_var); 1233 ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(message_var);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 &SetPNaClStartTime 1606 &SetPNaClStartTime
1653 }; 1607 };
1654 1608
1655 } // namespace 1609 } // namespace
1656 1610
1657 const PPB_NaCl_Private* GetNaClPrivateInterface() { 1611 const PPB_NaCl_Private* GetNaClPrivateInterface() {
1658 return &nacl_interface; 1612 return &nacl_interface;
1659 } 1613 }
1660 1614
1661 } // namespace nacl 1615 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/renderer/platform_info.cc ('k') | components/nacl/renderer/sandbox_arch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698