Dirty rects always contain full tiles with delegated rendering.
[chromium-blink-merge.git] / gin / isolate_holder.cc
blobc9f435c2f474baed5e41ebcb91ccc3384fdc9a6b
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
3 // found in the LICENSE file.
5 #include "gin/public/isolate_holder.h"
7 #include <stdlib.h>
8 #include <string.h>
10 #include "base/logging.h"
11 #include "base/rand_util.h"
12 #include "base/sys_info.h"
13 #include "gin/array_buffer.h"
14 #include "gin/function_template.h"
15 #include "gin/per_isolate_data.h"
17 namespace gin {
19 namespace {
21 bool GenerateEntropy(unsigned char* buffer, size_t amount) {
22 base::RandBytes(buffer, amount);
23 return true;
27 void EnsureV8Initialized(bool gin_managed) {
28 static bool v8_is_initialized = false;
29 static bool v8_is_gin_managed = false;
30 if (v8_is_initialized) {
31 CHECK_EQ(v8_is_gin_managed, gin_managed);
32 return;
34 v8_is_initialized = true;
35 v8_is_gin_managed = gin_managed;
37 v8::V8::SetArrayBufferAllocator(ArrayBufferAllocator::SharedInstance());
38 static const char v8_flags[] = "--use_strict --harmony";
39 v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1);
40 v8::V8::SetEntropySource(&GenerateEntropy);
41 v8::V8::Initialize();
44 } // namespace
46 IsolateHolder::IsolateHolder()
47 : isolate_owner_(true) {
48 EnsureV8Initialized(true);
49 isolate_ = v8::Isolate::New();
50 v8::ResourceConstraints constraints;
51 constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
52 base::SysInfo::NumberOfProcessors());
53 v8::SetResourceConstraints(isolate_, &constraints);
54 v8::Isolate::Scope isolate_scope(isolate_);
55 v8::HandleScope handle_scope(isolate_);
56 isolate_data_.reset(new PerIsolateData(isolate_));
57 InitFunctionTemplates(isolate_data_.get());
60 IsolateHolder::IsolateHolder(v8::Isolate* isolate)
61 : isolate_owner_(false),
62 isolate_(isolate) {
63 EnsureV8Initialized(false);
64 v8::Isolate::Scope isolate_scope(isolate_);
65 v8::HandleScope handle_scope(isolate_);
66 isolate_data_.reset(new PerIsolateData(isolate_));
69 IsolateHolder::~IsolateHolder() {
70 isolate_data_.reset();
71 if (isolate_owner_)
72 isolate_->Dispose();
75 } // namespace gin