summaryrefslogtreecommitdiffstats
path: root/gpu/command_buffer/service/gpu_processor_win.cc
blob: e37c636ae021be221efd64aaf601f35454f38f4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <windows.h>

#include "app/gfx/gl/gl_context.h"
#include "gpu/command_buffer/service/gpu_processor.h"

using ::base::SharedMemory;

namespace gpu {

bool GPUProcessor::Initialize(gfx::PluginWindowHandle window,
                              const gfx::Size& size,
                              GPUProcessor* parent,
                              uint32 parent_texture_id) {
  // Cannot reinitialize.
  if (context_.get())
    return false;

  // Get the parent decoder and the GLContext to share IDs with, if any.
  gles2::GLES2Decoder* parent_decoder = NULL;
  gfx::GLContext* parent_context = NULL;
  void* parent_handle = NULL;
  if (parent) {
    parent_decoder = parent->decoder_.get();
    DCHECK(parent_decoder);

    parent_context = parent_decoder->GetGLContext();
    DCHECK(parent_context);

    parent_handle = parent_context->GetHandle();
    DCHECK(parent_handle);
  }

  // Create either a view or pbuffer based GLContext.
  if (window) {
    DCHECK(!parent_handle);

    // TODO(apatrick): support multisampling.
    context_.reset(gfx::GLContext::CreateViewGLContext(window, false));
  } else {
    context_.reset(gfx::GLContext::CreateOffscreenGLContext(parent_handle));
  }

  if (!context_.get())
    return false;

  return InitializeCommon(size, parent_decoder, parent_texture_id);
}

void GPUProcessor::Destroy() {
  DestroyCommon();
}

void GPUProcessor::WillSwapBuffers() {
  if (wrapped_swap_buffers_callback_.get()) {
    wrapped_swap_buffers_callback_->Run();
  }
}

}  // namespace gpu