Logo Search packages:      
Sourcecode: chromium-browser version File versions  Download package


// Copyright (c) 2010 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 "chrome/gpu/gpu_view_x.h"

#include "app/gfx/gl/gl_bindings.h"
#include "base/scoped_ptr.h"
#include "chrome/common/gpu_messages.h"
#include "chrome/gpu/gpu_backing_store_glx.h"
#include "chrome/gpu/gpu_backing_store_glx_context.h"
#include "chrome/gpu/gpu_thread.h"
#include "chrome/gpu/gpu_video_layer_glx.h"

// X stuff must be last since it does "#define Status int" which messes up some
// of the header files we indirectly pull in.
#include <X11/Xutil.h>

GpuViewX::GpuViewX(GpuThread* gpu_thread,
                   XID parent,
                   int32 routing_id)
    : gpu_thread_(gpu_thread),
      window_(parent) {
  gpu_thread_->AddRoute(routing_id_, this);

GpuViewX::~GpuViewX() {
  // TODO(brettw) may want to delete any dangling backing stores, or perhaps
  // assert if one still exists.

GLXContext GpuViewX::BindContext() {
  GLXContext ctx = gpu_thread_->GetGLXContext()->BindContext(window_);
  return ctx;

void GpuViewX::OnMessageReceived(const IPC::Message& msg) {
    IPC_MESSAGE_HANDLER(GpuMsg_NewBackingStore, OnNewBackingStore)
    IPC_MESSAGE_HANDLER(GpuMsg_NewVideoLayer, OnNewVideoLayer)
    IPC_MESSAGE_HANDLER(GpuMsg_WindowPainted, OnWindowPainted)

void GpuViewX::OnChannelConnected(int32 peer_pid) {

void GpuViewX::OnChannelError() {
  // TODO(brettw) do we need to delete ourselves now?

void GpuViewX::DidScrollBackingStoreRect(int dx, int dy,
                                         const gfx::Rect& rect) {

void GpuViewX::Repaint() {

  const gfx::Size& size = backing_store_->size();

  glViewport(0, 0, size.width(), size.height());

  // TODO(apatrick): These functions are not available in GLES2.
  // glMatrixMode(GL_MODELVIEW);
  // glLoadIdentity();

  glBindTexture(GL_TEXTURE_2D, backing_store_->texture_id());

  // TODO(brettw) use vertex buffers.
  // TODO(brettw) make this so we use the texture size rather than the whole
  // area size so we don't stretch bitmaps.
  // TODO(apatrick): These functions are not available in GLES2.
  // glBegin(GL_QUADS);
  //  glTexCoord2f(0.0f, 0.0f);
  //  glVertex2f(-1.0, 1.0);

  //  glTexCoord2f(0.0f, 1.0f);
  //  glVertex2f(-1.0, -1.0);

  //  glTexCoord2f(1.0f, 1.0f);
  //  glVertex2f(1.0, -1.0);

  //  glTexCoord2f(1.0f, 0.0f);
  //  glVertex2f(1.0, 1.0);
  // glEnd();
  DCHECK(glGetError() == GL_NO_ERROR);

  if (video_layer_.get()) {
    DCHECK(glGetError() == GL_NO_ERROR);

  // TODO(brettw) when we no longer stretch non-fitting bitmaps, we should
  // paint white over any unpainted area here.

  glXSwapBuffers(gpu_thread_->display(), window_);

void GpuViewX::OnNewBackingStore(int32 routing_id, const gfx::Size& size) {
      new GpuBackingStoreGLX(this, gpu_thread_, routing_id, size));

void GpuViewX::OnNewVideoLayer(int32 routing_id, const gfx::Size& size) {
      new GpuVideoLayerGLX(this, gpu_thread_, routing_id, size));

void GpuViewX::OnWindowPainted() {

Generated by  Doxygen 1.6.0   Back to index