<commit_before>// Copyright (c) 2011 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.

#if defined(ENABLE_GPU)

#include "base/process_util.h"
#include "base/shared_memory.h"
#include "build/build_config.h"
#include "content/common/gpu_messages.h"
#include "content/common/child_thread.h"
#include "content/gpu/gpu_channel.h"
#include "content/gpu/gpu_command_buffer_stub.h"
#include "content/gpu/gpu_render_thread.h"
#include "content/gpu/gpu_watchdog_thread.h"
#include "gpu/common/gpu_trace_event.h"

using gpu::Buffer;

#if defined(OS_WIN)
#define kCompositorWindowOwner L"CompositorWindowOwner"
#endif  // defined(OS_WIN)

GpuCommandBufferStub::GpuCommandBufferStub(
    GpuChannel* channel,
    gfx::PluginWindowHandle handle,
    GpuCommandBufferStub* parent,
    const gfx::Size& size,
    const gpu::gles2::DisallowedExtensions& disallowed_extensions,
    const std::string& allowed_extensions,
    const std::vector<int32>& attribs,
    uint32 parent_texture_id,
    int32 route_id,
    int32 renderer_id,
    int32 render_view_id,
    GpuWatchdogThread* gpu_watchdog_thread)
    : channel_(channel),
      handle_(handle),
      parent_(
          parent ? parent->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>()),
      initial_size_(size),
      disallowed_extensions_(disallowed_extensions),
      allowed_extensions_(allowed_extensions),
      requested_attribs_(attribs),
      parent_texture_id_(parent_texture_id),
      route_id_(route_id),
#if defined(OS_WIN)
      compositor_window_(NULL),
#endif  // defined(OS_WIN)
      renderer_id_(renderer_id),
      render_view_id_(render_view_id),
      watchdog_thread_(gpu_watchdog_thread) {
}

#if defined(OS_WIN)
static LRESULT CALLBACK CompositorWindowProc(
    HWND hwnd,
    UINT message,
    WPARAM wparam,
    LPARAM lparam) {
  switch (message) {
    case WM_ERASEBKGND:
      return 0;
    case WM_DESTROY:
      RemoveProp(hwnd, kCompositorWindowOwner);
      return 0;
    case WM_PAINT: {
      PAINTSTRUCT paint;
      HDC dc = BeginPaint(hwnd, &paint);
      if (dc) {
        HANDLE h = GetProp(hwnd, kCompositorWindowOwner);
        if (h) {
          GpuCommandBufferStub* stub =
              reinterpret_cast<GpuCommandBufferStub*>(h);
          stub->OnCompositorWindowPainted();
        }
        EndPaint(hwnd, &paint);
      }
      break;
    }
    default:
      return DefWindowProc(hwnd, message, wparam, lparam);
  }
  return 0;
}

bool GpuCommandBufferStub::CreateCompositorWindow() {
  DCHECK(handle_ != gfx::kNullPluginWindow);
  HWND host_window = static_cast<HWND>(handle_);

  // Create the compositor window itself.
  DCHECK(host_window);
  static ATOM window_class = 0;
  if (!window_class) {
    WNDCLASSEX wcex;
    wcex.cbSize         = sizeof(wcex);
    wcex.style          = 0;
    wcex.lpfnWndProc    = CompositorWindowProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = GetModuleHandle(NULL);<commit_msg>GPU process: Add a SEH handler to the compositor window proc.<commit_after>// Copyright (c) 2011 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.

#if defined(ENABLE_GPU)

#include "base/process_util.h"
#include "base/shared_memory.h"
#include "build/build_config.h"
#include "content/common/gpu_messages.h"
#include "content/common/child_thread.h"
#include "content/gpu/gpu_channel.h"
#include "content/gpu/gpu_command_buffer_stub.h"
#include "content/gpu/gpu_render_thread.h"
#include "content/gpu/gpu_watchdog_thread.h"
#include "gpu/common/gpu_trace_event.h"

#if defined(OS_WIN)
#include "base/win/wrapped_window_proc.h"
#endif

using gpu::Buffer;

#if defined(OS_WIN)
#define kCompositorWindowOwner L"CompositorWindowOwner"
#endif  // defined(OS_WIN)

GpuCommandBufferStub::GpuCommandBufferStub(
    GpuChannel* channel,
    gfx::PluginWindowHandle handle,
    GpuCommandBufferStub* parent,
    const gfx::Size& size,
    const gpu::gles2::DisallowedExtensions& disallowed_extensions,
    const std::string& allowed_extensions,
    const std::vector<int32>& attribs,
    uint32 parent_texture_id,
    int32 route_id,
    int32 renderer_id,
    int32 render_view_id,
    GpuWatchdogThread* gpu_watchdog_thread)
    : channel_(channel),
      handle_(handle),
      parent_(
          parent ? parent->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>()),
      initial_size_(size),
      disallowed_extensions_(disallowed_extensions),
      allowed_extensions_(allowed_extensions),
      requested_attribs_(attribs),
      parent_texture_id_(parent_texture_id),
      route_id_(route_id),
#if defined(OS_WIN)
      compositor_window_(NULL),
#endif  // defined(OS_WIN)
      renderer_id_(renderer_id),
      render_view_id_(render_view_id),
      watchdog_thread_(gpu_watchdog_thread) {
}

#if defined(OS_WIN)
static LRESULT CALLBACK CompositorWindowProc(
    HWND hwnd,
    UINT message,
    WPARAM wparam,
    LPARAM lparam) {
  switch (message) {
    case WM_ERASEBKGND:
      return 0;
    case WM_DESTROY:
      RemoveProp(hwnd, kCompositorWindowOwner);
      return 0;
    case WM_PAINT: {
      PAINTSTRUCT paint;
      HDC dc = BeginPaint(hwnd, &paint);
      if (dc) {
        HANDLE h = GetProp(hwnd, kCompositorWindowOwner);
        if (h) {
          GpuCommandBufferStub* stub =
              reinterpret_cast<GpuCommandBufferStub*>(h);
          stub->OnCompositorWindowPainted();
        }
        EndPaint(hwnd, &paint);
      }
      break;
    }
    default:
      return DefWindowProc(hwnd, message, wparam, lparam);
  }
  return 0;
}

bool GpuCommandBufferStub::CreateCompositorWindow() {
  DCHECK(handle_ != gfx::kNullPluginWindow);
  HWND host_window = static_cast<HWND>(handle_);

  // Create the compositor window itself.
  DCHECK(host_window);
  static ATOM window_class = 0;
  if (!window_class) {
    WNDCLASSEX wcex;
    wcex.cbSize         = sizeof(wcex);
    wcex.style          = 0;
    wcex.lpfnWndProc    = base::win::WrappedWindowProc<CompositorWindowProc>;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = GetModuleHandle(NULL);
{'fraction_non_alphanumeric': 0.10236724248240563, 'fraction_numerical': 0.007037747920665387, 'mean_word_length': 3.6421677802524126, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3504135', 'n_tokens_mistral': 2153, 'n_tokens_neox': 2126, 'n_words': 412}